/** * Add an allowed header * @param headerName the allowed header name * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.ext.web.handler.CorsHandler allowedHeader(String headerName) { delegate.allowedHeader(headerName); return this; }
@Test public void testChaining() throws Exception { CorsHandler cors = CorsHandler.create("*"); assertNotNull(cors); assertSame(cors, cors.allowedMethod(HttpMethod.POST)); assertSame(cors, cors.allowedMethod(HttpMethod.DELETE)); assertSame(cors, cors.allowedMethods(new HashSet<>())); assertSame(cors, cors.allowedHeader("X-foo")); assertSame(cors, cors.allowedHeader("X-bar")); assertSame(cors, cors.allowedHeaders(new HashSet<>())); assertSame(cors, cors.exposedHeader("X-wibble")); assertSame(cors, cors.exposedHeader("X-blah")); assertSame(cors, cors.exposedHeaders(new HashSet<>())); }
@Test public void testChaining() throws Exception { CorsHandler cors = CorsHandler.create("*"); assertNotNull(cors); assertSame(cors, cors.allowedMethod(HttpMethod.POST)); assertSame(cors, cors.allowedMethod(HttpMethod.DELETE)); assertSame(cors, cors.allowedMethods(new HashSet<>())); assertSame(cors, cors.allowedHeader("X-foo")); assertSame(cors, cors.allowedHeader("X-bar")); assertSame(cors, cors.allowedHeaders(new HashSet<>())); assertSame(cors, cors.exposedHeader("X-wibble")); assertSame(cors, cors.exposedHeader("X-blah")); assertSame(cors, cors.exposedHeaders(new HashSet<>())); }
/** * Add an allowed header * @param headerName the allowed header name * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.ext.web.handler.CorsHandler allowedHeader(String headerName) { delegate.allowedHeader(headerName); return this; }
corsHandler.allowedHeader((String)allowHeaders); } else if (allowHeaders instanceof JsonArray) { corsHandler.allowedHeaders(Seq.seq((JsonArray)allowHeaders)
.allowedHeader(Constants.HEADER_QOS_LEVEL) .allowedHeader(Constants.HEADER_TIME_TIL_DISCONNECT) .allowedHeader(HttpHeaders.AUTHORIZATION.toString()) .allowedHeader(HttpHeaders.CONTENT_TYPE.toString())); .allowedHeader(Constants.HEADER_QOS_LEVEL) .allowedHeader(Constants.HEADER_TIME_TIL_DISCONNECT) .allowedHeader(HttpHeaders.AUTHORIZATION.toString()) .allowedHeader(HttpHeaders.CONTENT_TYPE.toString()));
.allowedHeader(Constants.HEADER_QOS_LEVEL) .allowedHeader(Constants.HEADER_TIME_TIL_DISCONNECT) .allowedHeader(HttpHeaders.AUTHORIZATION.toString()) .allowedHeader(HttpHeaders.CONTENT_TYPE.toString()) .exposedHeader(Constants.HEADER_COMMAND) .exposedHeader(Constants.HEADER_COMMAND_REQUEST_ID)); .allowedHeader(Constants.HEADER_QOS_LEVEL) .allowedHeader(Constants.HEADER_TIME_TIL_DISCONNECT) .allowedHeader(HttpHeaders.AUTHORIZATION.toString()) .allowedHeader(HttpHeaders.CONTENT_TYPE.toString()) .exposedHeader(Constants.HEADER_COMMAND) .exposedHeader(Constants.HEADER_COMMAND_REQUEST_ID));
private void addEventApiRoutes(final Router router, final Handler<RoutingContext> authHandler) { // support CORS headers for PUTing events router.routeWithRegex("\\/event\\/[^\\/]+\\/.*").handler(CorsHandler.create(getConfig().getCorsAllowedOrigin()) .allowedMethod(HttpMethod.PUT) .allowedHeader(Constants.HEADER_TIME_TIL_DISCONNECT) .allowedHeader(HttpHeaders.AUTHORIZATION.toString()) .allowedHeader(HttpHeaders.CONTENT_TYPE.toString())); if (getConfig().isAuthenticationRequired()) { // support CORS headers for POSTing events router.route("/event").handler(CorsHandler.create(getConfig().getCorsAllowedOrigin()) .allowedMethod(HttpMethod.POST) .allowedHeader(Constants.HEADER_TIME_TIL_DISCONNECT) .allowedHeader(HttpHeaders.AUTHORIZATION.toString()) .allowedHeader(HttpHeaders.CONTENT_TYPE.toString())); // require auth for POSTing events router.route(HttpMethod.POST, "/event").handler(authHandler); // route for posting events using tenant and device ID determined as part of // device authentication router.route(HttpMethod.POST, "/event").handler(this::handlePostEvent); // require auth for PUTing events router.route(HttpMethod.PUT, "/event/*").handler(authHandler); // route for asserting that authenticated device's tenant matches tenant from path variables router.route(HttpMethod.PUT, String.format("/event/:%s/:%s", PARAM_TENANT, PARAM_DEVICE_ID)) .handler(this::assertTenant); } // route for sending event messages router.route(HttpMethod.PUT, String.format("/event/:%s/:%s", PARAM_TENANT, PARAM_DEVICE_ID)) .handler(ctx -> uploadEventMessage(ctx, getTenantParam(ctx), getDeviceIdParam(ctx))); }
.allowedMethod(HttpMethod.POST) .allowedHeader(HttpHeaders.CONTENT_TYPE.toString()) .allowedHeader(XOkapiHeaders.TENANT) .allowedHeader(XOkapiHeaders.TOKEN) .allowedHeader(XOkapiHeaders.AUTHORIZATION) .allowedHeader(XOkapiHeaders.REQUEST_ID) //expose response headers .exposedHeader(HttpHeaders.LOCATION.toString()) .exposedHeader(XOkapiHeaders.TRACE)
.allowedHeader(Constants.HEADER_COMMAND_RESPONSE_STATUS) .allowedHeader(HttpHeaders.AUTHORIZATION.toString()) .allowedHeader(HttpHeaders.CONTENT_TYPE.toString())); .allowedHeader(Constants.HEADER_COMMAND_RESPONSE_STATUS) .allowedHeader(HttpHeaders.AUTHORIZATION.toString()) .allowedHeader(HttpHeaders.CONTENT_TYPE.toString()));
.allowedHeader(Constants.HEADER_COMMAND_RESPONSE_STATUS) .allowedHeader(HttpHeaders.AUTHORIZATION.toString()) .allowedHeader(HttpHeaders.CONTENT_TYPE.toString())); .allowedHeader(Constants.HEADER_COMMAND_RESPONSE_STATUS) .allowedHeader(HttpHeaders.AUTHORIZATION.toString()) .allowedHeader(HttpHeaders.CONTENT_TYPE.toString()));
.allowedHeader(Constants.HEADER_TIME_TIL_DISCONNECT) .allowedHeader(HttpHeaders.AUTHORIZATION.toString()) .allowedHeader(HttpHeaders.CONTENT_TYPE.toString()) .exposedHeader(Constants.HEADER_COMMAND) .exposedHeader(Constants.HEADER_COMMAND_REQUEST_ID)); .allowedHeader(Constants.HEADER_TIME_TIL_DISCONNECT) .allowedHeader(HttpHeaders.AUTHORIZATION.toString()) .allowedHeader(HttpHeaders.CONTENT_TYPE.toString()) .exposedHeader(Constants.HEADER_COMMAND) .exposedHeader(Constants.HEADER_COMMAND_REQUEST_ID));