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

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

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

Route.consumes介绍

[英]Add a content type consumed by this route. Used for content based routing.
[中]

代码示例

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

@Test
public void testConsumesWithQParameterIgnored() throws Exception {
 router.route().consumes("text/html;q").consumes("text/html;q=0.1").handler(rc -> rc.response().end());
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html;boo", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html;boo=yeah,right", 200, "OK");
}

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

@Test
public void testConsumesNoContentType() throws Exception {
 router.route().consumes("text/html").handler(rc -> rc.response().end());
 testRequest(HttpMethod.GET, "/foo", 404, "Not Found");
}

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

@Test
public void testConsumesCTParamsIgnored() throws Exception {
 router.route().consumes("text/html").handler(rc -> rc.response().end());
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html; someparam=12", 200, "OK");
}

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

@Test
public void testConsumesMultiple() throws Exception {
 router.route().consumes("text/html").consumes("application/json").handler(rc -> rc.response().end());
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "application/json", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/json", 404, "Not Found");
 testRequestWithContentType(HttpMethod.GET, "/foo", "something/html", 404, "Not Found");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/json", 404, "Not Found");
 testRequestWithContentType(HttpMethod.GET, "/foo", "application/blah", 404, "Not Found");
}

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

@Test
public void testConsumesWithParameter() throws Exception {
 router.route().consumes("text/html;boo=ya").handler(rc -> rc.response().end());
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html;boo=ya", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html;boo", 404, "Not Found");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html", 404, "Not Found");
}

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

@Test
public void testConsumesVariableParameters() throws Exception {
 router.route().consumes("text/html;boo").consumes("text/html;works").handler(rc -> rc.response().end());
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html;boo", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html;works", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html;boo;works", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html;boo=done;it=works", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html;yes=no;right", 404, "Not Found");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/book;boo", 404, "Not Found");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/book;works=aright", 404, "Not Found");
}

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

@Test
public void testConsumesSubtypeWildcard() throws Exception {
 router.route().consumes("text/*").handler(rc -> rc.response().end());
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/json", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "application/json", 404, "Not Found");
}

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

@Test
public void testConsumes() throws Exception {
 router.route().consumes("text/html").handler(rc -> rc.response().end());
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/json", 404, "Not Found");
 testRequestWithContentType(HttpMethod.GET, "/foo", "something/html", 404, "Not Found");
}

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

@Test
public void testConsumesTopLevelTypeWildcard() throws Exception {
 router.route().consumes("*/json").handler(rc -> rc.response().end());
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/json", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "application/json", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "application/html", 404, "Not Found");
}

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

@Test
public void testConsumesAll2() throws Exception {
 router.route().consumes("*").handler(rc -> rc.response().end());
 testRequestWithContentType(HttpMethod.GET, "/foo", "application/json", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html; someparam=12", 200, "OK");
 testRequest(HttpMethod.GET, "/foo", 200, "OK");
}

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

@Test
public void testConsumesMissingSlash() throws Exception {
 // will assume "*/json"
 router.route().consumes("json").handler(rc -> rc.response().end());
 testRequestWithContentType(HttpMethod.GET, "/foo", "application/json", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "application/json", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/json", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html", 404, "Not Found");
}

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

@Test
public void testConsumesAll1() throws Exception {
 router.route().consumes("*/*").handler(rc -> rc.response().end());
 testRequestWithContentType(HttpMethod.GET, "/foo", "application/json", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html; someparam=12", 200, "OK");
 testRequest(HttpMethod.GET, "/foo", 200, "OK");
}

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

@Test
public void testConsumesWithParameterKey() throws Exception {
 router.route().consumes("text/html;boo").handler(rc -> rc.response().end());
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html;boo=ya;itWorks=4real", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html;boo;itWorks", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html;boo=ya", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html;boo", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html", 404, "Not Found");
}

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

@Test
public void testConsumesWithQuotedParameterWithQuotes() throws Exception {
 router.route().consumes("text/html;boo=\"yeah\\\"right\"").handler(rc -> rc.response().end());
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html;boo=\"yeah\\\"right\"", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html;boo=\"yeah,right\"", 404, "Not Found");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html;boo=yeah,right", 404, "Not Found");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html;boo", 404, "Not Found");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html", 404, "Not Found");
}

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

@Test
public void testConsumesWithQuotedParameterWithComma() throws Exception {
 router.route().consumes("text/html;boo=\"yeah,right\"").handler(rc -> rc.response().end());
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html;boo=\"yeah,right\";itWorks=4real", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html;boo=\"yeah,right\"", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html;boo=\"yeah,right;itWorks=4real\"", 404, "Not Found");
 // this might look wrong but since there is only 1 entry per content-type, the comma has no semantic meaning
 // therefore it is ignored
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html;boo=yeah,right", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html;boo", 404, "Not Found");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html", 404, "Not Found");
}

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

@Test
public void testConsumesCTParamsIgnored() throws Exception {
 router.route().consumes("text/html").handler(rc -> rc.response().end());
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html; someparam=12", 200, "OK");
}

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

@Test
public void testConsumesNoContentType() throws Exception {
 router.route().consumes("text/html").handler(rc -> rc.response().end());
 testRequest(HttpMethod.GET, "/foo", 404, "Not Found");
}

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

@Test
public void testConsumes() throws Exception {
 router.route().consumes("text/html").handler(rc -> rc.response().end());
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/json", 404, "Not Found");
 testRequestWithContentType(HttpMethod.GET, "/foo", "something/html", 404, "Not Found");
}

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

@Test
public void testConsumesWithParameterKey() throws Exception {
 router.route().consumes("text/html;boo").handler(rc -> rc.response().end());
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html;boo=ya;itWorks=4real", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html;boo;itWorks", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html;boo=ya", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html;boo", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html", 404, "Not Found");
}

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

@Test
public void testConsumesWithQuotedParameterWithComma() throws Exception {
 router.route().consumes("text/html;boo=\"yeah,right\"").handler(rc -> rc.response().end());
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html;boo=\"yeah,right\";itWorks=4real", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html;boo=\"yeah,right\"", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html;boo=\"yeah,right;itWorks=4real\"", 404, "Not Found");
 // this might look wrong but since there is only 1 entry per content-type, the comma has no semantic meaning
 // therefore it is ignored
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html;boo=yeah,right", 200, "OK");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html;boo", 404, "Not Found");
 testRequestWithContentType(HttpMethod.GET, "/foo", "text/html", 404, "Not Found");
}

相关文章