当前位置: 首页>>代码示例>>Java>>正文


Java HttpResponse.containsHeader方法代码示例

本文整理汇总了Java中org.apache.http.HttpResponse.containsHeader方法的典型用法代码示例。如果您正苦于以下问题:Java HttpResponse.containsHeader方法的具体用法?Java HttpResponse.containsHeader怎么用?Java HttpResponse.containsHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.HttpResponse的用法示例。


在下文中一共展示了HttpResponse.containsHeader方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDirectRequest

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
@Override
public HttpRequestBase getDirectRequest(HttpResponse response) {
    if (response.containsHeader("Location")) {
        String location = response.getFirstHeader("Location").getValue();
        HttpGet request = new HttpGet(location);
        if (response.containsHeader("Set-Cookie")) {
            String cookie = response.getFirstHeader("Set-Cookie").getValue();
            request.addHeader("Cookie", cookie);
        }
        return request;
    }
    return null;
}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:14,代码来源:DefaultHttpRedirectHandler.java

示例2: process

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
public void process(final HttpResponse response, final HttpContext context)
        throws HttpException, IOException {
    if (response == null) {
        throw new IllegalArgumentException
            ("HTTP response may not be null.");
    }
    int status = response.getStatusLine().getStatusCode();
    if ((status >= HttpStatus.SC_OK) &&
        !response.containsHeader(HTTP.DATE_HEADER)) {
        String httpdate = DATE_GENERATOR.getCurrentDate();
        response.setHeader(HTTP.DATE_HEADER, httpdate);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:14,代码来源:ResponseDate.java

示例3: process

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
public void process(final HttpResponse response, final HttpContext context)
        throws HttpException, IOException {
    if (response == null) {
        throw new IllegalArgumentException("HTTP request may not be null");
    }
    if (!response.containsHeader(HTTP.SERVER_HEADER)) {
        String s = (String) response.getParams().getParameter(
                CoreProtocolPNames.ORIGIN_SERVER);
        if (s != null) {
            response.addHeader(HTTP.SERVER_HEADER, s);
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:14,代码来源:ResponseServer.java

示例4: DownloadableProduct

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
/** Downloads the given product (the URL returned by {@link Product#getOrigin()}) using the
 * given HTTP client.
 *
 * @param http_client A well configured HTTP client to download the product (not null)
 * @param download_attempts How many time an interrupted download will be resumed
 * @param to_download A product whose Origin is set (not null)
 * @param md5 hash of data to download, for verification purposes (not null)
 * @param default_name the default name of this product (not null)
 * @throws IOException if the HTTP client could not HEAD the origin of the product
 * @throws InterruptedException if current thread is interrupted
 */
public DownloadableProduct(InterruptibleHttpClient http_client, int download_attempts,
      String to_download, String md5, String default_name)
      throws IOException, InterruptedException
{
   Objects.requireNonNull(http_client);
   Objects.requireNonNull(to_download);
   Objects.requireNonNull(default_name);
   this.url = to_download;
   this.httpClient = http_client;
   this.md5 = md5;
   this.downloadAttempts = download_attempts;

   // HEADs the target to check availability and get its properties
   HttpResponse headrsp = http_client.interruptibleHead(to_download);
   if (headrsp.getStatusLine().getStatusCode() != HttpStatus.SC_OK)
   {
      raiseFailure(headrsp.getStatusLine(), headrsp.getFirstHeader("cause-message"));
   }
   // Gets the size of the payload, its ETag and its Accept-Ranges
   this.contentLength = Long.parseLong(headrsp.getFirstHeader("Content-Length").getValue());
   setProperty(ProductConstants.DATA_SIZE, this.contentLength);
   this.contentType = headrsp.getFirstHeader("Content-Type").getValue();
   Header etag = headrsp.getFirstHeader("ETag");
   if (etag != null)
   {
      this.canResume = headrsp.containsHeader("Accept-Ranges");
      this.ETag = etag.getValue();
   }
   else
   {
      this.ETag = null;
      canResume = false;
   }

   // Gets the filename from the HTTP header field `Content-Disposition'
   String contdis = headrsp.getFirstHeader("Content-Disposition").getValue();
   if (contdis != null && !contdis.isEmpty())
   {
      Matcher m = pattern.matcher(contdis);
      if (m.find())
      {
         this.filename = m.group(1);
      }
      else
      {
         this.filename = default_name;
      }
   }
   else
   {
      this.filename = default_name;
   }
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:65,代码来源:DownloadableProduct.java

示例5: process

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
/**
 * Processes the response (possibly updating or inserting) Content-Length and Transfer-Encoding headers.
 * @param response The HttpResponse to modify.
 * @param context Unused.
 * @throws ProtocolException If either the Content-Length or Transfer-Encoding headers are found.
 * @throws IllegalArgumentException If the response is null.
 */
public void process(final HttpResponse response, final HttpContext context)
        throws HttpException, IOException {
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }
    if (this.overwrite) {
        response.removeHeaders(HTTP.TRANSFER_ENCODING);
        response.removeHeaders(HTTP.CONTENT_LEN);
    } else {
        if (response.containsHeader(HTTP.TRANSFER_ENCODING)) {
            throw new ProtocolException("Transfer-encoding header already present");
        }
        if (response.containsHeader(HTTP.CONTENT_LEN)) {
            throw new ProtocolException("Content-Length header already present");
        }
    }
    ProtocolVersion ver = response.getStatusLine().getProtocolVersion();
    HttpEntity entity = response.getEntity();
    if (entity != null) {
        long len = entity.getContentLength();
        if (entity.isChunked() && !ver.lessEquals(HttpVersion.HTTP_1_0)) {
            response.addHeader(HTTP.TRANSFER_ENCODING, HTTP.CHUNK_CODING);
        } else if (len >= 0) {
            response.addHeader(HTTP.CONTENT_LEN, Long.toString(entity.getContentLength()));
        }
        // Specify a content type if known
        if (entity.getContentType() != null && !response.containsHeader(
                HTTP.CONTENT_TYPE )) {
            response.addHeader(entity.getContentType());
        }
        // Specify a content encoding if known
        if (entity.getContentEncoding() != null && !response.containsHeader(
                HTTP.CONTENT_ENCODING)) {
            response.addHeader(entity.getContentEncoding());
        }
    } else {
        int status = response.getStatusLine().getStatusCode();
        if (status != HttpStatus.SC_NO_CONTENT
                && status != HttpStatus.SC_NOT_MODIFIED
                && status != HttpStatus.SC_RESET_CONTENT) {
            response.addHeader(HTTP.CONTENT_LEN, "0");
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:52,代码来源:ResponseContent.java


注:本文中的org.apache.http.HttpResponse.containsHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。