List of usage examples for io.netty.handler.codec.http DefaultHttpResponse DefaultHttpResponse
public DefaultHttpResponse(HttpVersion version, HttpResponseStatus status, HttpHeaders headers)
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 .ja va 2 s . c om if (continueRequested) { ctx.channel() .writeAndFlush(new DefaultHttpResponse(httpVersion, HttpResponseStatus.CONTINUE, false)); } } }
From source file:com.linecorp.armeria.internal.http.Http1ObjectEncoder.java
License:Apache License
private HttpObject convertServerHeaders(int streamId, HttpHeaders headers, boolean endStream) throws Http2Exception { // Leading headers will always have :status, trailers will never have it. final HttpStatus status = headers.status(); if (status == null) { return convertTrailingHeaders(streamId, headers); }/*from w ww .j av a2 s . co m*/ // Convert leading headers. final HttpResponse res; final boolean informational = status.codeClass() == HttpStatusClass.INFORMATIONAL; if (endStream || informational) { res = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status.toNettyStatus(), Unpooled.EMPTY_BUFFER, false); final io.netty.handler.codec.http.HttpHeaders outHeaders = res.headers(); convert(streamId, headers, outHeaders, false); if (informational) { // 1xx responses does not have the 'content-length' header. outHeaders.remove(HttpHeaderNames.CONTENT_LENGTH); } else if (!headers.contains(HttpHeaderNames.CONTENT_LENGTH)) { // NB: Set the 'content-length' only when not set rather than always setting to 0. // It's because a response to a HEAD request can have empty content while having // non-zero 'content-length' header. // However, this also opens the possibility of sending a non-zero 'content-length' // header even when it really has to be zero. e.g. a response to a non-HEAD request outHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, 0); } } else { res = new DefaultHttpResponse(HttpVersion.HTTP_1_1, status.toNettyStatus(), false); // Perform conversion. convert(streamId, headers, res.headers(), false); setTransferEncoding(res); } return res; }
From source file:com.linecorp.armeria.internal.Http1ObjectEncoder.java
License:Apache License
private HttpObject convertServerHeaders(int streamId, HttpHeaders headers, boolean endStream) throws Http2Exception { // Leading headers will always have :status, trailers will never have it. final HttpStatus status = headers.status(); if (status == null) { return convertTrailingHeaders(streamId, headers); }//from w ww . jav a 2 s . co m // Convert leading headers. final HttpResponse res; final boolean informational = status.codeClass() == HttpStatusClass.INFORMATIONAL; final HttpResponseStatus nettyStatus = HttpResponseStatus.valueOf(status.code()); if (endStream || informational) { res = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, nettyStatus, Unpooled.EMPTY_BUFFER, false); final io.netty.handler.codec.http.HttpHeaders outHeaders = res.headers(); convert(streamId, headers, outHeaders, false); if (informational) { // 1xx responses does not have the 'content-length' header. outHeaders.remove(HttpHeaderNames.CONTENT_LENGTH); } else if (!headers.contains(HttpHeaderNames.CONTENT_LENGTH)) { // NB: Set the 'content-length' only when not set rather than always setting to 0. // It's because a response to a HEAD request can have empty content while having // non-zero 'content-length' header. // However, this also opens the possibility of sending a non-zero 'content-length' // header even when it really has to be zero. e.g. a response to a non-HEAD request outHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, 0); } } else { res = new DefaultHttpResponse(HttpVersion.HTTP_1_1, nettyStatus, false); // Perform conversion. convert(streamId, headers, res.headers(), false); setTransferEncoding(res); } return res; }
From source file:com.sengled.cloud.mediaserver.rtsp.codec.RtspResponseDecoder.java
License:Apache License
@Override protected HttpMessage createMessage(String[] initialLine) throws Exception { return new DefaultHttpResponse(RtspVersions.valueOf(initialLine[0]), new HttpResponseStatus(Integer.parseInt(initialLine[1]), initialLine[2]), validateHeaders); }
From source file:io.advantageous.conekt.http.impl.HttpServerResponseImpl.java
License:Open Source License
HttpServerResponseImpl(final ConektInternal vertx, ServerConnection conn, HttpRequest request) { this.vertx = vertx; this.conn = conn; this.version = request.getProtocolVersion(); this.response = new DefaultHttpResponse(version, HttpResponseStatus.OK, false); this.keepAlive = (version == HttpVersion.HTTP_1_1 && !request.headers() .contains(io.advantageous.conekt.http.HttpHeaders.CONNECTION, HttpHeaders.CLOSE, true)) || (version == HttpVersion.HTTP_1_0 && request.headers().contains(HttpHeaders.CONNECTION, HttpHeaders.KEEP_ALIVE, true)); }
From source file:io.cettia.asity.bridge.netty4.NettyServerHttpExchange.java
License:Apache License
public NettyServerHttpExchange(ChannelHandlerContext context, HttpRequest request) { this.context = context; this.request = request; this.response = new DefaultHttpResponse(request.getProtocolVersion(), HttpResponseStatus.OK, false); response.headers().set(HttpHeaders.Names.TRANSFER_ENCODING, HttpHeaders.Values.CHUNKED); }
From source file:io.jsync.http.impl.DefaultHttpServerResponse.java
License:Open Source License
DefaultHttpServerResponse(final AsyncInternal async, ServerConnection conn, HttpRequest request) { this.async = async; this.conn = conn; this.version = request.protocolVersion(); this.response = new DefaultHttpResponse(version, HttpResponseStatus.OK, false); this.keepAlive = version == HttpVersion.HTTP_1_1 || (version == HttpVersion.HTTP_1_0 && request.headers() .contains(io.jsync.http.HttpHeaders.CONNECTION, io.jsync.http.HttpHeaders.KEEP_ALIVE, true)); }
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 w w w . ja v a 2s .c o m 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.vertx.core.http.impl.HttpServerResponseImpl.java
License:Open Source License
HttpServerResponseImpl(final VertxInternal vertx, ServerConnection conn, HttpRequest request) { this.vertx = vertx; this.conn = conn; this.version = request.getProtocolVersion(); this.response = new DefaultHttpResponse(version, HttpResponseStatus.OK, false); this.keepAlive = (version == HttpVersion.HTTP_1_1 && !request.headers().contains(io.vertx.core.http.HttpHeaders.CONNECTION, HttpHeaders.CLOSE, true)) || (version == HttpVersion.HTTP_1_0 && request.headers() .contains(io.vertx.core.http.HttpHeaders.CONNECTION, HttpHeaders.KEEP_ALIVE, true)); }
From source file:org.glowroot.ui.HttpServerHandler.java
License:Apache License
private void sendResponse(ChannelHandlerContext ctx, FullHttpRequest request, CommonResponse response, boolean keepAlive) throws IOException { Object content = response.getContent(); if (content instanceof ByteBuf) { FullHttpResponse resp = new DefaultFullHttpResponse(HTTP_1_1, response.getStatus(), (ByteBuf) content, response.getHeaders(), EmptyHttpHeaders.INSTANCE); sendFullResponse(ctx, request, resp, keepAlive); } else if (content instanceof ChunkSource) { HttpResponse resp = new DefaultHttpResponse(HTTP_1_1, OK, response.getHeaders()); resp.headers().set(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED); ctx.write(resp);//from w w w. jav a 2 s .c om ChunkSource chunkSource = (ChunkSource) content; ChunkedInput<HttpContent> chunkedInput; String zipFileName = response.getZipFileName(); if (zipFileName == null) { chunkedInput = ChunkedInputs.create(chunkSource); } else { chunkedInput = ChunkedInputs.createZipFileDownload(chunkSource, zipFileName); } ChannelFuture future = ctx.write(chunkedInput); HttpServices.addErrorListener(future); if (!keepAlive) { HttpServices.addCloseListener(future); } } else { throw new IllegalStateException("Unexpected content: " + content.getClass().getName()); } }