Codota Logo
CorsHandler.create
Code IndexAdd Codota to your IDE (free)

How to use
create
method
in
io.vertx.ext.web.handler.CorsHandler

Best Java code snippets using io.vertx.ext.web.handler.CorsHandler.create (Showing top 20 results out of 315)

  • Common ways to obtain CorsHandler
private void myMethod () {
CorsHandler c =
  • Codota IconCorsHandler corsHandler;corsHandler.maxAgeSeconds(maxAgeSeconds)
  • Smart code suggestions by Codota
}
origin: vert-x3/vertx-examples

allowedMethods.add(HttpMethod.PUT);
router.route().handler(CorsHandler.create("*").allowedHeaders(allowedHeaders).allowedMethods(allowedMethods));
origin: apache/servicecomb-java-chassis

private CorsHandler getCorsHandler(String corsAllowedOrigin) {
 return CorsHandler.create(corsAllowedOrigin);
}
origin: vert-x3/vertx-web

@Test(expected=NullPointerException.class)
public void testNullAllowedOrigin() throws Exception {
 CorsHandler.create(null);
}
origin: vert-x3/vertx-web

@Test
public void testUnsecureCorsShouldNotBeAllowed() throws Exception {
 try {
  CorsHandler.create("*").allowCredentials(true);
  fail("Should not be allowed!");
 } catch (IllegalStateException e) {
  // OK
 }
}
origin: vert-x3/vertx-web

@Test
public void testPreflightAllowedHeaders() throws Exception {
 Set<HttpMethod> allowedMethods = new LinkedHashSet<>(Arrays.asList(HttpMethod.PUT, HttpMethod.DELETE));
 Set<String> allowedHeaders = new LinkedHashSet<>(Arrays.asList("X-wibble", "X-blah"));
 router.route().handler(CorsHandler.create("vertx\\.io").allowedMethods(allowedMethods).allowedHeaders(allowedHeaders));
 router.route().handler(context -> context.response().end());
 testRequest(HttpMethod.OPTIONS, "/", req -> {
  req.headers().add("origin", "vertx.io");
  req.headers().add("access-control-request-method", "PUT,DELETE");
  req.headers().add("access-control-request-headers", allowedHeaders);
 }, resp -> checkHeaders(resp, "vertx.io", "PUT,DELETE", "X-wibble,X-blah", null), 200, "OK", null);
}
origin: vert-x3/vertx-web

@Test
public void testPreflightMaxAge() throws Exception {
 Set<HttpMethod> allowedMethods = new LinkedHashSet<>(Arrays.asList(HttpMethod.PUT, HttpMethod.DELETE));
 int maxAge = 131233;
 router.route().handler(CorsHandler.create("vertx\\.io").allowedMethods(allowedMethods).maxAgeSeconds(maxAge));
 router.route().handler(context -> context.response().end());
 testRequest(HttpMethod.OPTIONS, "/", req -> {
  req.headers().add("origin", "vertx.io");
  req.headers().add("access-control-request-method", "PUT,DELETE");
 }, resp -> checkHeaders(resp, "vertx.io", "PUT,DELETE", null, null, null, String.valueOf(maxAge)), 200, "OK", null);
}
origin: vert-x3/vertx-web

@Test
public void testRealRequestCredentialsNoWildcardOrigin() throws Exception {
 Set<HttpMethod> allowedMethods = new LinkedHashSet<>(Arrays.asList(HttpMethod.PUT, HttpMethod.DELETE));
 router.route().handler(CorsHandler.create("vertx.*").allowedMethods(allowedMethods).allowCredentials(true));
 router.route().handler(context -> context.response().end());
 testRequest(HttpMethod.GET, "/", req -> req.headers().add("origin", "vertx.io"), resp -> checkHeaders(resp, "vertx.io", null, null, null, "true", null), 200, "OK", null);
}
origin: vert-x3/vertx-web

@Test
public void testRealRequestAllowCredentials() throws Exception {
 Set<HttpMethod> allowedMethods = new LinkedHashSet<>(Arrays.asList(HttpMethod.PUT, HttpMethod.DELETE));
 router.route().handler(CorsHandler.create("vertx\\.io").allowedMethods(allowedMethods).allowCredentials(true));
 router.route().handler(context -> context.response().end());
 testRequest(HttpMethod.GET, "/", req -> req.headers().add("origin", "vertx.io"), resp -> checkHeaders(resp, "vertx.io", null, null, null, "true", null), 200, "OK", null);
}
origin: vert-x3/vertx-web

