當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpResponse.getStatus方法代碼示例

本文整理匯總了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);
  }
}
 
開發者ID:didclab,項目名稱:onedatashare,代碼行數:43,代碼來源:HTTPTestHandler.java


注:本文中的io.netty.handler.codec.http.HttpResponse.getStatus方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。