CorsEnabledAuth implements HttpFunction { @Override public void service(HttpRequest request, HttpResponse response) throws IOException { response.appendHeader("Access-Control-Allow-Origin", "https: response.appendHeader("Access-Control-Allow-Credentials", "true"); if ("OPTIONS".equals(request.getMethod())) { response.appendHeader("Access-Control-Allow-Methods", "GET"); response.appendHeader("Access-Control-Allow-Headers", "Authorization"); response.appendHeader("Access-Control-Max-Age", "3600"); response.setStatusCode(HttpURLConnection.HTTP_NO_CONTENT); return; } BufferedWriter writer = response.getWriter(); writer.write("CORS headers set successfully!"); }  @Override void service(HttpRequest request, HttpResponse response);  }
@Test public void corsEnabledAuthTest() throws IOException { when(request.getMethod()).thenReturn("GET"); new CorsEnabledAuth().service(request, response); writerOut.flush(); assertThat(responseOut.toString()).contains("CORS headers set successfully!"); }