/** * Returns the value of the {@code "X-SPDY-Scheme"} header. */ public static String getScheme(HttpMessage message) { return message.headers().get(Names.SCHEME); }
/** * Returns the length of the content. Please note that this value is * not retrieved from {@link HttpMessage#getContent()} but from the * {@code "Content-Length"} header, and thus they are independent from each * other. * * @return the content length or {@code defaultValue} if this message does * not have the {@code "Content-Length"} header or its value is not * a number */ public static long getContentLength(HttpMessage message, long defaultValue) { String contentLength = message.headers().get(Names.CONTENT_LENGTH); if (contentLength != null) { try { return Long.parseLong(contentLength); } catch (NumberFormatException e) { // Not a long integer header - use the default. return defaultValue; } } // We know the content length if it's a Web Socket message even if // Content-Length header is missing. long webSocketContentLength = getWebSocketContentLength(message); if (webSocketContentLength >= 0) { return webSocketContentLength; } // Otherwise we don't. return defaultValue; }
/** * Returns the value of the {@code "X-SPDY-URL"} header. */ public static String getUrl(HttpMessage message) { return message.headers().get(Names.URL); }
/** * Returns the header value with the specified header name. If there are * more than one header value for the specified header name, the first * value is returned. * * @return the header value or {@code null} if there is no such header */ public static String getHeader(HttpMessage message, String name) { return message.headers().get(name); }
/** * Returns the value of the {@code "Host"} header. */ public static String getHost(HttpMessage message) { return message.headers().get(Names.HOST); }
/** * Returns the header value with the specified header name. If there are * more than one header value for the specified header name, the first * value is returned. * * @return the header value or the {@code defaultValue} if there is no such * header */ public static String getHeader(HttpMessage message, String name, String defaultValue) { String value = message.headers().get(name); if (value == null) { return defaultValue; } return value; }
private static String getWebSocketLocation(ChannelPipeline cp, HttpRequest req, String path) { String protocol = "ws"; if (cp.get(SslHandler.class) != null) { // SSL in use so use Secure WebSockets protocol = "wss"; } return protocol + "://" + req.headers().get(HttpHeaders.Names.HOST) + path; }
/** * Returns {@code true} if and only if the connection can remain open and * thus 'kept alive'. This methods respects the value of the * {@code "Connection"} header first and then the return value of * {@link HttpVersion#isKeepAliveDefault()}. */ public static boolean isKeepAlive(HttpMessage message) { String connection = message.headers().get(Names.CONNECTION); boolean close = Values.CLOSE.equalsIgnoreCase(connection); if (close) { return false; } if (message.getProtocolVersion().isKeepAliveDefault()) { return !close; } else { return Values.KEEP_ALIVE.equalsIgnoreCase(connection); } }
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { Object msg = e.getMessage(); if (!(msg instanceof HttpMessage)) { ctx.sendUpstream(e); return; } HttpMessage m = (HttpMessage) msg; String acceptedEncoding = m.headers().get(HttpHeaders.Names.ACCEPT_ENCODING); if (acceptedEncoding == null) { acceptedEncoding = HttpHeaders.Values.IDENTITY; } boolean offered = acceptEncodingQueue.offer(acceptedEncoding); assert offered; ctx.sendUpstream(e); }
static FullResponseHolder getResponseFromCurrentLeader(HttpClient client, Request request, FullResponseHandler fullResponseHandler) throws ExecutionException, InterruptedException { FullResponseHolder responseHolder = client.go(request, fullResponseHandler).get(); if (HttpResponseStatus.TEMPORARY_REDIRECT.equals(responseHolder.getStatus())) { String redirectUrlStr = responseHolder.getResponse().headers().get("Location"); LOG.debug("Request[%s] received redirect response to location [%s].", request.getUrl(), redirectUrlStr); final URL redirectUrl; try { redirectUrl = new URL(redirectUrlStr); } catch (MalformedURLException ex) { throw new ExecutionException(String.format( "Malformed redirect location is found in response from url[%s], new location[%s].", request.getUrl(), redirectUrlStr), ex); } responseHolder = client.go(withUrl(request, redirectUrl), fullResponseHandler).get(); } return responseHolder; }
request.headers().get(SecureShuffleUtils.HTTP_HEADER_URL_HASH); if (urlHashStr == null) { LOG.info("Missing header hash for " + appid);
public static class TaskNotRunnableException extends RuntimeException { public TaskNotRunnableException(String message) { super(message); } }
/** * Check if the given request is a multipart request * * @return True if the request is a Multipart request */ public static boolean isMultipart(HttpRequest request) throws ErrorDataDecoderException { if (request.headers().contains(HttpHeaders.Names.CONTENT_TYPE)) { return getMultipartDataBoundary(request.headers().get(HttpHeaders.Names.CONTENT_TYPE)) != null; } else { return false; } }
/** * * @param factory the factory used to create InterfaceHttpData * @param request the request to decode * @param charset the charset to use as default * @throws NullPointerException for request or charset or factory * @throws ErrorDataDecoderException if the default charset was wrong when decoding or other errors */ public HttpPostMultipartRequestDecoder(HttpDataFactory factory, HttpRequest request, Charset charset) throws ErrorDataDecoderException { if (factory == null) { throw new NullPointerException("factory"); } if (request == null) { throw new NullPointerException("request"); } if (charset == null) { throw new NullPointerException("charset"); } this.request = request; this.charset = charset; this.factory = factory; // Fill default values setMultipart(this.request.headers().get(HttpHeaders.Names.CONTENT_TYPE)); if (!this.request.isChunked()) { undecodedChunk = this.request.getContent(); isLastChunk = true; parseBody(); } }
String upgrade = response.headers().get(Names.UPGRADE); + response.headers().get(Names.UPGRADE)); String connection = response.headers().get(Names.CONNECTION); if (connection == null || !connection.toLowerCase().equals(Values.UPGRADE.toLowerCase())) { throw new WebSocketHandshakeException("Invalid handshake response connection: " + response.headers().get(Names.CONNECTION)); String accept = response.headers().get(Names.SEC_WEBSOCKET_ACCEPT); if (accept == null || !accept.equals(expectedChallengeResponseString)) { throw new WebSocketHandshakeException(String.format("Invalid challenge. Actual: %s. Expected: %s", accept, String subprotocol = response.headers().get(Names.SEC_WEBSOCKET_PROTOCOL); setActualSubprotocol(subprotocol);
/** * Returns {@code true} if and only if the specified message contains the * {@code "Expect: 100-continue"} header. */ public static boolean is100ContinueExpected(HttpMessage message) { // Expect: 100-continue is for requests only. if (!(message instanceof HttpRequest)) { return false; } // It works only on HTTP/1.1 or later. if (message.getProtocolVersion().compareTo(HttpVersion.HTTP_1_1) < 0) { return false; } // In most cases, there will be one or zero 'Expect' header. String value = message.headers().get(Names.EXPECT); if (value == null) { return false; } if (Values.CONTINUE.equalsIgnoreCase(value)) { return true; } // Multiple 'Expect' headers. Search through them. return message.headers().contains(Names.EXPECT, Values.CONTINUE, true); }
final String responseContext = response.headers().get("X-Druid-Response-Context");
/** * Instances a new handshaker * * @return A new WebSocketServerHandshaker for the requested web socket version. Null if web * socket version is not supported. */ public WebSocketServerHandshaker newHandshaker(HttpRequest req) { String version = req.headers().get(Names.SEC_WEBSOCKET_VERSION); if (version != null) { if (version.equals(WebSocketVersion.V13.toHttpHeaderValue())) { // Version 13 of the wire protocol - RFC 6455 (version 17 of the draft hybi specification). return new WebSocketServerHandshaker13( webSocketURL, subprotocols, allowExtensions, maxFramePayloadLength); } else if (version.equals(WebSocketVersion.V08.toHttpHeaderValue())) { // Version 8 of the wire protocol - version 10 of the draft hybi specification. return new WebSocketServerHandshaker08( webSocketURL, subprotocols, allowExtensions, maxFramePayloadLength); } else if (version.equals(WebSocketVersion.V07.toHttpHeaderValue())) { // Version 8 of the wire protocol - version 07 of the draft hybi specification. return new WebSocketServerHandshaker07( webSocketURL, subprotocols, allowExtensions, maxFramePayloadLength); } else { return null; } } else { // Assume version 00 where version header was not specified return new WebSocketServerHandshaker00( webSocketURL, subprotocols, maxFramePayloadLength); } }
String redirectUrlStr = fullResponseHolder.getResponse().headers().get("Location"); if (redirectUrlStr == null) { throw new IOE("No redirect location is found in response from url[%s].", request.getUrl());
@Override protected EncoderEmbedder<ChannelBuffer> newContentEncoder( HttpMessage msg, String acceptEncoding) throws Exception { String contentEncoding = msg.headers().get(HttpHeaders.Names.CONTENT_ENCODING); if (contentEncoding != null && !HttpHeaders.Values.IDENTITY.equalsIgnoreCase(contentEncoding)) { // Encoded already. return null; } ZlibWrapper wrapper = determineWrapper(acceptEncoding); if (wrapper == null) { return null; } if (DetectionUtil.javaVersion() < 7 || noJdkZlibEncoder || windowBits != DEFAULT_JDK_WINDOW_SIZE || memLevel != DEFAULT_JDK_MEM_LEVEL) { return new EncoderEmbedder<ChannelBuffer>( new ZlibEncoder(wrapper, compressionLevel, windowBits, memLevel)); } else { return new EncoderEmbedder<ChannelBuffer>( new JdkZlibEncoder(wrapper, compressionLevel)); } }