@Test
public void testNotCORSRequest() throws Exception {
 router.route().handler(CorsHandler.create("vertx\\.io"));
 router.route().handler(context -> context.response().end());
 testRequest(HttpMethod.GET, "/", null, resp -> checkHeaders(resp, null, null, null, null), 200, "OK", null);
}
origin: vert-x3/vertx-web

@Test
public void testPreflightSimple() throws Exception {
 Set<HttpMethod> allowedMethods = new LinkedHashSet<>(Arrays.asList(HttpMethod.PUT, HttpMethod.DELETE));
 router.route().handler(CorsHandler.create("vertx\\.io").allowedMethods(allowedMethods));
 router.route().handler(context -> context.response().end());
 testRequest(HttpMethod.OPTIONS, "/", req -> {
  req.headers().add("origin", "vertx.io");
  req.headers().add("access-control-request-method", "PUT,DELETE");
 }, resp -> checkHeaders(resp, "vertx.io", "PUT,DELETE", null, null), 200, "OK", null);
}
origin: vert-x3/vertx-web

@Test
public void testPreflightAllowCredentialsNoWildcardOrigin() throws Exception {
 Set<HttpMethod> allowedMethods = new LinkedHashSet<>(Arrays.asList(HttpMethod.PUT, HttpMethod.DELETE));
 // Make sure * isn't returned in access-control-allow-origin for credentials
 router.route().handler(CorsHandler.create("vertx.*").allowedMethods(allowedMethods).allowCredentials(true));
 router.route().handler(context -> context.response().end());
 testRequest(HttpMethod.OPTIONS, "/", req -> {
  req.headers().add("origin", "vertx.io");
  req.headers().add("access-control-request-method", "PUT,DELETE");
 }, resp -> checkHeaders(resp, "vertx.io", "PUT,DELETE", null, null, "true", null), 200, "OK", null);
}
origin: vert-x3/vertx-web

@Test
public void testPreflightAllowCredentials() throws Exception {
 Set<HttpMethod> allowedMethods = new LinkedHashSet<>(Arrays.asList(HttpMethod.PUT, HttpMethod.DELETE));
 router.route().handler(CorsHandler.create("vertx\\.io").allowedMethods(allowedMethods).allowCredentials(true));
 router.route().handler(context -> context.response().end());
 testRequest(HttpMethod.OPTIONS, "/", req -> {
  req.headers().add("origin", "vertx.io");
  req.headers().add("access-control-request-method", "PUT,DELETE");
 }, resp -> checkHeaders(resp, "vertx.io", "PUT,DELETE", null, null, "true", null), 200, "OK", null);
}
origin: vert-x3/vertx-web

@Test
public void testAcceptDotisAnyCharacter2() throws Exception {
 router.route().handler(CorsHandler.create("vertx.io")); // dot matches any character - watch out!
 router.route().handler(context -> context.response().end());
 testRequest(HttpMethod.GET, "/", req -> req.headers().add("origin", "vertx.io"), resp -> checkHeaders(resp, "vertx.io", null, null, null), 200, "OK", null);
}
origin: vert-x3/vertx-web

@Test
public void testAcceptConstantOriginDenied1() throws Exception {
 router.route().handler(CorsHandler.create("vertx\\.io"));
 router.route().handler(context -> context.response().end());
 testRequest(HttpMethod.GET, "/", req -> req.headers().add("origin", "foo.io"), resp -> checkHeaders(resp, null, null, null, null), 403, "CORS Rejected - Invalid origin", null);
}
origin: vert-x3/vertx-web

@Test
public void testAcceptAllAllowedOrigin() throws Exception {
 router.route().handler(CorsHandler.create("*"));
 router.route().handler(context -> context.response().end());
 testRequest(HttpMethod.GET, "/", req -> req.headers().add("origin", "vertx.io"), resp -> checkHeaders(resp, "*", null, null, null), 200, "OK", null);
}
origin: vert-x3/vertx-web

