io.vertx.ext.web.Router.optionsWithRegex()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(5.4k)|赞(0)|评价(0)|浏览(91)

本文整理了Java中io.vertx.ext.web.Router.optionsWithRegex方法的一些代码示例,展示了Router.optionsWithRegex的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Router.optionsWithRegex方法的具体详情如下:
包路径:io.vertx.ext.web.Router
类名称:Router
方法名:optionsWithRegex

Router.optionsWithRegex介绍

[英]Add a route that matches a HTTP OPTIONS request and the specified path regex
[中]

代码示例

代码示例来源:origin: vert-x3/vertx-web

XhrTransport(Vertx vertx, Router router, LocalMap<String, SockJSSession> sessions, SockJSHandlerOptions options,
       Handler<SockJSSocket> sockHandler) {
 super(vertx, sessions, options);
 String xhrBase = COMMON_PATH_ELEMENT_RE;
 String xhrRE = xhrBase + "xhr";
 String xhrStreamRE = xhrBase + "xhr_streaming";
 Handler<RoutingContext> xhrOptionsHandler = createCORSOptionsHandler(options, "OPTIONS, POST");
 router.optionsWithRegex(xhrRE).handler(xhrOptionsHandler);
 router.optionsWithRegex(xhrStreamRE).handler(xhrOptionsHandler);
 registerHandler(router, sockHandler, xhrRE, false, options);
 registerHandler(router, sockHandler, xhrStreamRE, true, options);
 String xhrSendRE = COMMON_PATH_ELEMENT_RE + "xhr_send";
 router.optionsWithRegex(xhrSendRE).handler(xhrOptionsHandler);
 router.postWithRegex(xhrSendRE).handler(rc -> {
  if (log.isTraceEnabled()) log.trace("XHR send, post, " + rc.request().uri());
  String sessionID = rc.request().getParam("param0");
  final SockJSSession session = sessions.get(sessionID);
  if (session != null && !session.isClosed()) {
   handleSend(rc, session);
  } else {
   rc.response().setStatusCode(404);
   setJSESSIONID(options, rc);
   rc.response().end();
  }
 });
}

代码示例来源:origin: org.zalando/vertx-swagger

@Override
public Route optionsWithRegex(String regex) {
  return router.optionsWithRegex(regex);
}

代码示例来源:origin: vert-x3/vertx-web

@Test
public void testOptionsWithRegex() throws Exception {
 router.optionsWithRegex("\\/somepath\\/.*").handler(rc -> rc.response().setStatusMessage("foo").end());
 testRequest(HttpMethod.OPTIONS, "/somepath/whatever", 200, "foo");
 testRequest(HttpMethod.OPTIONS, "/otherpath/whatever", 404, "Not Found");
 testRequest(HttpMethod.GET, "/somepath/whatever", 404, "Not Found");
 testRequest(HttpMethod.POST, "/somepath/whatever", 404, "Not Found");
 testRequest(HttpMethod.PUT, "/somepath/whatever", 404, "Not Found");
 testRequest(HttpMethod.DELETE, "/somepath/whatever", 404, "Not Found");
 testRequest(HttpMethod.HEAD, "/somepath/whatever", 404, "Not Found");
}

代码示例来源:origin: vert-x3/vertx-rx

/**
 * Add a route that matches a HTTP OPTIONS request and the specified path regex
 * @param regex URI paths that begin with a match for this regex will match
 * @return the route
 */
public io.vertx.rxjava.ext.web.Route optionsWithRegex(String regex) { 
 io.vertx.rxjava.ext.web.Route ret = io.vertx.rxjava.ext.web.Route.newInstance(delegate.optionsWithRegex(regex));
 return ret;
}

代码示例来源:origin: io.vertx/vertx-rx-java

/**
 * Add a route that matches a HTTP OPTIONS request and the specified path regex
 * @param regex URI paths that begin with a match for this regex will match
 * @return the route
 */
public io.vertx.rxjava.ext.web.Route optionsWithRegex(String regex) { 
 io.vertx.rxjava.ext.web.Route ret = io.vertx.rxjava.ext.web.Route.newInstance(delegate.optionsWithRegex(regex));
 return ret;
}

代码示例来源:origin: wang007/vertx-start

@Override
public io.vertx.ext.web.Route optionsWithRegex(String regex) {
  return delegate.optionsWithRegex(getFullPath(regex));
}

代码示例来源:origin: io.vertx/vertx-web

XhrTransport(Vertx vertx, Router router, LocalMap<String, SockJSSession> sessions, SockJSHandlerOptions options,
       Handler<SockJSSocket> sockHandler) {
 super(vertx, sessions, options);
 String xhrBase = COMMON_PATH_ELEMENT_RE;
 String xhrRE = xhrBase + "xhr";
 String xhrStreamRE = xhrBase + "xhr_streaming";
 Handler<RoutingContext> xhrOptionsHandler = createCORSOptionsHandler(options, "OPTIONS, POST");
 router.optionsWithRegex(xhrRE).handler(xhrOptionsHandler);
 router.optionsWithRegex(xhrStreamRE).handler(xhrOptionsHandler);
 registerHandler(router, sockHandler, xhrRE, false, options);
 registerHandler(router, sockHandler, xhrStreamRE, true, options);
 String xhrSendRE = COMMON_PATH_ELEMENT_RE + "xhr_send";
 router.optionsWithRegex(xhrSendRE).handler(xhrOptionsHandler);
 router.postWithRegex(xhrSendRE).handler(rc -> {
  if (log.isTraceEnabled()) log.trace("XHR send, post, " + rc.request().uri());
  String sessionID = rc.request().getParam("param0");
  final SockJSSession session = sessions.get(sessionID);
  if (session != null && !session.isClosed()) {
   handleSend(rc, session);
  } else {
   rc.response().setStatusCode(404);
   setJSESSIONID(options, rc);
   rc.response().end();
  }
 });
}

代码示例来源:origin: io.vertx/vertx-web

@Test
public void testOptionsWithRegex() throws Exception {
 router.optionsWithRegex("\\/somepath\\/.*").handler(rc -> rc.response().setStatusMessage("foo").end());
 testRequest(HttpMethod.OPTIONS, "/somepath/whatever", 200, "foo");
 testRequest(HttpMethod.OPTIONS, "/otherpath/whatever", 404, "Not Found");
 testRequest(HttpMethod.GET, "/somepath/whatever", 404, "Not Found");
 testRequest(HttpMethod.POST, "/somepath/whatever", 404, "Not Found");
 testRequest(HttpMethod.PUT, "/somepath/whatever", 404, "Not Found");
 testRequest(HttpMethod.DELETE, "/somepath/whatever", 404, "Not Found");
 testRequest(HttpMethod.HEAD, "/somepath/whatever", 404, "Not Found");
}

相关文章