/** * 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; } }
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; }
request.headers().get(SecureShuffleUtils.HTTP_HEADER_URL_HASH); if (urlHashStr == null) { LOG.info("Missing header hash for " + appid);
/** * * @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(); } }
request.headers().add(Names.UPGRADE, Values.WEBSOCKET.toLowerCase()); request.headers().add(Names.CONNECTION, Values.UPGRADE); request.headers().add(Names.SEC_WEBSOCKET_KEY, key); request.headers().add(Names.HOST, wsURL.getHost()); request.headers().add(Names.SEC_WEBSOCKET_ORIGIN, originValue); request.headers().add(Names.SEC_WEBSOCKET_PROTOCOL, expectedSubprotocol); request.headers().add(Names.SEC_WEBSOCKET_VERSION, "7"); request.headers().add(e.getKey(), e.getValue());
request.headers().add(Names.UPGRADE, Values.WEBSOCKET.toLowerCase()); request.headers().add(Names.CONNECTION, Values.UPGRADE); request.headers().add(Names.SEC_WEBSOCKET_KEY, key); request.headers().add(Names.HOST, wsURL.getHost() + ':' + wsPort); request.headers().add(Names.ORIGIN, originValue); request.headers().add(Names.SEC_WEBSOCKET_PROTOCOL, expectedSubprotocol); request.headers().add(Names.SEC_WEBSOCKET_VERSION, "13"); request.headers().add(e.getKey(), e.getValue());
request.headers().add(Names.UPGRADE, Values.WEBSOCKET.toLowerCase()); request.headers().add(Names.CONNECTION, Values.UPGRADE); request.headers().add(Names.SEC_WEBSOCKET_KEY, key); request.headers().add(Names.HOST, wsURL.getHost()); request.headers().add(Names.SEC_WEBSOCKET_ORIGIN, originValue); request.headers().add(Names.SEC_WEBSOCKET_PROTOCOL, expectedSubprotocol); request.headers().add(Names.SEC_WEBSOCKET_VERSION, "8"); request.headers().add(e.getKey(), e.getValue());
request.headers().add(Names.UPGRADE, Values.WEBSOCKET); request.headers().add(Names.CONNECTION, Values.UPGRADE); request.headers().add(Names.HOST, wsURL.getHost()); request.headers().add(Names.ORIGIN, originValue); request.headers().add(Names.SEC_WEBSOCKET_KEY1, key1); request.headers().add(Names.SEC_WEBSOCKET_KEY2, key2); String expectedSubprotocol = getExpectedSubprotocol(); if (expectedSubprotocol != null && expectedSubprotocol.length() != 0) { request.headers().add(Names.SEC_WEBSOCKET_PROTOCOL, expectedSubprotocol); request.headers().add(e.getKey(), e.getValue()); request.headers().set(Names.CONTENT_LENGTH, key3.length); request.setContent(ChannelBuffers.copiedBuffer(key3));
/** * 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); } }
HttpVersion.HTTP_1_1, HttpMethod.POST, serverPath); if (serverName != null) { req.headers().set(HttpHeaders.Names.HOST, serverName); req.headers().set(HttpHeaders.Names.CONTENT_TYPE, "application/octet-stream"); req.headers().set(HttpHeaders.Names.TRANSFER_ENCODING, HttpHeaders.Values.CHUNKED); req.headers().set(HttpHeaders.Names.CONTENT_TRANSFER_ENCODING, HttpHeaders.Values.BINARY); req.headers().set(HttpHeaders.Names.USER_AGENT, HttpTunnelingClientSocketChannel.class.getName());
private static HttpRequest createHttpRequest(int spdyVersion, SpdyHeadersFrame requestFrame) throws Exception { // Create the first line of the request from the name/value pairs HttpMethod method = SpdyHeaders.getMethod(spdyVersion, requestFrame); String url = SpdyHeaders.getUrl(spdyVersion, requestFrame); HttpVersion httpVersion = SpdyHeaders.getVersion(spdyVersion, requestFrame); SpdyHeaders.removeMethod(spdyVersion, requestFrame); SpdyHeaders.removeUrl(spdyVersion, requestFrame); SpdyHeaders.removeVersion(spdyVersion, requestFrame); HttpRequest httpRequest = new DefaultHttpRequest(httpVersion, method, url); // Remove the scheme header SpdyHeaders.removeScheme(spdyVersion, requestFrame); // Replace the SPDY host header with the HTTP host header String host = SpdyHeaders.getHost(requestFrame); SpdyHeaders.removeHost(requestFrame); HttpHeaders.setHost(httpRequest, host); for (Map.Entry<String, String> e: requestFrame.headers()) { httpRequest.headers().add(e.getKey(), e.getValue()); } // The Connection and Keep-Alive headers are no longer valid HttpHeaders.setKeepAlive(httpRequest, true); // Transfer-Encoding header is not valid httpRequest.headers().remove(HttpHeaders.Names.TRANSFER_ENCODING); return httpRequest; }
if (!Values.UPGRADE.equalsIgnoreCase(req.headers().get(CONNECTION)) || !WEBSOCKET.equalsIgnoreCase(req.headers().get(Names.UPGRADE))) { throw new WebSocketHandshakeException("not a WebSocket handshake request: missing upgrade"); boolean isHixie76 = req.headers().contains(SEC_WEBSOCKET_KEY1) && req.headers().contains(SEC_WEBSOCKET_KEY2); res.headers().add(SEC_WEBSOCKET_ORIGIN, req.headers().get(ORIGIN)); res.headers().add(SEC_WEBSOCKET_LOCATION, getWebSocketUrl()); String subprotocols = req.headers().get(SEC_WEBSOCKET_PROTOCOL); if (subprotocols != null) { String selectedSubprotocol = selectSubprotocol(subprotocols); String key1 = req.headers().get(SEC_WEBSOCKET_KEY1); String key2 = req.headers().get(SEC_WEBSOCKET_KEY2); int a = (int) (Long.parseLong(key1.replaceAll("[^0-9]", "")) / key1.replaceAll("[^ ]", "").length()); int b = (int) (Long.parseLong(key2.replaceAll("[^0-9]", "")) / key2.replaceAll("[^ ]", "").length()); } else { res.headers().add(WEBSOCKET_ORIGIN, req.headers().get(ORIGIN)); res.headers().add(WEBSOCKET_LOCATION, getWebSocketUrl()); String protocol = req.headers().get(WEBSOCKET_PROTOCOL); if (protocol != null) { res.headers().add(WEBSOCKET_PROTOCOL, selectSubprotocol(protocol));
HttpHeaders headers = request.headers();
String key = req.headers().get(Names.SEC_WEBSOCKET_KEY); if (key == null) { throw new WebSocketHandshakeException("not a WebSocket request: missing key"); res.headers().add(Names.CONNECTION, Names.UPGRADE); res.headers().add(Names.SEC_WEBSOCKET_ACCEPT, accept); String subprotocols = req.headers().get(Names.SEC_WEBSOCKET_PROTOCOL); if (subprotocols != null) { String selectedSubprotocol = selectSubprotocol(subprotocols);
String key = req.headers().get(Names.SEC_WEBSOCKET_KEY); if (key == null) { throw new WebSocketHandshakeException("not a WebSocket request: missing key"); res.headers().add(Names.CONNECTION, Names.UPGRADE); res.headers().add(Names.SEC_WEBSOCKET_ACCEPT, accept); String subprotocols = req.headers().get(Names.SEC_WEBSOCKET_PROTOCOL); if (subprotocols != null) { String selectedSubprotocol = selectSubprotocol(subprotocols);
String key = req.headers().get(Names.SEC_WEBSOCKET_KEY); if (key == null) { throw new WebSocketHandshakeException("not a WebSocket request: missing key"); res.headers().add(Names.CONNECTION, Names.UPGRADE); res.headers().add(Names.SEC_WEBSOCKET_ACCEPT, accept); String subprotocols = req.headers().get(Names.SEC_WEBSOCKET_PROTOCOL); if (subprotocols != null) { String selectedSubprotocol = selectSubprotocol(subprotocols);
public static MultivaluedMap<String, String> extractRequestHeaders(HttpRequest request) { Headers<String> requestHeaders = new Headers<String>(); for (Map.Entry<String, String> header : request.headers()) { requestHeaders.add(header.getKey(), header.getValue()); } return requestHeaders; } }
private void configureTransferAdapter(AsyncHandler<?> handler, HttpRequest httpRequest) { FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); for (Map.Entry<String, String> entries : httpRequest.headers()) { h.add(entries.getKey(), entries.getValue()); } TransferCompletionHandler.class.cast(handler).headers(h); }