List of usage examples for io.netty.handler.codec.http HttpMethod HEAD
HttpMethod HEAD
To view the source code for io.netty.handler.codec.http HttpMethod HEAD.
Click Source Link
From source file:com.github.ambry.rest.NettyResponseChannelTest.java
License:Open Source License
/** * Tests keep-alive for different HTTP methods and error statuses. *//*from w w w . j a va 2 s. co m*/ @Test public void keepAliveTest() { HttpMethod[] HTTP_METHODS = { HttpMethod.POST, HttpMethod.GET, HttpMethod.HEAD, HttpMethod.DELETE }; EmbeddedChannel channel = createEmbeddedChannel(); for (HttpMethod httpMethod : HTTP_METHODS) { for (Map.Entry<RestServiceErrorCode, HttpResponseStatus> entry : REST_ERROR_CODE_TO_HTTP_STATUS .entrySet()) { HttpHeaders httpHeaders = new DefaultHttpHeaders(); httpHeaders.set(MockNettyMessageProcessor.REST_SERVICE_ERROR_CODE_HEADER_NAME, entry.getKey()); channel.writeInbound(RestTestUtils.createRequest(httpMethod, TestingUri.OnResponseCompleteWithRestException.toString(), httpHeaders)); HttpResponse response = (HttpResponse) channel.readOutbound(); assertEquals("Unexpected response status", entry.getValue(), response.getStatus()); if (!(response instanceof FullHttpResponse)) { // empty the channel while (channel.readOutbound() != null) { } } boolean shouldBeAlive = !httpMethod.equals(HttpMethod.POST) && !NettyResponseChannel.CLOSE_CONNECTION_ERROR_STATUSES.contains(entry.getValue()); assertEquals("Channel state (open/close) not as expected", shouldBeAlive, channel.isActive()); assertEquals("Connection header should be consistent with channel state", shouldBeAlive, HttpHeaders.isKeepAlive(response)); if (!shouldBeAlive) { channel = createEmbeddedChannel(); } } } channel.close(); }
From source file:com.github.jonbonazza.puni.core.mux.DefaultMuxer.java
License:Apache License
public DefaultMuxer() { methodMap.put(HttpMethod.CONNECT, new HashMap<>()); methodMap.put(HttpMethod.DELETE, new HashMap<>()); methodMap.put(HttpMethod.GET, new HashMap<>()); methodMap.put(HttpMethod.HEAD, new HashMap<>()); methodMap.put(HttpMethod.OPTIONS, new HashMap<>()); methodMap.put(HttpMethod.PATCH, new HashMap<>()); methodMap.put(HttpMethod.POST, new HashMap<>()); methodMap.put(HttpMethod.PUT, new HashMap<>()); methodMap.put(HttpMethod.TRACE, new HashMap<>()); }
From source file:com.linecorp.armeria.client.http.SimpleHttpRequestBuilder.java
License:Apache License
/** * Returns a {@link SimpleHttpRequestBuilder} for a HEAD request to the given URI, * for setting additional HTTP parameters as needed. *//*from w w w .ja v a2s . co m*/ public static SimpleHttpRequestBuilder forHead(String uri) { return createRequestBuilder(uri, HttpMethod.HEAD); }
From source file:com.linecorp.armeria.client.http.SimpleHttpRequestBuilderTest.java
License:Apache License
@Test public void httpMethods() { assertEquals(HttpMethod.GET, SimpleHttpRequestBuilder.forGet("/path").build().method()); assertEquals(HttpMethod.POST, SimpleHttpRequestBuilder.forPost("/path").build().method()); assertEquals(HttpMethod.PUT, SimpleHttpRequestBuilder.forPut("/path").build().method()); assertEquals(HttpMethod.PATCH, SimpleHttpRequestBuilder.forPatch("/path").build().method()); assertEquals(HttpMethod.DELETE, SimpleHttpRequestBuilder.forDelete("/path").build().method()); assertEquals(HttpMethod.HEAD, SimpleHttpRequestBuilder.forHead("/path").build().method()); assertEquals(HttpMethod.OPTIONS, SimpleHttpRequestBuilder.forOptions("/path").build().method()); }
From source file:com.litgh.RouterTest.java
License:Open Source License
public void testRouterAPI() { Router router = new Router(); final Map<String, Boolean> test = new HashMap<String, Boolean>(); router.GET("/GET", new Handler() { public void handle(HttpRequest req, FullHttpResponse resp, List<Param> params) { test.put("GET", true); }/*from w w w . jav a 2s .c o m*/ }); router.POST("/POST", new Handler() { public void handle(HttpRequest req, FullHttpResponse resp, List<Param> params) { test.put("POST", true); } }); router.PUT("/PUT", new Handler() { public void handle(HttpRequest req, FullHttpResponse resp, List<Param> params) { test.put("PUT", true); } }); router.DELETE("/DELETE", new Handler() { public void handle(HttpRequest req, FullHttpResponse resp, List<Param> params) { test.put("DELETE", true); } }); router.HEAD("/HEAD", new Handler() { public void handle(HttpRequest req, FullHttpResponse resp, List<Param> params) { test.put("HEAD", true); } }); router.PATCH("/PATCH", new Handler() { public void handle(HttpRequest req, FullHttpResponse resp, List<Param> params) { test.put("PATCH", true); } }); HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/GET"); FullHttpResponse resp = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); router.serverHttp(req, resp); req.setMethod(HttpMethod.POST); req.setUri("/POST"); router.serverHttp(req, resp); req.setMethod(HttpMethod.PUT); req.setUri("/PUT"); router.serverHttp(req, resp); req.setMethod(HttpMethod.DELETE); req.setUri("/DELETE"); router.serverHttp(req, resp); req.setMethod(HttpMethod.HEAD); req.setUri("/HEAD"); router.serverHttp(req, resp); req.setMethod(HttpMethod.PATCH); req.setUri("/PATCH"); router.serverHttp(req, resp); assertEquals("routing GET failed", Boolean.TRUE, test.get("GET")); assertEquals("routing POST failed", Boolean.TRUE, test.get("POST")); assertEquals("routing PUT failed", Boolean.TRUE, test.get("PUT")); assertEquals("routing DELETE failed", Boolean.TRUE, test.get("DELETE")); assertEquals("routing HEAD failed", Boolean.TRUE, test.get("HEAD")); assertEquals("routing PATCH failed", Boolean.TRUE, test.get("PATCH")); }
From source file:com.netflix.iep.http.RxHttpTest.java
License:Apache License
@Test public void head() throws Exception { int code = 200; statusCode.set(code);/*from w ww. ja va 2 s .c o m*/ AtomicIntegerArray expected = copy(statusCounts); expected.addAndGet(code, 1); rxHttp.submit(HttpClientRequest.<ByteBuf>create(HttpMethod.HEAD, uri("/empty").toString())).toBlocking() .toFuture().get(); assertEquals(expected, statusCounts); }
From source file:com.rackspacecloud.blueflood.http.RouteMatcher.java
License:Apache License
public void route(ChannelHandlerContext context, FullHttpRequest request) { final String method = request.getMethod().name(); final String URI = request.getUri(); // Method not implemented for any resource. So return 501. if (method == null || !implementedVerbs.contains(method)) { route(context, request, unsupportedVerbsHandler); return;//from w w w. j a v a2 s . c om } final Pattern pattern = getMatchingPatternForURL(URI); // No methods registered for this pattern i.e. URL isn't registered. Return 404. if (pattern == null) { route(context, request, noRouteHandler); return; } final Set<String> supportedMethods = getSupportedMethods(pattern); if (supportedMethods == null) { log.warn("No supported methods registered for a known pattern " + pattern); route(context, request, noRouteHandler); return; } // The method requested is not available for the resource. Return 405. if (!supportedMethods.contains(method)) { route(context, request, unsupportedMethodHandler); return; } PatternRouteBinding binding = null; if (method.equals(HttpMethod.GET.name())) { binding = getBindings.get(pattern); } else if (method.equals(HttpMethod.PUT.name())) { binding = putBindings.get(pattern); } else if (method.equals(HttpMethod.POST.name())) { binding = postBindings.get(pattern); } else if (method.equals(HttpMethod.DELETE.name())) { binding = deleteBindings.get(pattern); } else if (method.equals(HttpMethod.PATCH.name())) { binding = deleteBindings.get(pattern); } else if (method.equals(HttpMethod.OPTIONS.name())) { binding = optionsBindings.get(pattern); } else if (method.equals(HttpMethod.HEAD.name())) { binding = headBindings.get(pattern); } else if (method.equals(HttpMethod.TRACE.name())) { binding = traceBindings.get(pattern); } else if (method.equals(HttpMethod.CONNECT.name())) { binding = connectBindings.get(pattern); } if (binding != null) { request = updateRequestHeaders(request, binding); route(context, request, binding.handler); } else { throw new RuntimeException("Cannot find a valid binding for URL " + URI); } }
From source file:com.rackspacecloud.blueflood.http.RouteMatcher.java
License:Apache License
public void head(String pattern, HttpRequestHandler handler) { addBinding(pattern, HttpMethod.HEAD.name(), handler, headBindings); }
From source file:com.strategicgains.restexpress.plugin.cache.CacheHeaderPostprocessor.java
License:Apache License
@Override public void process(Request request, Response response) { if (!request.isMethodGet() && !HttpMethod.HEAD.equals(request.getHttpMethod())) return;/*from ww w. jav a 2 s . c om*/ Object maxAge = request.getParameter(Parameters.Cache.MAX_AGE); if (maxAge != null) { response.addHeader(CACHE_CONTROL, String.format("max-age=%s", maxAge)); response.addHeader(EXPIRES, fmt.format(computeExpiresDate((Integer) maxAge))); } else { if (request.isFlagged(Flags.Cache.DONT_CACHE)) { response.addHeader(CACHE_CONTROL, NO_CACHE); response.addHeader(PRAGMA, NO_CACHE); } } }
From source file:com.strategicgains.restexpress.plugin.cache.DateHeaderPostprocessor.java
License:Apache License
@Override public void process(Request request, Response response) { if ((request.isMethodGet() || HttpMethod.HEAD.equals(request.getHttpMethod())) && !response.hasHeader(DATE)) { Date date = new Date(System.currentTimeMillis()); response.addHeader(DATE, fmt.format(date)); }//from w ww . j a v a 2s .co m }