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:org.restexpress.RestExpressTest.java
License:Apache License
@Test public void shouldCallAltNamedMethods() throws ClientProtocolException, IOException { int port = nextPort(); String testUrl = createUrl(TEST_URL_PATTERN, port); RestExpress re = new RestExpress(); AltController controller = new AltController(); re.uri(TEST_PATH, controller).action("altHead", HttpMethod.HEAD).action("altOptions", HttpMethod.OPTIONS) .action("altPatch", HttpMethod.PATCH); re.bind(port);/*from www .j a v a 2 s. c o m*/ waitForStartup(); HttpGet get = new HttpGet(testUrl); try { HttpResponse response = (HttpResponse) CLIENT.execute(get); assertEquals(405, response.getStatusLine().getStatusCode()); } finally { get.releaseConnection(); } HttpOptions options = new HttpOptions(testUrl); try { HttpResponse response = (HttpResponse) CLIENT.execute(options); assertEquals(200, response.getStatusLine().getStatusCode()); assertEquals(1, controller.options); assertEquals(0, controller.head); assertEquals(0, controller.patch); } finally { options.releaseConnection(); } HttpHead head = new HttpHead(testUrl); try { HttpResponse response = (HttpResponse) CLIENT.execute(head); assertEquals(200, response.getStatusLine().getStatusCode()); assertEquals(1, controller.options); assertEquals(1, controller.head); assertEquals(0, controller.patch); } finally { head.releaseConnection(); } HttpPatch patch = new HttpPatch(testUrl); try { HttpResponse response = (HttpResponse) CLIENT.execute(patch); assertEquals(200, response.getStatusLine().getStatusCode()); assertEquals(1, controller.options); assertEquals(1, controller.head); assertEquals(1, controller.patch); } finally { patch.releaseConnection(); } re.shutdown(true); }
From source file:org.restexpress.route.RouteMapping.java
License:Apache License
public RouteMapping() { super();//from w ww . jav a 2 s .c o m routes = new HashMap<HttpMethod, List<Route>>(); routes.put(HttpMethod.DELETE, deleteRoutes); routes.put(HttpMethod.GET, getRoutes); routes.put(HttpMethod.POST, postRoutes); routes.put(HttpMethod.PUT, putRoutes); routes.put(HttpMethod.HEAD, headRoutes); routes.put(HttpMethod.OPTIONS, optionRoutes); }
From source file:org.restnext.core.http.RequestImpl.java
License:Apache License
private boolean isGetOrHead() { HttpMethod httpMethod = HttpMethod.valueOf(getMethod().toString()); return HttpMethod.GET.equals(httpMethod) || HttpMethod.HEAD.equals(httpMethod); }
From source file:org.robotbrains.support.web.server.netty.NettyStaticContentHandler.java
License:Apache License
@Override public boolean isHandledBy(HttpRequest request) { if (request.getUri().startsWith(uriPrefix)) { HttpMethod method = request.getMethod(); return method == HttpMethod.GET || method == HttpMethod.HEAD; } else {//from w ww . j av a 2 s . c om return false; } }
From source file:org.thingsplode.synapse.endpoint.handlers.HttpRequestHandler.java
License:Apache License
@Override protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest httpRequest) throws Exception { //todo: support for API keys ///endpoints/json?api_key=565656 try {//from w ww .j a v a2 s . c o m // Handle a bad request. if (!httpRequest.decoderResult().isSuccess()) { HttpResponseHandler.sendError(ctx, HttpResponseStatus.BAD_REQUEST, "Could not decode request.", httpRequest); return; } if (httpRequest.method().equals(HttpMethod.HEAD) || httpRequest.method().equals(HttpMethod.PATCH) || httpRequest.method().equals(HttpMethod.TRACE) || httpRequest.method().equals(HttpMethod.CONNECT) || httpRequest.method().equals(HttpMethod.OPTIONS)) { HttpResponseHandler.sendError(ctx, HttpResponseStatus.FORBIDDEN, "Method forbidden (The following are not supported: HEAD, PATCH, TRACE, CONNECT, OPTIONS).", httpRequest); return; } //check websocket upgrade request String upgradeHeader = httpRequest.headers().get(HttpHeaderNames.UPGRADE); if (!Util.isEmpty(upgradeHeader) && UPGRADE_TO_WEBSOCKET.equalsIgnoreCase(upgradeHeader)) { //case websocket upgrade request is detected -> Prepare websocket handshake upgradeToWebsocket(ctx, httpRequest); return; } else { //case simple http request Request request = new Request(prepareHeader(ctx, httpRequest)); //no information about the object type / it will be processed in a later stage //todo: with requestbodytype header value early deserialization would be possible, however not beneficial in routing cases request.setBody(httpRequest.content()); ctx.fireChannelRead(request); } } catch (Exception ex) { logger.error("Channel read error: " + ex.getMessage(), ex); HttpResponseHandler.sendError(ctx, HttpResponseStatus.INTERNAL_SERVER_ERROR, ex.getClass().getSimpleName() + ": " + ex.getMessage(), httpRequest); } }
From source file:org.waarp.gateway.kernel.rest.HttpRestHandler.java
License:Open Source License
/** * Create the decoder//from w w w .ja va 2 s . c o m * * @throws HttpIncorrectRequestException */ protected void createDecoder() throws HttpIncorrectRequestException { HttpMethod method = request.method(); if (!method.equals(HttpMethod.HEAD)) { // in order decoder allows to parse request.setMethod(HttpMethod.POST); } try { decoder = new HttpPostRequestDecoder(factory, request); } catch (ErrorDataDecoderException e1) { status = HttpResponseStatus.NOT_ACCEPTABLE; throw new HttpIncorrectRequestException(e1); } catch (Exception e1) { // GETDOWNLOAD Method: should not try to create a HttpPostRequestDecoder // So OK but stop here status = HttpResponseStatus.NOT_ACCEPTABLE; throw new HttpIncorrectRequestException(e1); } }
From source file:reactor.ipc.netty.http.client.HttpClientOperations.java
License:Open Source License
@Override public NettyOutbound send(Publisher<? extends ByteBuf> source) { if (method() == HttpMethod.GET || method() == HttpMethod.HEAD) { ByteBufAllocator alloc = channel().alloc(); Flux.from(source).doOnNext(ByteBuf::retain).collect(alloc::buffer, ByteBuf::writeBytes).then(agg -> { if (!hasSentHeaders() && !HttpUtil.isTransferEncodingChunked(outboundHttpMessage()) && !HttpUtil.isContentLengthSet(outboundHttpMessage())) { outboundHttpMessage().headers().setInt(HttpHeaderNames.CONTENT_LENGTH, agg.readableBytes()); }//from w w w .ja v a2 s . c om return sendHeaders().send(Mono.just(agg)).then(); }); } return super.send(source); }