@Override public ClientResponse<StatusResponseHolder> handleResponse(HttpResponse response, TrafficCop trafficCop) { return ClientResponse.unfinished( new StatusResponseHolder( response.getStatus(), null ) ); }
@Override public ClientResponse<FullResponseHolder> handleResponse(HttpResponse response, TrafficCop trafficCop) { return ClientResponse.unfinished( new FullResponseHolder( response.getStatus(), response, new StringBuilder(response.getContent().toString(charset)) ) ); }
@Override public ClientResponse<AppendableByteArrayInputStream> handleResponse(HttpResponse response, TrafficCop trafficCop) { status = response.getStatus().getCode(); description = response.getStatus().getReasonPhrase(); return ClientResponse.unfinished(super.handleResponse(response, trafficCop).getObj()); }
@Override public ClientResponse<StatusResponseHolder> handleResponse(HttpResponse response, TrafficCop trafficCop) { return ClientResponse.unfinished( new StatusResponseHolder( response.getStatus(), new StringBuilder(response.getContent().toString(charset)) ) ); }
@Override public ClientResponse<RetryResponseHolder<Intermediate>> handleResponse(HttpResponse httpResponse) { LOG.debug("UnauthorizedResponseHandler - Got response status {}", httpResponse.getStatus()); if (httpResponse.getStatus().equals(HttpResponseStatus.UNAUTHORIZED)) { // Drain the buffer //noinspection ResultOfMethodCallIgnored httpResponse.getContent().toString(); return ClientResponse.unfinished(RetryResponseHolder.retry()); } else { return wrap(httpResponseHandler.handleResponse(httpResponse)); } }
@Override public ClientResponse<RetryResponseHolder<Intermediate>> handleResponse( HttpResponse httpResponse, TrafficCop trafficCop ) { log.debug("UnauthorizedResponseHandler - Got response status [%s]", httpResponse.getStatus()); if (httpResponse.getStatus().equals(HttpResponseStatus.UNAUTHORIZED)) { // Drain the buffer httpResponse.getContent().toString(); return ClientResponse.unfinished(RetryResponseHolder.retry()); } else { return wrap(httpResponseHandler.handleResponse(httpResponse, trafficCop)); } }
private static void sendHttpResponse(ChannelHandlerContext ctx, HttpRequest req, HttpResponse res) { ChannelFuture f = ctx.getChannel().write(res); if (!isKeepAlive(req) || res.getStatus().getCode() != 200) { f.addListener(ChannelFutureListener.CLOSE); } }
@Override protected void encodeInitialLine(ChannelBuffer buf, HttpMessage message) throws Exception { HttpResponse response = (HttpResponse) message; buf.writeBytes(response.getProtocolVersion().toString().getBytes("ASCII")); buf.writeByte((byte) ' '); buf.writeBytes(String.valueOf(response.getStatus().getCode()).getBytes("ASCII")); buf.writeByte((byte) ' '); buf.writeBytes(String.valueOf(response.getStatus().getReasonPhrase()).getBytes("ASCII")); buf.writeByte((byte) '\r'); buf.writeByte((byte) '\n'); } }
@Override public ClientResponse<FullResponseHolder> handleResponse(HttpResponse response, TrafficCop trafficCop) { BytesFullResponseHolder holder = new BytesFullResponseHolder( response.getStatus(), response, null ); holder.addChunk(getContentBytes(response.getContent())); return ClientResponse.unfinished( holder ); }
private void resetState() { if (!isDecodingRequest()) { HttpResponse res = (HttpResponse) message; if (res != null && res.getStatus().getCode() == 101) { checkpoint(State.UPGRADED); return; } } checkpoint(State.SKIP_CONTROL_CHARS); }
@Override protected void encodeInitialLine(ChannelBuffer buf, HttpMessage message) throws Exception { HttpResponse response = (HttpResponse) message; encodeAscii(response.getProtocolVersion().toString(), buf); buf.writeByte(SP); encodeAscii(String.valueOf(response.getStatus().getCode()), buf); buf.writeByte(SP); encodeAscii(String.valueOf(response.getStatus().getReasonPhrase()), buf); buf.writeByte(CR); buf.writeByte(LF); } }
protected boolean isContentAlwaysEmpty(HttpMessage msg) { if (msg instanceof HttpResponse) { HttpResponse res = (HttpResponse) msg; int code = res.getStatus().getCode(); // Correctly handle return codes of 1xx. // // See: // - http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html Section 4.4 // - https://github.com/netty/netty/issues/222 if (code >= 100 && code < 200) { if (code == 101 && !res.headers().contains(HttpHeaders.Names.SEC_WEBSOCKET_ACCEPT)) { // It's Hixie 76 websocket handshake response return false; } return true; } switch (code) { case 204: case 205: case 304: return true; } } return false; }
@Override protected boolean isContentAlwaysEmpty(HttpMessage msg) { final int statusCode = ((HttpResponse) msg).getStatus().getCode(); if (statusCode == 100) {
if (HttpResponseStatus.TEMPORARY_REDIRECT.equals(fullResponseHolder.getResponse().getStatus())) { String redirectUrlStr = fullResponseHolder.getResponse().headers().get("Location"); if (redirectUrlStr == null) {
@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)); } } }
HttpResponse httpResponse = (HttpResponse) msg; if (log.isDebugEnabled()) { log.debug("[%s] Got response: %s", requestDesc, httpResponse.getStatus());
/** * Returns the content length of the specified web socket message. If the * specified message is not a web socket message, {@code -1} is returned. */ private static int getWebSocketContentLength(HttpMessage message) { // WebSockset messages have constant content-lengths. HttpHeaders h = message.headers(); if (message instanceof HttpRequest) { HttpRequest req = (HttpRequest) message; if (HttpMethod.GET.equals(req.getMethod()) && h.contains(Names.SEC_WEBSOCKET_KEY1) && h.contains(Names.SEC_WEBSOCKET_KEY2)) { return 8; } } else if (message instanceof HttpResponse) { HttpResponse res = (HttpResponse) message; if (res.getStatus().getCode() == 101 && h.contains(Names.SEC_WEBSOCKET_ORIGIN) && h.contains(Names.SEC_WEBSOCKET_LOCATION)) { return 16; } } // Not a web socket message return -1; }
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; }