Projects tigase _server server-core Commits 799df132
ctrl k
  • src/main/java/tigase/server/websocket/WebSocketHixie76.java
    ■ ■ ■ ■ ■ ■
    skipped 63 lines
    64 64   @Override
    65 65   public boolean handshake(WebSocketXMPPIOService service, Map<String, String> headers, byte[] buf)
    66 66   throws NoSuchAlgorithmException, IOException {
    67  - if (headers.containsKey(WS_VERSION_KEY)) {
     67 + if (headers.containsKey(WS_VERSION_KEY.toUpperCase())) {
    68 68   return false;
    69 69   }
    70 70   
    71 71   byte[] secBufArr = new byte[16];
    72  - Long secKey1 = decodeHyxie76SecKey(headers.get(WS_KEY1_KEY));
    73  - Long secKey2 = decodeHyxie76SecKey(headers.get(WS_KEY2_KEY));
     72 + Long secKey1 = decodeHyxie76SecKey(headers.get(WS_KEY1_KEY.toUpperCase()));
     73 + Long secKey2 = decodeHyxie76SecKey(headers.get(WS_KEY2_KEY.toUpperCase()));
    74 74   if (log.isLoggable(Level.FINEST)) {
    75 75   log.log(Level.FINEST, "WS-KEY1 = {0}", secKey1);
    76 76   log.log(Level.FINEST, "WS-KEY2 = {0}", secKey2);
    skipped 15 lines
    92 92   
    93 93   response.append("Content-Length: ").append(resp.length).append("\r\n");
    94 94   response.append(WS_PROTOCOL_KEY).append(": ");
    95  - if (headers.get(WS_PROTOCOL_KEY).contains("xmpp-framing")) {
     95 + if (headers.get(WS_PROTOCOL_KEY.toUpperCase()).contains("xmpp-framing")) {
    96 96   response.append("xmpp-framing");
    97 97   } else {
    98 98   response.append("xmpp");
    99 99   }
    100 100   response.append("\r\n");
    101  - if (headers.containsKey(ORIGIN_KEY)) {
    102  - response.append(WS_ORIGIN_KEY).append(": ").append(headers.get(ORIGIN_KEY)).append("\r\n");
     101 + if (headers.containsKey(ORIGIN_KEY.toUpperCase())) {
     102 + response.append(WS_ORIGIN_KEY).append(": ").append(headers.get(ORIGIN_KEY.toUpperCase())).append("\r\n");
    103 103   }
    104 104   
    105 105   boolean ssl = SocketType.ssl == ((SocketType) service.getSessionData().get("socket"));
    106 106   int localPort = service.getLocalPort();
    107  - String location = (ssl ? "wss://" : "ws://") + headers.get(HOST_KEY) +
    108  - (((ssl && localPort == 443) || (!ssl && localPort == 80) || headers.get(HOST_KEY).contains(":"))
     107 + String location = (ssl ? "wss://" : "ws://") + headers.get(HOST_KEY.toUpperCase()) +
     108 + (((ssl && localPort == 443) || (!ssl && localPort == 80) || headers.get(HOST_KEY.toUpperCase()).contains(":"))
    109 109   ? ""
    110 110   : (":" + localPort)) + "/";
    111 111   response.append(WS_LOCATION_KEY).append(": ").append(location).append("\r\n");
    skipped 153 lines
  • src/main/java/tigase/server/websocket/WebSocketHybi.java
    ■ ■ ■ ■ ■ ■
    skipped 69 lines
    70 70   @Override
    71 71   public boolean handshake(WebSocketXMPPIOService service, Map<String, String> headers, byte[] buf)
    72 72   throws NoSuchAlgorithmException, IOException {
    73  - if (!headers.containsKey(WS_VERSION_KEY)) {
     73 + if (!headers.containsKey(WS_VERSION_KEY.toUpperCase())) {
    74 74   return false;
    75 75   }
    76 76   
    77 77   StringBuilder response = new StringBuilder(RESPONSE_HEADER.length() * 2);
    78 78   response.append(RESPONSE_HEADER);
    79 79   
    80  - int version = Integer.parseInt(headers.get(WS_VERSION_KEY));
     80 + int version = Integer.parseInt(headers.get(WS_VERSION_KEY.toUpperCase()));
    81 81   String key = headers.get(WS_KEY_KEY) + GUID;
    82 82   
    83 83   MessageDigest md = MessageDigest.getInstance("SHA1");
    84 84   byte[] resp = md.digest(key.getBytes());
    85 85   
    86 86   response.append(WS_PROTOCOL_KEY).append(": ");
    87  - if (headers.get(WS_PROTOCOL_KEY).contains("xmpp-framing")) {
     87 + if (headers.get(WS_PROTOCOL_KEY.toUpperCase()).contains("xmpp-framing")) {
    88 88   response.append("xmpp-framing");
    89 89   } else {
    90 90   response.append("xmpp");
    skipped 216 lines
  • src/main/java/tigase/server/websocket/WebSocketXMPPIOService.java
    ■ ■ ■ ■ ■ ■
    skipped 306 lines
    307 307   switch (buf[i]) {
    308 308   case ':':
    309 309   if (key == null) {
    310  - key = builder.toString().trim();
     310 + key = builder.toString().trim().toUpperCase();
    311 311   builder = new StringBuilder(64);
    312 312   skipWhitespace = true;
    313 313   } else {
    skipped 43 lines
    357 357   HashMap<String, String> headers = new HashMap<String, String>();
    358 358   int i = parseHttpHeaders(buf, headers);
    359 359   
    360  - String connectionHeader = headers.get(CONNECTION_KEY);
     360 + String connectionHeader = headers.get(CONNECTION_KEY.toUpperCase());
    361 361   if (connectionHeader != null) {
    362 362   String[] values = connectionHeader.split(",");
    363 363   boolean contains = false;
    skipped 11 lines
    375 375   return;
    376 376   }
    377 377   }
    378  - if (!headers.containsKey(WebSocketProtocolIfc.WS_PROTOCOL_KEY) ||
    379  - !headers.get(WebSocketProtocolIfc.WS_PROTOCOL_KEY).contains("xmpp")) {
     378 + if (!headers.containsKey(WebSocketProtocolIfc.WS_PROTOCOL_KEY.toUpperCase()) ||
     379 + !headers.get(WebSocketProtocolIfc.WS_PROTOCOL_KEY.toUpperCase()).contains("xmpp")) {
    380 380   writeRawData(BAD_REQUEST);
    381 381   
    382 382   dumpHeaders(headers);
    skipped 98 lines
  • src/test/java/tigase/server/websocket/WebSocketHixie76Test.java
    ■ ■ ■ ■ ■ ■
    skipped 73 lines
    74 74   
    75 75   };
    76 76   Map<String, String> params = new HashMap<String, String>();
    77  - params.put("Sec-WebSocket-Key1", "1C2J899_05 6 ! M 9 ^4");
    78  - params.put("Sec-WebSocket-Key2", "23 2ff0M_E0#.454X23");
    79  - params.put("Sec-WebSocket-Protocol", "xmpp");
     77 + params.put("Sec-WebSocket-Key1".toUpperCase(), "1C2J899_05 6 ! M 9 ^4");
     78 + params.put("Sec-WebSocket-Key2".toUpperCase(), "23 2ff0M_E0#.454X23");
     79 + params.put("Sec-WebSocket-Protocol".toUpperCase(), "xmpp");
    80 80   byte[] bytes = new byte[10];
    81 81   bytes[0] = '\r';
    82 82   bytes[1] = '\n';
    skipped 18 lines
    101 101   
    102 102   };
    103 103   Map<String, String> params = new HashMap<String, String>();
    104  - params.put("Sec-WebSocket-Version", "13");
    105  - params.put("Sec-WebSocket-Protocol", "xmpp");
     104 + params.put("Sec-WebSocket-Version".toUpperCase(), "13");
     105 + params.put("Sec-WebSocket-Protocol".toUpperCase(), "xmpp");
    106 106   byte[] bytes = new byte[10];
    107 107   bytes[0] = '\r';
    108 108   bytes[1] = '\n';
    skipped 14 lines
  • src/test/java/tigase/server/websocket/WebSocketHybiTest.java
    ■ ■ ■ ■ ■ ■
    skipped 75 lines
    76 76   
    77 77   };
    78 78   Map<String, String> params = new HashMap<String, String>();
    79  - params.put("Sec-WebSocket-Key1", "1C2J899_05 6 ! M 9 ^4");
    80  - params.put("Sec-WebSocket-Key2", "23 2ff0M_E0#.454X23");
    81  - params.put("Sec-WebSocket-Protocol", "xmpp");
     79 + params.put("Sec-WebSocket-Key1".toUpperCase(), "1C2J899_05 6 ! M 9 ^4");
     80 + params.put("Sec-WebSocket-Key2".toUpperCase(), "23 2ff0M_E0#.454X23");
     81 + params.put("Sec-WebSocket-Protocol".toUpperCase(), "xmpp");
    82 82   byte[] bytes = new byte[10];
    83 83   bytes[0] = '\r';
    84 84   bytes[1] = '\n';
    skipped 18 lines
    103 103   
    104 104   };
    105 105   Map<String, String> params = new HashMap<String, String>();
    106  - params.put("Sec-WebSocket-Version", "13");
    107  - params.put("Sec-WebSocket-Key", "some random data as a key");
    108  - params.put("Sec-WebSocket-Protocol", "xmpp");
     106 + params.put("Sec-WebSocket-Version".toUpperCase(), "13");
     107 + params.put("Sec-WebSocket-Key".toUpperCase(), "some random data as a key");
     108 + params.put("Sec-WebSocket-Protocol".toUpperCase(), "xmpp");
    109 109   byte[] bytes = new byte[10];
    110 110   bytes[0] = '\r';
    111 111   bytes[1] = '\n';
    skipped 112 lines
  • src/test/java/tigase/server/websocket/WebSocketXMPPIOServiceTest.java
    ■ ■ ■ ■ ■
    skipped 38 lines
    39 39   Map<String, String> parsedHeaders = new HashMap<>();
    40 40   service.parseHttpHeaders(data, parsedHeaders);
    41 41   
    42  - assertMaps(headers, parsedHeaders);
     42 + assertMaps(prepareExpectedParsedHeaders(headers), parsedHeaders);
    43 43   }
    44 44   
    45 45   @Test
    skipped 3 lines
    49 49   Map<String, String> parsedHeaders = new HashMap<>();
    50 50   service.parseHttpHeaders(data, parsedHeaders);
    51 51   
    52  - assertMaps(headers, parsedHeaders);
     52 + assertMaps(prepareExpectedParsedHeaders(headers), parsedHeaders);
    53 53   }
    54 54   
    55 55   @Override
    skipped 41 lines
    97 97   }
    98 98   sb.append("\r\n");
    99 99   return sb.toString().getBytes("UTF-8");
     100 + }
     101 + 
     102 + private Map<String, String> prepareExpectedParsedHeaders(Map<String, String> headers) {
     103 + Map<String, String> result = new HashMap<>();
     104 + for (Map.Entry<String,String> e : headers.entrySet()) {
     105 + result.put(e.getKey().toUpperCase(), e.getValue());
     106 + }
     107 + return result;
    100 108   }
    101 109  }
    102 110   
Please wait...
Page is in error, reload to recover