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


Java HttpResponse.headers方法代碼示例

本文整理匯總了Java中io.netty.handler.codec.http.HttpResponse.headers方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpResponse.headers方法的具體用法?Java HttpResponse.headers怎麽用?Java HttpResponse.headers使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.netty.handler.codec.http.HttpResponse的用法示例。


在下文中一共展示了HttpResponse.headers方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: afterResponse

import io.netty.handler.codec.http.HttpResponse; //導入方法依賴的package包/類
@Override
public void afterResponse(Channel clientChannel, Channel proxyChannel, HttpResponse httpResponse,
    HttpProxyInterceptPipeline pipeline) throws Exception {
  if (HttpDownUtil.checkReferer(pipeline.getHttpRequest(), "^https?://pan.baidu.com/disk/home.*$")
      && HttpDownUtil.checkUrl(pipeline.getHttpRequest(), "^.*method=batchdownload.*$")) {
    HttpHeaders resHeaders = httpResponse.headers();
    long fileSize = HttpDownUtil.getDownFileSize(resHeaders);
    //百度合並下載分段最多為16M
    int connections = (int) Math.ceil(fileSize / CHUNK_16M);
    TaskInfo taskInfo = new TaskInfo()
        .setId(UUID.randomUUID().toString())
        .setFileName(HttpDownUtil.getDownFileName(pipeline.getHttpRequest(), resHeaders))
        .setTotalSize(HttpDownUtil.getDownFileSize(resHeaders))
        .setConnections(connections)
        .setSupportRange(true);
    HttpDownUtil.startDownTask(taskInfo, pipeline.getHttpRequest(), httpResponse, clientChannel);
    return;
  }
  pipeline.afterResponse(clientChannel, proxyChannel, httpResponse);
}
 
開發者ID:monkeyWie,項目名稱:proxyee-down,代碼行數:21,代碼來源:BdyBatchDownIntercept.java

示例2: startDownTask

import io.netty.handler.codec.http.HttpResponse; //導入方法依賴的package包/類
public static void startDownTask(TaskInfo taskInfo, HttpRequest httpRequest,
    HttpResponse httpResponse, Channel clientChannel) {
  HttpHeaders httpHeaders = httpResponse.headers();
  HttpDownInfo httpDownInfo = new HttpDownInfo(taskInfo, httpRequest);
  HttpDownServer.DOWN_CONTENT.put(taskInfo.getId(), httpDownInfo);
  httpHeaders.clear();
  httpResponse.setStatus(HttpResponseStatus.OK);
  httpHeaders.set(HttpHeaderNames.CONTENT_TYPE, "text/html");
  String host = HttpDownServer.isDev() ? "localhost"
      : ((InetSocketAddress) clientChannel.localAddress()).getHostString();
  String js =
      "<script>window.top.location.href='http://" + host + ":" + HttpDownServer.VIEW_SERVER_PORT
          + "/#/tasks/new/" + httpDownInfo
          .getTaskInfo().getId()
          + "';</script>";
  HttpContent content = new DefaultLastHttpContent();
  content.content().writeBytes(js.getBytes());
  httpHeaders.set(HttpHeaderNames.CONTENT_LENGTH, js.getBytes().length);
  clientChannel.writeAndFlush(httpResponse);
  clientChannel.writeAndFlush(content);
  clientChannel.close();
}
 
開發者ID:monkeyWie,項目名稱:proxyee-down,代碼行數:23,代碼來源:HttpDownUtil.java

示例3: afterResponse

import io.netty.handler.codec.http.HttpResponse; //導入方法依賴的package包/類
@Override
public void afterResponse(Channel clientChannel, Channel proxyChannel, HttpResponse httpResponse,
    HttpProxyInterceptPipeline pipeline) throws Exception {
  boolean downFlag = false;
  if ((httpResponse.status().code() + "").indexOf("20") == 0) { //響應碼為20x
    HttpHeaders httpResHeaders = httpResponse.headers();
    String accept = pipeline.getHttpRequest().headers().get(HttpHeaderNames.ACCEPT);
    String contentType = httpResHeaders.get(HttpHeaderNames.CONTENT_TYPE);
    if (accept != null
        && accept.matches("^.*text/html.*$")  //直接url的方式訪問不是以HTML標簽加載的(a標簽除外)
        && contentType != null
        && !contentType.matches("^.*text/.*$")) { //響應體不是text/html報文
      //有兩種情況進行下載 1.url後綴為.xxx  2.帶有CONTENT_DISPOSITION:ATTACHMENT響應頭
      String disposition = httpResHeaders.get(HttpHeaderNames.CONTENT_DISPOSITION);
      if (pipeline.getHttpRequest().uri().matches("^.*\\.[^./]{1,5}(\\?[^?]*)?$")
          || (disposition != null && disposition.contains(HttpHeaderValues.ATTACHMENT))) {
        downFlag = true;
      }
    }
    HttpRequestInfo httpRequestInfo = (HttpRequestInfo) pipeline.getHttpRequest();
    if (downFlag) {   //如果是下載
      proxyChannel.close();//關閉嗅探下載連接
      HttpDownServer.LOGGER.debug("=====================下載===========================\n" +
          pipeline.getHttpRequest().toString() + "\n" +
          httpResponse.toString() + "\n" +
          "================================================");
      //原始的請求協議
      httpRequestInfo.setRequestProto(pipeline.getRequestProto());
      pipeline.afterResponse(clientChannel, proxyChannel, httpResponse);
    } else {
      if (httpRequestInfo.content() != null) {
        httpRequestInfo.setContent(null);
      }
    }
  }
  pipeline.getDefault().afterResponse(clientChannel, proxyChannel, httpResponse, pipeline);
}
 
開發者ID:monkeyWie,項目名稱:proxyee-down,代碼行數:38,代碼來源:HttpDownSniffIntercept.java


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