@Test public void testHandleRequest_bad_handshake_method() throws IOException { final EngineIoServer server = new EngineIoServer(); final HttpServletRequest request = Mockito.mock(HttpServletRequest.class); Mockito.doAnswer(invocationOnMock -> { HashMap<String, String> queryMap = new HashMap<>(); queryMap.put("transport", "polling"); return ParseQS.encode(queryMap); }).when(request).getQueryString(); Mockito.doAnswer(invocationOnMock -> "POST").when(request).getMethod(); final HttpServletResponseImpl response = new HttpServletResponseImpl(); server.handleRequest(request, response); response.flushWriterIfNecessary(); final String responseStr = new String(response.getByteOutputStream().toByteArray(), StandardCharsets.UTF_8); final JSONObject responseObject = new JSONObject(responseStr); assertTrue(responseObject.has("code")); assertEquals(ServerErrors.BAD_HANDSHAKE_METHOD.getCode(), responseObject.get("code")); assertTrue(responseObject.has("message")); assertEquals(ServerErrors.BAD_HANDSHAKE_METHOD.getMessage(), responseObject.get("message")); }
public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws IOException { final Map<String, String> query = ParseQS.decode(request.getQueryString()); request.setAttribute("query", query); if (!mOptions.isCorsHandlingDisabled()) { final String origin = request.getHeader("Origin"); boolean sendCors = (origin != null) && ((mOptions.getAllowedCorsOrigins() == EngineIoServerOptions.ALLOWED_CORS_ORIGIN_ALL) || (Arrays.binarySearch(mOptions.getAllowedCorsOrigins(), origin) >= 0)); if (sendCors) { response.addHeader("Access-Control-Allow-Origin", origin); response.addHeader("Access-Control-Allow-Credentials", "true"); response.addHeader("Access-Control-Allow-Methods", "GET,HEAD,PUT,PATCH,POST,DELETE"); response.addHeader("Access-Control-Allow-Headers", "origin, content-type, accept"); } } if (!query.containsKey("transport") || !query.get("transport").equals("polling")) { sendErrorMessage(response, ServerErrors.UNKNOWN_TRANSPORT); return; } final String sid = query.get("sid"); if (sid != null) { if(!mClients.containsKey(query.get("sid"))) { sendErrorMessage(response, ServerErrors.UNKNOWN_SID); } else if(!query.containsKey("transport") || !query.get("transport").equals(mClients.get(sid).getCurrentTransportName())) { sendErrorMessage(response, ServerErrors.BAD_REQUEST); } else { mClients.get(sid).onRequest(request, response); } } else { if(!request.getMethod().toUpperCase().equals("GET")) { sendErrorMessage(response, ServerErrors.BAD_HANDSHAKE_METHOD); } else { handshakePolling(request, response); } } }
EngineIoServer extends Emitter { public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws IOException { final Map<String, String> query = ParseQS.decode(request.getQueryString()); request.setAttribute("query", query); if (!mOptions.isCorsHandlingDisabled()) { final String origin = request.getHeader("Origin"); boolean sendCors = (origin != null) && ((mOptions.getAllowedCorsOrigins() == EngineIoServerOptions.ALLOWED_CORS_ORIGIN_ALL) || (Arrays.binarySearch(mOptions.getAllowedCorsOrigins(), origin) >= 0)); if (sendCors) { response.addHeader("Access-Control-Allow-Origin", origin); response.addHeader("Access-Control-Allow-Credentials", "true"); response.addHeader("Access-Control-Allow-Methods", "GET,HEAD,PUT,PATCH,POST,DELETE"); response.addHeader("Access-Control-Allow-Headers", "origin, content-type, accept"); } } if (!query.containsKey("transport") || !query.get("transport").equals("polling")) { sendErrorMessage(response, ServerErrors.UNKNOWN_TRANSPORT); return; } final String sid = query.get("sid"); if (sid != null) { if(!mClients.containsKey(query.get("sid"))) { sendErrorMessage(response, ServerErrors.UNKNOWN_SID); } else if(!query.containsKey("transport") || !query.get("transport").equals(mClients.get(sid).getCurrentTransportName())) { sendErrorMessage(response, ServerErrors.BAD_REQUEST); } else { mClients.get(sid).onRequest(request, response); } } else { if(!request.getMethod().toUpperCase().equals("GET")) { sendErrorMessage(response, ServerErrors.BAD_HANDSHAKE_METHOD); } else { handshakePolling(request, response); } } } }
EngineIoServer extends Emitter { public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws IOException { final Map<String, String> query = ParseQS.decode(request.getQueryString()); request.setAttribute("query", query); if (!mOptions.isCorsHandlingDisabled()) { final String origin = request.getHeader("Origin"); boolean sendCors = (origin != null) && ((mOptions.getAllowedCorsOrigins() == EngineIoServerOptions.ALLOWED_CORS_ORIGIN_ALL) || (Arrays.binarySearch(mOptions.getAllowedCorsOrigins(), origin) >= 0)); if (sendCors) { response.addHeader("Access-Control-Allow-Origin", origin); response.addHeader("Access-Control-Allow-Credentials", "true"); response.addHeader("Access-Control-Allow-Methods", "GET,HEAD,PUT,PATCH,POST,DELETE"); response.addHeader("Access-Control-Allow-Headers", "origin, content-type, accept"); } } if (!query.containsKey("transport") || !query.get("transport").equals("polling")) { sendErrorMessage(response, ServerErrors.UNKNOWN_TRANSPORT); return; } final String sid = query.get("sid"); if (sid != null) { if(!mClients.containsKey(query.get("sid"))) { sendErrorMessage(response, ServerErrors.UNKNOWN_SID); } else if(!query.containsKey("transport") || !query.get("transport").equals(mClients.get(sid).getCurrentTransportName())) { sendErrorMessage(response, ServerErrors.BAD_REQUEST); } else { mClients.get(sid).onRequest(request, response); } } else { if(!request.getMethod().toUpperCase().equals("GET")) { sendErrorMessage(response, ServerErrors.BAD_HANDSHAKE_METHOD); } else { handshakePolling(request, response); } } } EngineIoServer();  EngineIoServer(EngineIoServerOptions options); }
EngineIoServer extends Emitter { public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws IOException { final Map<String, String> query = ParseQS.decode(request.getQueryString()); request.setAttribute("query", query); if (!mOptions.isCorsHandlingDisabled()) { final String origin = request.getHeader("Origin"); boolean sendCors = (origin != null) && ((mOptions.getAllowedCorsOrigins() == EngineIoServerOptions.ALLOWED_CORS_ORIGIN_ALL) || (Arrays.binarySearch(mOptions.getAllowedCorsOrigins(), origin) >= 0)); if (sendCors) { response.addHeader("Access-Control-Allow-Origin", origin); response.addHeader("Access-Control-Allow-Credentials", "true"); response.addHeader("Access-Control-Allow-Methods", "GET,HEAD,PUT,PATCH,POST,DELETE"); response.addHeader("Access-Control-Allow-Headers", "origin, content-type, accept"); } } if (!query.containsKey("transport") || !query.get("transport").equals("polling")) { sendErrorMessage(response, ServerErrors.UNKNOWN_TRANSPORT); return; } final String sid = query.get("sid"); if (sid != null) { if(!mClients.containsKey(query.get("sid"))) { sendErrorMessage(response, ServerErrors.UNKNOWN_SID); } else if(!query.containsKey("transport") || !query.get("transport").equals(mClients.get(sid).getCurrentTransportName())) { sendErrorMessage(response, ServerErrors.BAD_REQUEST); } else { mClients.get(sid).onRequest(request, response); } } else { if(!request.getMethod().toUpperCase().equals("GET")) { sendErrorMessage(response, ServerErrors.BAD_HANDSHAKE_METHOD); } else { handshakePolling(request, response); } } } EngineIoServer();  EngineIoServer(EngineIoServerOptions options); EngineIoServerOptions getOptions(); @Deprecated long getPingTimeout(); @Deprecated long getPingInterval(); void handleRequest(HttpServletRequest request, HttpServletResponse response); void handleWebSocket(EngineIoWebSocket webSocket); }
EngineIoServer extends Emitter { public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws IOException { final Map<String, String> query = ParseQS.decode(request.getQueryString()); request.setAttribute("query", query); if (!mOptions.isCorsHandlingDisabled()) { final String origin = request.getHeader("Origin"); boolean sendCors = (origin != null) && ((mOptions.getAllowedCorsOrigins() == EngineIoServerOptions.ALLOWED_CORS_ORIGIN_ALL) || (Arrays.binarySearch(mOptions.getAllowedCorsOrigins(), origin) >= 0)); if (sendCors) { response.addHeader("Access-Control-Allow-Origin", origin); response.addHeader("Access-Control-Allow-Credentials", "true"); response.addHeader("Access-Control-Allow-Methods", "GET,HEAD,PUT,PATCH,POST,DELETE"); response.addHeader("Access-Control-Allow-Headers", "origin, content-type, accept"); } } if (!query.containsKey("transport") || !query.get("transport").equals("polling")) { sendErrorMessage(response, ServerErrors.UNKNOWN_TRANSPORT); return; } final String sid = query.get("sid"); if (sid != null) { if(!mClients.containsKey(query.get("sid"))) { sendErrorMessage(response, ServerErrors.UNKNOWN_SID); } else if(!query.containsKey("transport") || !query.get("transport").equals(mClients.get(sid).getCurrentTransportName())) { sendErrorMessage(response, ServerErrors.BAD_REQUEST); } else { mClients.get(sid).onRequest(request, response); } } else { if(!request.getMethod().toUpperCase().equals("GET")) { sendErrorMessage(response, ServerErrors.BAD_HANDSHAKE_METHOD); } else { handshakePolling(request, response); } } } EngineIoServer();  EngineIoServer(EngineIoServerOptions options); EngineIoServerOptions getOptions(); @Deprecated long getPingTimeout(); @Deprecated long getPingInterval(); void handleRequest(HttpServletRequest request, HttpServletResponse response); void handleWebSocket(EngineIoWebSocket webSocket);  }