List of usage examples for io.netty.handler.codec.http HttpResponseStatus CONTINUE
HttpResponseStatus CONTINUE
To view the source code for io.netty.handler.codec.http HttpResponseStatus CONTINUE.
Click Source Link
From source file:com.aerofs.baseline.http.EntityInputStream.java
License:Apache License
private void sendContinueIfRequested() { // we only have to send a continue // the *first* time the request processor // decides to read the data if (firstRead) { firstRead = false;//from w w w.j ava2 s . com if (continueRequested) { ctx.channel() .writeAndFlush(new DefaultHttpResponse(httpVersion, HttpResponseStatus.CONTINUE, false)); } } }
From source file:com.example.http.hello.HttpHelloServerHandler.java
License:Apache License
@Override public void channelRead(final ChannelHandlerContext ctx, final Object msg) { log.info("request coming[{}, hash: {}]: {}", current, hasher.hashCode(), msg); current = counter.incrementAndGet(); if (msg instanceof HttpRequest) { final HttpRequest request = (HttpRequest) msg; if (HttpUtil.is100ContinueExpected(request)) { ctx.write(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE)); }/*from w ww . j a v a 2s.c o m*/ final DefaultFullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.wrappedBuffer(CONTENT)); response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain"); response.headers().set(HttpHeaderNames.CONTENT_LENGTH, response.content().readableBytes()); final boolean keepAlive = HttpUtil.isKeepAlive(request); if (keepAlive) { ctx.write(response).addListener(ChannelFutureListener.CLOSE); } else { response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE); ctx.write(response); } } }
From source file:com.github.thinker0.mesos.MesosHealthCheckerServer.java
License:Apache License
/** * Writes a 100 Continue response.// w ww . j a va 2s . c o m * * @param ctx The HTTP handler context. */ private static void send100Continue(final ChannelHandlerContext ctx) { ctx.write(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE)); }
From source file:com.stremebase.examples.todomvc.HttpRouter.java
License:Apache License
@Override public void channelRead0(ChannelHandlerContext ctx, HttpRequest req) { if (HttpHeaders.is100ContinueExpected(req)) { ctx.writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE)); return;/*from w w w.ja va2 s. com*/ } HttpResponse res = createResponse(req, router); flushResponse(ctx, req, res); }
From source file:gribbit.http.request.decoder.HttpRequestDecoder.java
License:Open Source License
/** Decode an HTTP message. */ @Override//from w w w . j a v a 2 s.com public void messageReceived(ChannelHandlerContext ctx, Object msg) { try { Log.info("Got message of type " + msg.getClass().getName()); if (msg instanceof HttpRequest) { // Got a new HTTP request -- decode HTTP headers HttpRequest httpReq = (HttpRequest) msg; if (!httpReq.decoderResult().isSuccess()) { throw new BadRequestException(null); } // Free resources to avoid DoS attack by sending repeated unterminated requests freeResources(); // Parse the HttpRequest fields. request = new Request(ctx, httpReq); // Handle expect-100-continue List<CharSequence> allExpectHeaders = httpReq.headers().getAll(EXPECT); for (int i = 0; i < allExpectHeaders.size(); i++) { String h = allExpectHeaders.get(i).toString(); if (h.equalsIgnoreCase("100-continue")) { ctx.writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE, Unpooled.EMPTY_BUFFER)); return; } } if (httpReq.method() == HttpMethod.POST) { // Start decoding HttpContent chunks. freeResources(); postRequestDecoder = new HttpPostRequestDecoder(httpDataFactory, httpReq); } } if (msg instanceof LastHttpContent || msg instanceof FullHttpRequest) { // Reached end of HTTP request if (request != null) { // Check for WebSocket upgrade request if (!tryWebSocketHandlers(ctx, request.getHttpRequest())) { // This is a regular HTTP request -- find a handler for the request tryHttpRequestHandlers(ctx); } // After the last content message has been processed, free resources freeResources(); } } else if (msg instanceof HttpContent) { // Decode HTTP POST body HttpContent chunk = (HttpContent) msg; if (!chunk.decoderResult().isSuccess()) { throw new BadRequestException(null); } handlePOSTChunk(chunk); } else if (msg instanceof WebSocketFrame) { // Handle WebSocket frame if (webSocketHandler == null) { // Connection was never upgraded to websocket throw new BadRequestException(); } WebSocketFrame frame = (WebSocketFrame) msg; handleWebSocketFrame(ctx, frame); } } catch (Exception e) { exceptionCaught(ctx, e); } }
From source file:io.crate.protocols.http.HttpBlobHandler.java
License:Apache License
private void writeToFile(ByteBuf input, boolean last, final boolean continueExpected) throws IOException { if (digestBlob == null) { throw new IllegalStateException("digestBlob is null in writeToFile"); }/*from ww w .j a v a 2 s. c o m*/ RemoteDigestBlob.Status status = digestBlob.addContent(input, last); HttpResponseStatus exitStatus = null; switch (status) { case FULL: exitStatus = HttpResponseStatus.CREATED; break; case PARTIAL: // tell the client to continue if (continueExpected) { ctx.write(new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.CONTINUE)); } return; case MISMATCH: exitStatus = HttpResponseStatus.BAD_REQUEST; break; case EXISTS: exitStatus = HttpResponseStatus.CONFLICT; break; case FAILED: exitStatus = HttpResponseStatus.INTERNAL_SERVER_ERROR; break; default: throw new IllegalArgumentException("Unknown status: " + status); } assert exitStatus != null : "exitStatus should not be null"; LOGGER.trace("writeToFile exit status http:{} blob: {}", exitStatus, status); simpleResponse(exitStatus); }
From source file:io.nebo.container.ServletContentHandler.java
License:Apache License
@Override protected void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception { if (msg instanceof HttpRequest) { HttpRequest request = (HttpRequest) msg; log.info("uri" + request.getUri()); HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, false); NettyHttpServletResponse servletResponse = new NettyHttpServletResponse(ctx, servletContext, response); servletRequest = new NettyHttpServletRequest(ctx, servletContext, request, inputStream, servletResponse);//from ww w. j a va2s .c om if (HttpMethod.GET.equals(request.getMethod())) { HttpHeaders.setKeepAlive(response, HttpHeaders.isKeepAlive(request)); if (HttpHeaders.is100ContinueExpected(request)) { ctx.write(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE), ctx.voidPromise()); } ctx.fireChannelRead(servletRequest); } else if (HttpMethod.POST.equals(request.getMethod())) { decoder = new HttpPostRequestDecoder(factory, request); } } if (decoder != null && msg instanceof HttpContent) { HttpContent chunk = (HttpContent) msg; log.info("HttpContent" + chunk.content().readableBytes()); inputStream.addContent(chunk); List<InterfaceHttpData> interfaceHttpDatas = decoder.getBodyHttpDatas(); for (InterfaceHttpData data : interfaceHttpDatas) { try { if (data.getHttpDataType() == InterfaceHttpData.HttpDataType.Attribute) { Attribute attribute = (Attribute) data; Map<String, String[]> params = servletRequest.getParameterMap(); HttpRequestUtils.setParamMap(attribute.getName(), attribute.getValue(), params); } } finally { // data.release(); } } } if (decoder != null && msg instanceof LastHttpContent) { ctx.fireChannelRead(servletRequest); reset(); } }
From source file:io.termd.core.http.netty.HttpRequestHandler.java
License:Apache License
private static void send100Continue(ChannelHandlerContext ctx) { FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE); ctx.writeAndFlush(response);//www . j av a 2 s . c o m }
From source file:io.urmia.proxy.HttpProxyBackendHandler.java
License:Open Source License
@Override public void channelRead0(final ChannelHandlerContext ctx, HttpObject msg) throws Exception { //log.info("backend read. direct write back: {}. writing to inbound: {}", directWriteBack, msg); if (msg instanceof HttpResponse) { httpResponse = (HttpResponse) msg; log.info("backend http response: {}, status code: {}", httpResponse, httpResponse.getStatus().code()); ctx.channel().read();/*from w w w . j av a 2 s. com*/ return; } if (httpResponse == null) { log.error("httpResponse is null when received: {}", msg); inboundCtx.pipeline().fireUserEventTriggered(new ProxyUserEvent(OUTBOUND_ERROR, index)); return; } if (!(msg instanceof LastHttpContent)) { log.error("input message is not supported: {}", msg); inboundCtx.pipeline().fireUserEventTriggered(new ProxyUserEvent(OUTBOUND_ERROR, index)); return; } if (httpResponse.getStatus().equals(HttpResponseStatus.CONTINUE)) { log.info("continue from client."); ProxyUserEvent pevt = new ProxyUserEvent(OUTBOUND_CONTINUE, index); log.info("fire user event: {}", pevt); inboundCtx.pipeline().fireUserEventTriggered(pevt); ctx.read(); return; } ProxyUserEvent pevt = new ProxyUserEvent(OUTBOUND_COMPLETED, index); log.info("fire user event: {}", pevt); inboundCtx.pipeline().fireUserEventTriggered(pevt); ctx.read(); }
From source file:io.urmia.proxy.HttpProxyFrontendHandler.java
License:Open Source License
private void onContinue(final ChannelHandlerContext ctx, int index) { log.info("onContinue: {}", index); continueSet.set(index);// w w w . j a v a 2 s. c o m if (continueSet.cardinality() != outboundCount) return; log.info("all onContinue"); ctx.writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE)); }