本文整理匯總了Java中io.netty.handler.codec.http.HttpResponse.getStatus方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpResponse.getStatus方法的具體用法?Java HttpResponse.getStatus怎麽用?Java HttpResponse.getStatus使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.netty.handler.codec.http.HttpResponse
的用法示例。
在下文中一共展示了HttpResponse.getStatus方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: channelRead
import io.netty.handler.codec.http.HttpResponse; //導入方法依賴的package包/類
/**
* Reads the header part of response from remote HTTP server. Tests
* the validity of this connection.
*
* @param ctx handler context of this channel
* @param msg received message
*/
public void channelRead(ChannelHandlerContext ctx, Object msg) {
if (msg instanceof HttpResponse) {
HttpResponse response = (HttpResponse) msg;
HttpResponseStatus status = response.getStatus();
try {
if (HTTPResponseCode.isMoved(status)) {
URI uri = URI.create(
response.headers().get(HttpHeaders.Names.LOCATION));
builder.setUri(URI.create(uri.endpoint()));
code = ActionCode.Redirect;
throw new HTTPException(builder.getHost() + " " + status.toString());
} else if (HTTPResponseCode.isNotFound(status)) {
code = ActionCode.NotFound;
throw new HTTPException(builder.getHost() + " " + status.toString());
} else if (HTTPResponseCode.isInvalid(status)) {
code = ActionCode.Bad;
throw new HTTPException(
builder.getHost() + " HEADER method unsupported");
} else if (HTTPResponseCode.isOK(status)) try {
// Valid HTTP server found
code = ActionCode.OK;
builder.setKeepAlive(!response.headers()
.get("Connection").equalsIgnoreCase("close"));
} catch (NullPointerException npe) {
// No connection header.
builder.setKeepAlive(true);
}
} catch (HTTPException e) {
System.err.println(e.getMessage());
}
}
if (msg instanceof HttpContent) {
endTest(ctx);
}
}