/** * Adds all header entries of the specified {@code headers}. * * @return {@code this} */ public HttpHeaders add(HttpHeaders headers) { if (headers == null) { throw new NullPointerException("headers"); } for (Map.Entry<String, String> e: headers) { add(e.getKey(), e.getValue()); } return this; }
protected void setResponseHeaders(HttpResponse response, boolean keepAliveParam, long contentLength) { if (!connectionKeepAliveEnabled && !keepAliveParam) { LOG.info("Setting connection close header..."); response.headers().add(HttpHeaders.Names.CONNECTION, CONNECTION_CLOSE); } else { response.headers().add(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(contentLength)); response.headers().add(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.KEEP_ALIVE); response.headers().add(HttpHeaders.Values.KEEP_ALIVE, "timeout=" + connectionKeepAliveTimeOut); LOG.debug("Content Length in shuffle : " + contentLength); } }
/** * Adds a new header with the specified name and value. * If the specified value is not a {@link String}, it is converted into a * {@link String} by {@link Object#toString()}, except for {@link Date} * and {@link Calendar} which are formatted to the date format defined in * <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1">RFC2616</a>. */ public static void addHeader(HttpMessage message, String name, Object value) { message.headers().add(name, value); }
/** * Adds a new integer header with the specified name and value. */ public static void addIntHeader(HttpMessage message, String name, int value) { message.headers().add(name, value); }
/** * Adds a new date header with the specified name and value. The specified * value is formatted as defined in * <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1">RFC2616</a> */ public static void addDateHeader(HttpMessage message, String name, Date value) { message.headers().add(name, value); }
/** * Cleans the current header entries and copies all header entries of the specified {@code headers}. * * @return {@code this} */ public HttpHeaders set(HttpHeaders headers) { if (headers == null) { throw new NullPointerException("headers"); } clear(); for (Map.Entry<String, String> e: headers) { add(e.getKey(), e.getValue()); } return this; }
protected void sendError(ChannelHandlerContext ctx, String message, HttpResponseStatus status) { HttpResponse response = new DefaultHttpResponse(HTTP_1_1, status); response.headers().add(CONTENT_TYPE, "text/plain; charset=UTF-8"); // Put shuffle version into http header response.headers().add(ShuffleHeader.HTTP_HEADER_NAME, ShuffleHeader.DEFAULT_HTTP_HEADER_NAME); response.headers().add(ShuffleHeader.HTTP_HEADER_VERSION, ShuffleHeader.DEFAULT_HTTP_HEADER_VERSION); response.setContent( ChannelBuffers.copiedBuffer(message, CharsetUtil.UTF_8)); // Close the connection as soon as the error message is sent. ctx.getChannel().write(response).addListener(ChannelFutureListener.CLOSE); }
SecureShuffleUtils.generateHash(urlHashStr.getBytes(Charsets.UTF_8), tokenSecret); response.headers().add(SecureShuffleUtils.HTTP_HEADER_REPLY_URL_HASH, reply); response.headers().add(ShuffleHeader.HTTP_HEADER_NAME, ShuffleHeader.DEFAULT_HTTP_HEADER_NAME); response.headers().add(ShuffleHeader.HTTP_HEADER_VERSION, ShuffleHeader.DEFAULT_HTTP_HEADER_VERSION); if (LOG.isDebugEnabled()) {
!name.equalsIgnoreCase(HttpHeaders.Names.TRANSFER_ENCODING) && !name.equalsIgnoreCase(HttpHeaders.Names.TRAILER)) { trailer.trailingHeaders().add(name, header[1]);
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());
headers.add(HttpHeaders.Names.CONTENT_TYPE, contentType); String value = HttpHeaders.Values.MULTIPART_FORM_DATA + "; " + HttpHeaders.Values.BOUNDARY + '=' + multipartDataBoundary; headers.add(HttpHeaders.Names.CONTENT_TYPE, value); } else { headers.add(HttpHeaders.Names.CONTENT_TYPE, HttpHeaders.Values.APPLICATION_X_WWW_FORM_URLENCODED); headers.add(HttpHeaders.Names.TRANSFER_ENCODING, v); headers.add(HttpHeaders.Names.TRANSFER_ENCODING, HttpHeaders.Values.CHUNKED); request.setContent(ChannelBuffers.EMPTY_BUFFER); } else {
private static HttpResponse createHttpResponse(int spdyVersion, SpdyHeadersFrame responseFrame) throws Exception { // Create the first line of the response from the name/value pairs HttpResponseStatus status = SpdyHeaders.getStatus(spdyVersion, responseFrame); HttpVersion version = SpdyHeaders.getVersion(spdyVersion, responseFrame); SpdyHeaders.removeStatus(spdyVersion, responseFrame); SpdyHeaders.removeVersion(spdyVersion, responseFrame); HttpResponse httpResponse = new DefaultHttpResponse(version, status); for (Map.Entry<String, String> e: responseFrame.headers()) { httpResponse.headers().add(e.getKey(), e.getValue()); } // The Connection and Keep-Alive headers are no longer valid HttpHeaders.setKeepAlive(httpResponse, true); // Transfer-Encoding header is not valid httpResponse.headers().remove(HttpHeaders.Names.TRANSFER_ENCODING); httpResponse.headers().remove(HttpHeaders.Names.TRAILER); return httpResponse; } }
res.headers().add(Names.UPGRADE, WEBSOCKET.toLowerCase()); 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) { throw new WebSocketHandshakeException("Requested subprotocol(s) not supported: " + subprotocols); } else { res.headers().add(Names.SEC_WEBSOCKET_PROTOCOL, selectedSubprotocol); setSelectedSubprotocol(selectedSubprotocol);
res.headers().add(Names.UPGRADE, WEBSOCKET.toLowerCase()); 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) { throw new WebSocketHandshakeException("Requested subprotocol(s) not supported: " + subprotocols); } else { res.headers().add(Names.SEC_WEBSOCKET_PROTOCOL, selectedSubprotocol); setSelectedSubprotocol(selectedSubprotocol);
res.headers().add(Names.UPGRADE, WEBSOCKET.toLowerCase()); 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) { throw new WebSocketHandshakeException("Requested subprotocol(s) not supported: " + subprotocols); } else { res.headers().add(Names.SEC_WEBSOCKET_PROTOCOL, selectedSubprotocol); setSelectedSubprotocol(selectedSubprotocol);
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; }
m.headers().add(Names.TRANSFER_ENCODING, Values.CHUNKED);