@Test public void test_RequestMethodOptions() { String originExpected = "*"; CorsHandler corsHandler = new CorsHandler(originExpected); doReturn("OPTIONS").when(routeContext).getRequestMethod(); corsHandler.handle(routeContext); assertEquals(originExpected, response.getHeader(ACCESS_CONTROL_ALLOW_ORIGIN)); Mockito.verify(routeContext, Mockito.never()).next(); Mockito.verify(response, Mockito.times(1)).accepted(); }
@Override public void handle(RouteContext context) { final Response response = context.getResponse(); response.header(HttpConstants.Header.ACCESS_CONTROL_ALLOW_ORIGIN, allowOrigin); if (exposeHeaders != null) { response.header(HttpConstants.Header.ACCESS_CONTROL_EXPOSE_HEADERS, exposeHeaders); } if (maxAge != -1) { response.header(HttpConstants.Header.ACCESS_CONTROL_MAX_AGE, "" + maxAge); } if (allowCredentials) { response.header(HttpConstants.Header.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true"); } if (allowMethods != null) { response.header(HttpConstants.Header.ACCESS_CONTROL_ALLOW_METHODS, allowMethods); } if (allowHeaders != null) { response.header(HttpConstants.Header.ACCESS_CONTROL_ALLOW_HEADERS, allowHeaders); } if (context.getRequestMethod().equals("OPTIONS")) { response.accepted(); return; } context.next(); }
CorsHandler implements RouteHandler<RouteContext> { @Override public void handle(RouteContext context) { final Response response = context.getResponse(); response.header(HttpConstants.Header.ACCESS_CONTROL_ALLOW_ORIGIN, allowOrigin); if (exposeHeaders != null) { response.header(HttpConstants.Header.ACCESS_CONTROL_EXPOSE_HEADERS, exposeHeaders); } if (maxAge != -1) { response.header(HttpConstants.Header.ACCESS_CONTROL_MAX_AGE, "" + maxAge); } if (allowCredentials) { response.header(HttpConstants.Header.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true"); } if (allowMethods != null) { response.header(HttpConstants.Header.ACCESS_CONTROL_ALLOW_METHODS, allowMethods); } if (allowHeaders != null) { response.header(HttpConstants.Header.ACCESS_CONTROL_ALLOW_HEADERS, allowHeaders); } if (context.getRequestMethod().equals("OPTIONS")) { response.accepted(); return; } context.next(); } }
CorsHandler implements RouteHandler<RouteContext> { @Override public void handle(RouteContext context) { final Response response = context.getResponse(); response.header(HttpConstants.Header.ACCESS_CONTROL_ALLOW_ORIGIN, allowOrigin); if (exposeHeaders != null) { response.header(HttpConstants.Header.ACCESS_CONTROL_EXPOSE_HEADERS, exposeHeaders); } if (maxAge != -1) { response.header(HttpConstants.Header.ACCESS_CONTROL_MAX_AGE, "" + maxAge); } if (allowCredentials) { response.header(HttpConstants.Header.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true"); } if (allowMethods != null) { response.header(HttpConstants.Header.ACCESS_CONTROL_ALLOW_METHODS, allowMethods); } if (allowHeaders != null) { response.header(HttpConstants.Header.ACCESS_CONTROL_ALLOW_HEADERS, allowHeaders); } if (context.getRequestMethod().equals("OPTIONS")) { response.accepted(); return; } context.next(); } CorsHandler(String allowOrigin); }
CorsHandler implements RouteHandler<RouteContext> { @Override public void handle(RouteContext context) { final Response response = context.getResponse(); response.header(HttpConstants.Header.ACCESS_CONTROL_ALLOW_ORIGIN, allowOrigin); if (exposeHeaders != null) { response.header(HttpConstants.Header.ACCESS_CONTROL_EXPOSE_HEADERS, exposeHeaders); } if (maxAge != -1) { response.header(HttpConstants.Header.ACCESS_CONTROL_MAX_AGE, "" + maxAge); } if (allowCredentials) { response.header(HttpConstants.Header.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true"); } if (allowMethods != null) { response.header(HttpConstants.Header.ACCESS_CONTROL_ALLOW_METHODS, allowMethods); } if (allowHeaders != null) { response.header(HttpConstants.Header.ACCESS_CONTROL_ALLOW_HEADERS, allowHeaders); } if (context.getRequestMethod().equals("OPTIONS")) { response.accepted(); return; } context.next(); } CorsHandler(String allowOrigin); @Override void handle(RouteContext context); CorsHandler exposeHeaders(String exposeHeaders); CorsHandler maxAge(int maxAgeInSeconds); CorsHandler allowCredentials(boolean allowCredentials); CorsHandler allowMethods(String allowMethods); CorsHandler allowHeaders(String allowHeaders); String details(); }
CorsHandler implements RouteHandler<RouteContext> { @Override public void handle(RouteContext context) { final Response response = context.getResponse(); response.header(HttpConstants.Header.ACCESS_CONTROL_ALLOW_ORIGIN, allowOrigin); if (exposeHeaders != null) { response.header(HttpConstants.Header.ACCESS_CONTROL_EXPOSE_HEADERS, exposeHeaders); } if (maxAge != -1) { response.header(HttpConstants.Header.ACCESS_CONTROL_MAX_AGE, "" + maxAge); } if (allowCredentials) { response.header(HttpConstants.Header.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true"); } if (allowMethods != null) { response.header(HttpConstants.Header.ACCESS_CONTROL_ALLOW_METHODS, allowMethods); } if (allowHeaders != null) { response.header(HttpConstants.Header.ACCESS_CONTROL_ALLOW_HEADERS, allowHeaders); } if (context.getRequestMethod().equals("OPTIONS")) { response.accepted(); return; } context.next(); } CorsHandler(String allowOrigin); @Override void handle(RouteContext context); CorsHandler exposeHeaders(String exposeHeaders); CorsHandler maxAge(int maxAgeInSeconds); CorsHandler allowCredentials(boolean allowCredentials); CorsHandler allowMethods(String allowMethods); CorsHandler allowHeaders(String allowHeaders); String details();  }