possiblySuspendReads(response); if (!httpResponse.isChunked()) { finishRequest();
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { if (!readingChunks) { HttpResponse res = (HttpResponse) e.getMessage(); if (res.getStatus().getCode() != HttpResponseStatus.OK.getCode()) { throw new ChannelException("Unexpected HTTP response status: " + res.getStatus()); } if (res.isChunked()) { readingChunks = true; } else { ChannelBuffer content = res.getContent(); if (content.readable()) { fireMessageReceived(HttpTunnelingClientSocketChannel.this, content); } // Reached to the end of response - close the request. closeReal(succeededFuture(virtualChannel)); } } else { HttpChunk chunk = (HttpChunk) e.getMessage(); if (!chunk.isLast()) { fireMessageReceived(HttpTunnelingClientSocketChannel.this, chunk.getContent()); } else { readingChunks = false; // Reached to the end of response - close the request. closeReal(succeededFuture(virtualChannel)); } } }
private SpdySynReplyFrame createSynReplyFrame(HttpResponse httpResponse) throws Exception { boolean chunked = httpResponse.isChunked(); // Get the Stream-ID from the headers int streamId = SpdyHttpHeaders.getStreamId(httpResponse); SpdyHttpHeaders.removeStreamId(httpResponse); // The Connection, Keep-Alive, Proxy-Connection, and Transfer-Encoding // headers are not valid and MUST not be sent. httpResponse.headers().remove(HttpHeaders.Names.CONNECTION); httpResponse.headers().remove("Keep-Alive"); httpResponse.headers().remove("Proxy-Connection"); httpResponse.headers().remove(HttpHeaders.Names.TRANSFER_ENCODING); SpdySynReplyFrame spdySynReplyFrame = new DefaultSpdySynReplyFrame(streamId); spdySynReplyFrame.setLast(!chunked && !httpResponse.getContent().readable()); // Unfold the first line of the response into name/value pairs SpdyHeaders.setStatus(spdyVersion, spdySynReplyFrame, httpResponse.getStatus()); SpdyHeaders.setVersion(spdyVersion, spdySynReplyFrame, httpResponse.getProtocolVersion()); // Transfer the remaining HTTP headers for (Map.Entry<String, String> entry: httpResponse.headers()) { spdySynReplyFrame.headers().add(entry.getKey(), entry.getValue()); } return spdySynReplyFrame; }
private NettyHttpResponse content(ChannelBuffer content) { if (response.isChunked()) { throw new UnsupportedOperationException(); } responseBuffer.writeBytes(content); return this; }
@Override public NettyHttpResponse write(String content) { if (response.isChunked()) { ctx.getChannel().write(new DefaultHttpChunk(wrappedBuffer(content.getBytes(CharsetUtil.UTF_8)))); } else { write(copiedBuffer(content, CharsetUtil.UTF_8)); } return this; }
private void flushResponse() { try { // TODO: Shouldn't have to do this, but without it we sometimes seem to get two Content-Length headers in the response. header("Content-Length", (String) null); header("Content-Length", responseBuffer.readableBytes()); ChannelFuture future = response.isChunked() ? ctx.getChannel().write(new DefaultHttpChunk(ChannelBuffers.EMPTY_BUFFER)) : write(responseBuffer); if (!isKeepAlive) { future.addListener(ChannelFutureListener.CLOSE); } } catch (Exception e) { exceptionHandler.uncaughtException(Thread.currentThread(), WebbitException.fromException(e, ctx.getChannel())); } }
private boolean exitAfterHandlingBody(Channel channel, NettyResponseFuture<?> future, HttpResponse response, AsyncHandler<?> handler) throws Exception { if (!response.isChunked()) { // no chunks expected, exiting if (response.getContent().readableBytes() > 0) // FIXME no need to notify an empty bodypart? updateBodyAndInterrupt(future, handler, new NettyResponseBodyPart(response, null, true)); finishUpdate(future, channel, false); return true; } return false; }
if (future.isKeepAlive() && !HttpHeaders.isTransferEncodingChunked(response) && !response.isChunked()) { future.setConnectAllowed(true); future.setReuseChannel(true);
if (future.isKeepAlive() && !HttpHeaders.isTransferEncodingChunked(response) && !response.isChunked()) { future.setReuseChannel(true); } else {
private NettyHttpResponse content(ChannelBuffer content) { if (response.isChunked()) { throw new UnsupportedOperationException(); } responseBuffer.writeBytes(content); return this; }
if (future.isKeepAlive() && !HttpHeaders.isTransferEncodingChunked(response) && !response.isChunked()) {
@Override public NettyHttpResponse write(String content) { if (response.isChunked()) { ctx.getChannel().write(new DefaultHttpChunk(wrappedBuffer(content.getBytes(CharsetUtil.UTF_8)))); } else { write(copiedBuffer(content, CharsetUtil.UTF_8)); } return this; }
private void flushResponse() { try { // TODO: Shouldn't have to do this, but without it we sometimes seem to get two Content-Length headers in the response. header("Content-Length", (String) null); header("Content-Length", responseBuffer.readableBytes()); ChannelFuture future = response.isChunked() ? ctx.getChannel().write(new DefaultHttpChunk(ChannelBuffers.EMPTY_BUFFER)) : write(responseBuffer); if (!isKeepAlive) { future.addListener(ChannelFutureListener.CLOSE); } } catch (Exception e) { exceptionHandler.uncaughtException(Thread.currentThread(), WebbitException.fromException(e, ctx.getChannel())); } }
private boolean exitAfterHandlingBody(Channel channel, NettyResponseFuture<?> future, HttpResponse response, AsyncHandler<?> handler) throws Exception { if (!response.isChunked()) { // no chunks expected, exiting if (response.getContent().readableBytes() > 0) // FIXME no need to notify an empty bodypart? updateBodyAndInterrupt(future, handler, new NettyResponseBodyPart(response, null, true)); finishUpdate(future, channel, false); return true; } return false; }
private boolean exitAfterHandlingBody(Channel channel, NettyResponseFuture<?> future, HttpResponse response, AsyncHandler<?> handler) throws Exception { if (!response.isChunked()) { // no chunks expected, exiting if (response.getContent().readableBytes() > 0) // FIXME no need to notify an empty bodypart? updateBodyAndInterrupt(future, handler, new NettyResponseBodyPart(response, null, true)); finishUpdate(future, channel, false); return true; } return false; }
private boolean exitAfterHandlingBody(Channel channel, NettyResponseFuture<?> future, HttpResponse response, AsyncHandler<?> handler) throws Exception { if (!response.isChunked()) { // no chunks expected, exiting if (response.getContent().readableBytes() > 0) { // no need to notify an empty bodypart updateBodyAndInterrupt(future, handler, new NettyResponseBodyPart(response, null, true)); } finishUpdate(future, channel, false); return true; } return false; }
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { if (!this.readingChunks) { HttpResponse response = (HttpResponse) e.getMessage(); LOGGER.info("STATUS: " + response.getStatus()); if ((response.getStatus().getCode() == 200) && (response.isChunked())) { this.readingChunks = true; } else { ChannelBuffer content = response.getContent(); if (content.readable()) this.responseContent.append(content .toString(CharsetUtil.UTF_8)); } } else { HttpChunk chunk = (HttpChunk) e.getMessage(); if (chunk.isLast()) { this.readingChunks = false; this.responseContent.append(chunk.getContent().toString( CharsetUtil.UTF_8)); String json = this.responseContent.toString(); this.result = ((Result) JSONUtil.parseObject(json,Result.class)); } else { this.responseContent.append(chunk.getContent().toString( CharsetUtil.UTF_8)); } } }
conn.handleResponseChunk(new Buffer(content)); if (!response.isChunked() && (response.getStatus().getCode() != 100)) { conn.handleResponseEnd();
private void logResponse(HttpResponse response) { finerLog("STATUS: " + response.getStatus()); finerLog("VERSION: " + response.getProtocolVersion()); if (!response.getHeaderNames().isEmpty()) { for (String name : response.getHeaderNames()) { for (String value : response.getHeaders(name)) { finerLog("HEADER: " + name + " = " + value); } } finerLog(System.getProperty("line.separator")); } if (response.getStatus().getCode() == 200 && response.isChunked()) { readingChunks = true; finerLog("CHUNKED CONTENT {"); } else if(response.getStatus().getCode() == 200) { ChannelBuffer content = response.getContent(); if (content.readable()) { finerLog("CONTENT {"); finerLog(content.toString(CharsetUtil.UTF_8)); finerLog("} END OF CONTENT"); } } else { throw new ConnectionException("Could not retrieve configuration chunk. " + "Response Code is: " + response.getStatus()); } }