@Test
public void testAcceptDotisAnyCharacter1() throws Exception {
 router.route().handler(CorsHandler.create("vertx.io")); // dot matches any character - watch out!
 router.route().handler(context -> context.response().end());
 testRequest(HttpMethod.GET, "/", req -> req.headers().add("origin", "vertxxio"), resp -> checkHeaders(resp, "vertxxio", null, null, null), 200, "OK", null);
}
origin: vert-x3/vertx-web

@Test
public void testAcceptConstantOrigin() throws Exception {
 router.route().handler(CorsHandler.create("vertx\\.io"));
 router.route().handler(context -> context.response().end());
 testRequest(HttpMethod.GET, "/", req -> req.headers().add("origin", "vertx.io"), resp -> checkHeaders(resp, "vertx.io", null, null, null), 200, "OK", null);
}
origin: vert-x3/vertx-web

@Test
public void testAcceptConstantOriginDenied2() throws Exception {
 router.route().handler(CorsHandler.create("vertx\\.io"));
 router.route().handler(context -> context.response().end());
 testRequest(HttpMethod.GET, "/", req -> {
  // Make sure the '.' doesn't match like a regex
  req.headers().add("origin", "fooxio");
 }, resp -> checkHeaders(resp, null, null, null, null), 403, "CORS Rejected - Invalid origin", null);
}
origin: vert-x3/vertx-web

@Test
public void testAcceptPatternDenied() throws Exception {
 // Any subdomains of vertx.io
 router.route().handler(CorsHandler.create(".*\\.vertx\\.io"));
 router.route().handler(context -> context.response().end());
 testRequest(HttpMethod.GET, "/", req -> req.headers().add("origin", "foo.vertx.com"), resp -> checkHeaders(resp, null, null, null, null), 403, "CORS Rejected - Invalid origin", null);
 testRequest(HttpMethod.GET, "/", req -> req.headers().add("origin", "barxvertxxio"), resp -> checkHeaders(resp, null, null, null, null), 403, "CORS Rejected - Invalid origin", null);
}
origin: vert-x3/vertx-web

@Test
public void testAcceptPattern() throws Exception {
 // Any subdomains of vertx.io
 router.route().handler(CorsHandler.create(".*\\.vertx\\.io"));
 router.route().handler(context -> context.response().end());
 testRequest(HttpMethod.GET, "/", req -> req.headers().add("origin", "foo.vertx.io"), resp -> checkHeaders(resp, "foo.vertx.io", null, null, null), 200, "OK", null);
 testRequest(HttpMethod.GET, "/", req -> req.headers().add("origin", "bar.vertx.io"), resp -> checkHeaders(resp, "bar.vertx.io", null, null, null), 200, "OK", null);
 testRequest(HttpMethod.GET, "/", req -> req.headers().add("origin", "wibble.bar.vertx.io"), resp -> checkHeaders(resp, "wibble.bar.vertx.io", null, null, null), 200, "OK", null);
}
io.vertx.ext.web.handlerCorsHandlercreate

Javadoc

Create a CORS handler

Popular methods of CorsHandler

  • allowedHeaders
    Add a set of allowed headers
  • allowCredentials
    Set whether credentials are allowed. Note that user agents will block requests that use a wildcard a
  • allowedMethod
    Add an allowed method
  • allowedMethods
    Add a set of allowed methods
  • maxAgeSeconds
    Set how long the browser should cache the information
  • allowedHeader
    Add an allowed header
  • exposedHeader
    Add an exposed header
  • exposedHeaders
    Add a set of exposed headers
  • handle

Popular in Java

  • Finding current android device location
  • getApplicationContext (Context)
  • findViewById (Activity)
  • scheduleAtFixedRate (ScheduledExecutorService)
    Creates and executes a periodic action that becomes enabled first after the given initial delay, and
  • FileNotFoundException (java.io)
    Thrown when a file specified by a program cannot be found.
  • InputStream (java.io)
    A readable source of bytes.Most clients will use input streams that read data from the file system (
  • BigInteger (java.math)
    Immutable arbitrary-precision integers. All operations behave as if BigIntegers were represented in
  • KeyStore (java.security)
    This class represents an in-memory collection of keys and certificates. It manages two types of entr
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
  • JFileChooser (javax.swing)
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now