本文整理了Java中io.netty.handler.codec.http.HttpResponse
类的一些代码示例,展示了HttpResponse
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse
类的具体详情如下:
包路径:io.netty.handler.codec.http.HttpResponse
类名称:HttpResponse
[英]An HTTP response.
Unlike the Servlet API, io.netty.handler.codec.http.cookie.Cookie support is provided separately via io.netty.handler.codec.http.cookie.ServerCookieDecoder, io.netty.handler.codec.http.cookie.ClientCookieDecoder, io.netty.handler.codec.http.cookie.ServerCookieEncoder, and io.netty.handler.codec.http.cookie.ClientCookieEncoder.
[中]HTTP响应。
####访问Cookies
与ServletAPI不同,io。内蒂。处理程序。编解码器。http。曲奇Cookie支持通过io单独提供。内蒂。处理程序。编解码器。http。曲奇服务器CookieDecoder,io。内蒂。处理程序。编解码器。http。曲奇客户端CookieDecoder,io。内蒂。处理程序。编解码器。http。曲奇ServerCookieEncoder和io。内蒂。处理程序。编解码器。http。曲奇ClientCookie编码器。
代码示例来源:origin: wildfly/wildfly
if (response.status().code() == HttpResponseStatus.SWITCHING_PROTOCOLS.code() && response.headers().get(HttpHeaderNames.UPGRADE).equals(ACTIVEMQ_REMOTING)) {
String accept = response.headers().get(SEC_ACTIVEMQ_REMOTING_ACCEPT);
String expectedResponse = createExpectedResponse(MAGIC_NUMBER, ctx.channel().attr(REMOTING_KEY).get());
ctx.close();
latch.countDown();
ctx.close();
代码示例来源:origin: JZ-Darkal/AndroidHttpCapture
protected void captureResponseHeaderSize(HttpResponse httpResponse) {
String statusLine = httpResponse.getProtocolVersion().toString() + ' ' + httpResponse.getStatus().toString();
// +2 => CRLF after status line, +4 => header/data separation
long responseHeadersSize = statusLine.length() + 6;
HttpHeaders headers = httpResponse.headers();
responseHeadersSize += BrowserMobHttpUtil.getHeaderSize(headers);
harEntry.getResponse().setHeadersSize(responseHeadersSize);
}
代码示例来源:origin: wildfly/wildfly
@Override
public FullHttpResponse setStatus(HttpResponseStatus status) {
((HttpResponse) message).setStatus(status);
return this;
}
代码示例来源:origin: wildfly/wildfly
@Override
protected void sanitizeHeadersBeforeEncode(HttpResponse msg, boolean isAlwaysEmpty) {
if (!isAlwaysEmpty && method == HttpMethod.CONNECT && msg.status().codeClass() == HttpStatusClass.SUCCESS) {
// Stripping Transfer-Encoding:
// See https://tools.ietf.org/html/rfc7230#section-3.3.1
msg.headers().remove(HttpHeaderNames.TRANSFER_ENCODING);
return;
}
super.sanitizeHeadersBeforeEncode(msg, isAlwaysEmpty);
}
代码示例来源:origin: wildfly/wildfly
protected boolean isContentAlwaysEmpty(HttpMessage msg) {
if (msg instanceof HttpResponse) {
HttpResponse res = (HttpResponse) msg;
int code = res.status().code();
// 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) {
// One exception: Hixie 76 websocket handshake response
return !(code == 101 && !res.headers().contains(HttpHeaderNames.SEC_WEBSOCKET_ACCEPT)
&& res.headers().contains(HttpHeaderNames.UPGRADE, HttpHeaderValues.WEBSOCKET, true));
}
switch (code) {
case 204: case 304:
return true;
}
}
return false;
}
代码示例来源:origin: wildfly/wildfly
@Override
protected void sanitizeHeadersBeforeEncode(HttpResponse msg, boolean isAlwaysEmpty) {
if (isAlwaysEmpty) {
HttpResponseStatus status = msg.status();
if (status.codeClass() == HttpStatusClass.INFORMATIONAL ||
status.code() == HttpResponseStatus.NO_CONTENT.code()) {
// Stripping Content-Length:
// See https://tools.ietf.org/html/rfc7230#section-3.3.2
msg.headers().remove(HttpHeaderNames.CONTENT_LENGTH);
// Stripping Transfer-Encoding:
// See https://tools.ietf.org/html/rfc7230#section-3.3.1
msg.headers().remove(HttpHeaderNames.TRANSFER_ENCODING);
} else if (status.code() == HttpResponseStatus.RESET_CONTENT.code()) {
// Stripping Transfer-Encoding:
msg.headers().remove(HttpHeaderNames.TRANSFER_ENCODING);
// Set Content-Length: 0
// https://httpstatuses.com/205
msg.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, 0);
}
}
}
代码示例来源:origin: Atmosphere/nettosphere
private void sendHttpResponse(ChannelHandlerContext ctx, HttpRequest req, HttpResponse res) {
ctx.pipeline().addBefore(BridgeRuntime.class.getName(), "encoder", new HttpResponseEncoder());
// Generate an error page if response status code is not OK (200).
if (res.getStatus().code() != 200) {
FullHttpResponse response = (FullHttpResponse) res;
response.content().writeBytes(Unpooled.copiedBuffer(res.getStatus().toString(), CharsetUtil.UTF_8));
io.netty.handler.codec.http.HttpUtil.setContentLength(res, response.content().readableBytes());
io.netty.handler.codec.http.HttpUtil.setKeepAlive(res, false);
}
// Send the response and close the connection if necessary.
ChannelFuture f = ctx.channel().writeAndFlush(res);
if (!isKeepAlive(req) || res.getStatus().code() != 200) {
f.addListener(ChannelFutureListener.CLOSE);
}
}
代码示例来源:origin: jersey/jersey
for (Map.Entry<String, String> entry : response.headers().entries()) {
jerseyResponse.getHeaders().add(entry.getKey(), entry.getValue());
if ((response.headers().contains(HttpHeaderNames.CONTENT_LENGTH) && HttpUtil.getContentLength(response) > 0)
|| HttpUtil.isTransferEncodingChunked(response)) {
ctx.channel().closeFuture().addListener(new GenericFutureListener<Future<? super Void>>() {
@Override
public void operationComplete(Future<? super Void> future) throws Exception {
if (content.isReadable()) {
byte[] bytes = new byte[content.readableBytes()];
content.getBytes(content.readerIndex(), bytes);
isList.add(new ByteArrayInputStream(bytes));
代码示例来源:origin: docker-java/docker-java
switch (response.status().code()) {
case 200:
case 201:
case 204:
ctx.fireChannelRead(byteBuf);
break;
default:
errorBody.writeBytes(byteBuf);
try {
switch (response.status().code()) {
case 101:
case 200:
case 301:
case 302:
if (response.headers().contains(HttpHeaderNames.LOCATION)) {
String location = response.headers().get(HttpHeaderNames.LOCATION);
HttpRequest redirected = requestProvider.getHttpRequest(location);
ctx.channel().writeAndFlush(redirected);
throw new InternalServerErrorException(getBodyAsMessage(errorBody));
default:
throw new DockerException(getBodyAsMessage(errorBody), response.status().code());
代码示例来源:origin: blynkkk/blynk-server
HttpUtil.setContentLength(response, content.length());
response.headers().set(CONTENT_TYPE, "text/html");
if (HttpUtil.isKeepAlive(request)) {
response.headers().set(CONNECTION, HttpHeaderValues.KEEP_ALIVE);
ctx.write(response);
ByteBuf buf = ctx.alloc().buffer(content.length());
buf.writeBytes(content.getBytes());
ctx.write(buf);
lastContentFuture = ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT);
if (!HttpUtil.isKeepAlive(request)) {
代码示例来源:origin: eclipse-vertx/vert.x
if (msg instanceof HttpResponse) {
HttpResponse resp = (HttpResponse) msg;
HttpResponseStatus status = resp.status();
if (status.code() != 101) {
handshaker = null;
close();
handleException(new WebsocketRejectedException(status.code()));
return;
response = new DefaultFullHttpResponse(resp.protocolVersion(), status);
response.headers().add(resp.headers());
response.content().writeBytes(((HttpContent) msg).content());
if (msg instanceof LastHttpContent) {
response.trailingHeaders().add(((LastHttpContent) msg).trailingHeaders());
try {
handshakeComplete(ctx, response);
chctx.pipeline().remove(HandshakeInboundHandler.this);
for (;;) {
Object m = buffered.poll();
break;
ctx.fireChannelRead(m);
代码示例来源:origin: wildfly/wildfly
if (this.contentSizeThreshold > 0) {
if (headers instanceof HttpContent &&
((HttpContent) headers).content().readableBytes() < contentSizeThreshold) {
return null;
String contentEncoding = headers.headers().get(HttpHeaderNames.CONTENT_ENCODING);
if (contentEncoding != null) {
new EmbeddedChannel(ctx.channel().id(), ctx.channel().metadata().hasDisconnect(),
ctx.channel().config(), ZlibCodecFactory.newZlibEncoder(
wrapper, compressionLevel, windowBits, memLevel)));
代码示例来源:origin: Netflix/zuul
HttpResponse response = ((CompleteEvent) evt).getResponse();
if (response != null) {
if ("close".equalsIgnoreCase(response.headers().get("Connection"))) {
closeConnection = true;
handleComplete(ctx.channel());
if (! closeConnection) {
ctx.channel().read();
} else {
ctx.close();
代码示例来源:origin: wildfly/wildfly
private static void sendHttpResponse(ChannelHandlerContext ctx, HttpRequest req, HttpResponse res) {
ChannelFuture f = ctx.channel().writeAndFlush(res);
if (!isKeepAlive(req) || res.status().code() != 200) {
f.addListener(ChannelFutureListener.CLOSE);
}
}
代码示例来源:origin: mpusher/mpush
@Override
public void onResponse(HttpResponse httpResponse) {
HttpResponseMessage response = HttpResponseMessage
.from(request)
.setStatusCode(httpResponse.status().code())
.setReasonPhrase(httpResponse.status().reasonPhrase());
for (Map.Entry<String, String> entry : httpResponse.headers()) {
response.addHeader(entry.getKey(), entry.getValue());
}
if (httpResponse instanceof FullHttpResponse) {
ByteBuf content = ((FullHttpResponse) httpResponse).content();
if (content != null && content.readableBytes() > 0) {
byte[] body = new byte[content.readableBytes()];
content.readBytes(body);
response.body = body;
response.addHeader(CONTENT_LENGTH.toString(), Integer.toString(response.body.length));
}
}
response.send();
Logs.HTTP.info("send proxy request success end request={}, response={}", request, response);
}
代码示例来源:origin: line/armeria
if (msg instanceof HttpResponse) {
final HttpResponse nettyRes = (HttpResponse) msg;
final DecoderResult decoderResult = nettyRes.decoderResult();
if (!decoderResult.isSuccess()) {
fail(ctx, new ProtocolViolationException(decoderResult.cause()));
if (!HttpUtil.isKeepAlive(nettyRes)) {
disconnectWhenFinished();
if (nettyRes.status().codeClass() == HttpStatusClass.INFORMATIONAL) {
state = State.NEED_INFORMATIONAL_DATA;
} else {
res.scheduleTimeout(channel().eventLoop());
res.write(ArmeriaHttpUtil.toArmeria(nettyRes));
} else {
final int dataLength = data.readableBytes();
if (dataLength > 0) {
assert res != null;
if (!trailingHeaders.isEmpty()) {
res.write(ArmeriaHttpUtil.toArmeria(trailingHeaders));
ctx.close();
代码示例来源:origin: AsyncHttpClient/async-http-client
String ifModifiedSince = request.headers().get(IF_MODIFIED_SINCE);
if (ifModifiedSince != null && !ifModifiedSince.isEmpty()) {
SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US);
HttpUtil.setContentLength(response, fileLength);
setContentTypeHeader(response, file);
setDateAndCacheHeaders(response, file);
if (HttpUtil.isKeepAlive(request)) {
response.headers().set(CONNECTION, HttpHeaderValues.KEEP_ALIVE);
ctx.write(response);
if (ctx.pipeline().get(SslHandler.class) == null) {
sendFileFuture =
ctx.write(new DefaultFileRegion(raf.getChannel(), 0, fileLength), ctx.newProgressivePromise());
lastContentFuture = ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT);
if (!HttpUtil.isKeepAlive(request)) {
代码示例来源:origin: resteasy/Resteasy
if (message != null)
responseStatus = new HttpResponseStatus(status, message);
setStatus(status);
responseStatus = HttpResponseStatus.valueOf(status);
setStatus(status);
if (message != null)
ByteBuf byteBuf = ctx.alloc().buffer();
byteBuf.writeBytes(message.getBytes());
response.headers().add(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
if (message == null) response.headers().add(HttpHeaderNames.CONTENT_LENGTH, 0);
else response.headers().add(HttpHeaderNames.CONTENT_LENGTH, message.getBytes().length);
ctx.writeAndFlush(response);
committed = true;
代码示例来源:origin: mrniko/netty-socketio
private void write(XHROptionsMessage msg, ChannelHandlerContext ctx, ChannelPromise promise) {
HttpResponse res = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.OK);
res.headers().add(HttpHeaderNames.SET_COOKIE, "io=" + msg.getSessionId())
.add(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE)
.add(HttpHeaderNames.ACCESS_CONTROL_ALLOW_HEADERS, HttpHeaderNames.CONTENT_TYPE);
String origin = ctx.channel().attr(ORIGIN).get();
addOriginHeaders(origin, res);
ByteBuf out = encoder.allocateBuffer(ctx.alloc());
sendMessage(msg, ctx.channel(), out, res, promise);
}
代码示例来源:origin: line/armeria
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (needsToFilterUpgradeResponse && msg instanceof HttpResponse) {
needsToFilterUpgradeResponse = false;
final HttpResponse res = (HttpResponse) msg;
if (res.status().code() == HttpResponseStatus.SWITCHING_PROTOCOLS.code()) {
final HttpHeaders headers = res.headers();
if (!headers.contains(HttpHeaderNames.UPGRADE)) {
headers.set(HttpHeaderNames.UPGRADE,
Http2CodecUtil.HTTP_UPGRADE_PROTOCOL_NAME);
}
}
if (!needsToFilterUpgradeRequest) {
ctx.pipeline().remove(this);
}
}
ctx.fireChannelRead(msg);
}
内容来源于网络,如有侵权,请联系作者删除!