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


Java HttpResponse.headerIterator方法代码示例

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


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

示例1: getKeepAliveDuration

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }
    HeaderElementIterator it = new BasicHeaderElementIterator(
            response.headerIterator(HTTP.CONN_KEEP_ALIVE));
    while (it.hasNext()) {
        HeaderElement he = it.nextElement();
        String param = he.getName();
        String value = he.getValue();
        if (value != null && param.equalsIgnoreCase("timeout")) {
            try {
                return Long.parseLong(value) * 1000;
            } catch(NumberFormatException ignore) {
            }
        }
    }
    return -1;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:DefaultConnectionKeepAliveStrategy.java

示例2: getAllowedMethods

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
public Set<String> getAllowedMethods(final HttpResponse response) {
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }

    HeaderIterator it = response.headerIterator("Allow");
    Set<String> methods = new HashSet<String>();
    while (it.hasNext()) {
        Header header = it.nextHeader();
        HeaderElement[] elements = header.getElements();
        for (HeaderElement element : elements) {
            methods.add(element.getName());
        }
    }
    return methods;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:HttpOptions.java

示例3: getKeepAliveDuration

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
@Override
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
  HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
  while (it.hasNext()) {
    HeaderElement he = it.nextElement();
    String param = he.getName();
    String value = he.getValue();
    if (value != null && param.equalsIgnoreCase("timeout")) {
      long timeout = Long.parseLong(value) * 1000;
      if (timeout > 20 * 1000) {
        return 20 * 1000;
      } else {
        return timeout;
      }
    }
  }
  return 5 * 1000;
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:19,代码来源:WebhookMsgHandler.java

示例4: getKeepAliveDuration

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
    HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
    while (it.hasNext()) {
        HeaderElement he = it.nextElement();
        String param = he.getName();
        String value = he.getValue();
        if (value != null && param.equalsIgnoreCase("timeout")) {
            try {
                return Long.parseLong(value) * 1000;
            } catch(NumberFormatException ignore) {
            }
        }
    }
    return 30 * 1000; //默认30秒
}
 
开发者ID:penggle,项目名称:xproject,代码行数:16,代码来源:HttpClientUtils.java

示例5: 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 (context == null) {
        throw new IllegalArgumentException("HTTP context may not be null");
    }

    // Obtain actual CookieSpec instance
    CookieSpec cookieSpec = (CookieSpec) context.getAttribute(
            ClientContext.COOKIE_SPEC);
    if (cookieSpec == null) {
        this.log.debug("Cookie spec not specified in HTTP context");
        return;
    }
    // Obtain cookie store
    CookieStore cookieStore = (CookieStore) context.getAttribute(
            ClientContext.COOKIE_STORE);
    if (cookieStore == null) {
        this.log.debug("Cookie store not specified in HTTP context");
        return;
    }
    // Obtain actual CookieOrigin instance
    CookieOrigin cookieOrigin = (CookieOrigin) context.getAttribute(
            ClientContext.COOKIE_ORIGIN);
    if (cookieOrigin == null) {
        this.log.debug("Cookie origin not specified in HTTP context");
        return;
    }
    HeaderIterator it = response.headerIterator(SM.SET_COOKIE);
    processCookies(it, cookieSpec, cookieOrigin, cookieStore);

    // see if the cookie spec supports cookie versioning.
    if (cookieSpec.getVersion() > 0) {
        // process set-cookie2 headers.
        // Cookie2 will replace equivalent Cookie instances
        it = response.headerIterator(SM.SET_COOKIE2);
        processCookies(it, cookieSpec, cookieOrigin, cookieStore);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:42,代码来源:ResponseProcessCookies.java


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