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