本文整理了Java中org.jboss.netty.handler.codec.http.HttpResponse.headers()
方法的一些代码示例,展示了HttpResponse.headers()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.headers()
方法的具体详情如下:
包路径:org.jboss.netty.handler.codec.http.HttpResponse
类名称:HttpResponse
方法名:headers
暂无
代码示例来源:origin: apache/hive
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);
}
}
代码示例来源:origin: io.netty/netty
@Override
public void writeRequested(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
if (e.getMessage() instanceof HttpResponse) {
HttpResponse response = (HttpResponse) e.getMessage();
Integer id = ids.poll();
if (id != null && id.intValue() != NO_ID && !response.headers().contains(SpdyHttpHeaders.Names.STREAM_ID)) {
SpdyHttpHeaders.setStreamId(response, id);
}
}
super.writeRequested(ctx, e);
}
代码示例来源:origin: apache/hive
@Override public ClientResponse<Intermediate> handleResponse(HttpResponse httpResponse) {
try {
final HttpHeaders headers = httpResponse.headers();
manager.put(uri, Maps.asMap(headers.names(), headers::getAll));
return delegate.handleResponse(httpResponse);
} catch (IOException e) {
LOG.error("Error while processing Cookies from header", e);
throw new RuntimeException(e);
}
}
代码示例来源:origin: apache/hive
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);
}
代码示例来源:origin: apache/hive
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()) {
代码示例来源:origin: io.netty/netty
/**
* Return that we need cannot not support the web socket version
*
* @param channel
* Channel
*/
public ChannelFuture sendUnsupportedWebSocketVersionResponse(Channel channel) {
HttpResponse res = new DefaultHttpResponse(
HttpVersion.HTTP_1_1,
HttpResponseStatus.SWITCHING_PROTOCOLS);
res.setStatus(HttpResponseStatus.UPGRADE_REQUIRED);
res.headers().set(Names.SEC_WEBSOCKET_VERSION, WebSocketVersion.V13.toHttpHeaderValue());
return channel.write(res);
}
代码示例来源:origin: apache/hive
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;
}
代码示例来源:origin: io.netty/netty
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;
}
}
代码示例来源:origin: apache/incubator-druid
public static class TaskNotRunnableException extends RuntimeException
{
public TaskNotRunnableException(String message)
{
super(message);
}
}
代码示例来源:origin: io.netty/netty
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);
代码示例来源:origin: io.netty/netty
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;
}
代码示例来源:origin: io.netty/netty
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;
}
代码示例来源:origin: io.netty/netty
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);
代码示例来源:origin: apache/incubator-druid
@Override
public ClientResponse<Intermediate> handleResponse(HttpResponse httpResponse, TrafficCop trafficCop)
{
try {
final HttpHeaders headers = httpResponse.headers();
manager.put(uri, Maps.asMap(headers.names(), new Function<String, List<String>>()
{
@Override
public List<String> apply(String input)
{
return headers.getAll(input);
}
}));
}
catch (IOException e) {
log.error(e, "Error while processing Cookies from header");
}
finally {
return delegate.handleResponse(httpResponse, trafficCop);
}
}
代码示例来源:origin: io.netty/netty
String upgrade = response.headers().get(Names.UPGRADE);
if (!Values.WEBSOCKET.equalsIgnoreCase(upgrade)) {
throw new WebSocketHandshakeException("Invalid handshake response upgrade: "
+ response.headers().get(Names.UPGRADE));
String connection = response.headers().get(Names.CONNECTION);
if (!Values.UPGRADE.equalsIgnoreCase(connection)) {
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);
代码示例来源:origin: apache/incubator-druid
final String responseContext = response.headers().get("X-Druid-Response-Context");
代码示例来源:origin: apache/incubator-druid
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());
代码示例来源:origin: io.netty/netty
String upgrade = response.headers().get(Names.UPGRADE);
if (!Values.WEBSOCKET.equals(upgrade)) {
throw new WebSocketHandshakeException("Invalid handshake response upgrade: "
String connection = response.headers().get(Names.CONNECTION);
if (!Values.UPGRADE.equals(connection)) {
throw new WebSocketHandshakeException("Invalid handshake response connection: "
String subprotocol = response.headers().get(Names.SEC_WEBSOCKET_PROTOCOL);
setActualSubprotocol(subprotocol);
代码示例来源:origin: io.netty/netty
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);
代码示例来源:origin: io.netty/netty
if (httpResponse.headers().contains(SpdyHttpHeaders.Names.ASSOCIATED_TO_STREAM_ID)) {
SpdySynStreamFrame spdySynStreamFrame = createSynStreamFrame(httpResponse);
currentStreamId = spdySynStreamFrame.getStreamId();
内容来源于网络,如有侵权,请联系作者删除!