@Test public void validateOrigin_disallowedOrigin() { handler = new CorsHandler("http: boolean valid = validateOrigin( "get", ImmutableMap.of("Origin", "http: ImmutableMap.of("vary", "origin") ); assertThat(valid).isFalse(); }
boolean validateOrigin(HttpServerExchange exchange) { HeaderMap responseHeaders = exchange.getResponseHeaders(); responseHeaders.put(VARY, "origin"); String origin = exchange.getRequestHeaders().getFirst(ORIGIN); if (origin == null) return true; return setOrigin(origin, responseHeaders); }
CorsHandler implements HttpHandler, HandlerWrapper { boolean validateOrigin(HttpServerExchange exchange) { HeaderMap responseHeaders = exchange.getResponseHeaders(); responseHeaders.put(VARY, "origin"); String origin = exchange.getRequestHeaders().getFirst(ORIGIN); if (origin == null) return true; return setOrigin(origin, responseHeaders); } }
CorsHandler implements HttpHandler, HandlerWrapper { boolean validateOrigin(HttpServerExchange exchange) { HeaderMap responseHeaders = exchange.getResponseHeaders(); responseHeaders.put(VARY, "origin"); String origin = exchange.getRequestHeaders().getFirst(ORIGIN); if (origin == null) return true; return setOrigin(origin, responseHeaders); } CorsHandler(String allowedOrigins); }
CorsHandler implements HttpHandler, HandlerWrapper { boolean validateOrigin(HttpServerExchange exchange) { HeaderMap responseHeaders = exchange.getResponseHeaders(); responseHeaders.put(VARY, "origin"); String origin = exchange.getRequestHeaders().getFirst(ORIGIN); if (origin == null) return true; return setOrigin(origin, responseHeaders); } CorsHandler(String allowedOrigins); @Override void handleRequest(HttpServerExchange exchange); @Override HttpHandler wrap(HttpHandler handler); }
CorsHandler implements HttpHandler, HandlerWrapper { boolean validateOrigin(HttpServerExchange exchange) { HeaderMap responseHeaders = exchange.getResponseHeaders(); responseHeaders.put(VARY, "origin"); String origin = exchange.getRequestHeaders().getFirst(ORIGIN); if (origin == null) return true; return setOrigin(origin, responseHeaders); } CorsHandler(String allowedOrigins); @Override void handleRequest(HttpServerExchange exchange); @Override HttpHandler wrap(HttpHandler handler);  }