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


Java HttpMessage.getProtocolVersion方法代码示例

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


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

示例1: generateViaHeader

import org.apache.http.HttpMessage; //导入方法依赖的package包/类
private String generateViaHeader(final HttpMessage msg) {

        final ProtocolVersion pv = msg.getProtocolVersion();
        final String existingEntry = viaHeaders.get(pv);
        if (existingEntry != null) {
            return existingEntry;
        }

        final VersionInfo vi = VersionInfo.loadVersionInfo("org.apache.http.client", getClass().getClassLoader());
        final String release = (vi != null) ? vi.getRelease() : VersionInfo.UNAVAILABLE;

        String value;
        if ("http".equalsIgnoreCase(pv.getProtocol())) {
            value = String.format("%d.%d localhost (Apache-HttpClient/%s (cache))", pv.getMajor(), pv.getMinor(),
                    release);
        } else {
            value = String.format("%s/%d.%d localhost (Apache-HttpClient/%s (cache))", pv.getProtocol(), pv.getMajor(),
                    pv.getMinor(), release);
        }
        viaHeaders.put(pv, value);

        return value;
    }
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:24,代码来源:CachingHttpClient.java

示例2: generateViaHeader

import org.apache.http.HttpMessage; //导入方法依赖的package包/类
private String generateViaHeader(final HttpMessage msg) {

        final ProtocolVersion pv = msg.getProtocolVersion();
        final String existingEntry = viaHeaders.get(pv);
        if (existingEntry != null) {
            return existingEntry;
        }

        final VersionInfo vi = VersionInfo.loadVersionInfo("org.apache.http.client", getClass().getClassLoader());
        final String release = (vi != null) ? vi.getRelease() : VersionInfo.UNAVAILABLE;

        String value;
        final int major = pv.getMajor();
        final int minor = pv.getMinor();
        if ("http".equalsIgnoreCase(pv.getProtocol())) {
            value = String.format("%d.%d localhost (Apache-HttpClient/%s (cache))", major, minor,
                    release);
        } else {
            value = String.format("%s/%d.%d localhost (Apache-HttpClient/%s (cache))", pv.getProtocol(), major,
                    minor, release);
        }
        viaHeaders.put(pv, value);

        return value;
    }
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:26,代码来源:CachingExec.java

示例3: generateViaHeader

import org.apache.http.HttpMessage; //导入方法依赖的package包/类
private String generateViaHeader(HttpMessage msg) {
	final VersionInfo vi = VersionInfo.loadVersionInfo(
			"org.apache.http.client", getClass().getClassLoader());
	final String release = (vi != null) ? vi.getRelease()
			: VersionInfo.UNAVAILABLE;
	final ProtocolVersion pv = msg.getProtocolVersion();
	if ("http".equalsIgnoreCase(pv.getProtocol())) {
		return String.format(
				"%d.%d localhost (Apache-HttpClient/%s (cache))",
				pv.getMajor(), pv.getMinor(), release);
	} else {
		return String.format(
				"%s/%d.%d localhost (Apache-HttpClient/%s (cache))",
				pv.getProtocol(), pv.getMajor(), pv.getMinor(), release);
	}
}
 
开发者ID:apigee,项目名称:apigee-android-sdk,代码行数:17,代码来源:CachingHttpClient.java

示例4: setKeepAlive

import org.apache.http.HttpMessage; //导入方法依赖的package包/类
/**
 * Sets the value of the {@code "Connection"} header depending on the
 * protocol version of the specified message.  This method sets or removes
 * the {@code "Connection"} header depending on what the default keep alive
 * mode of the message's protocol version is, as specified by
 * {@link HttpVersion#isKeepAliveDefault()}.
 * <ul>
 * <li>If the connection is kept alive by default:
 *     <ul>
 *     <li>set to {@code "close"} if {@code keepAlive} is {@code false}.</li>
 *     <li>remove otherwise.</li>
 *     </ul></li>
 * <li>If the connection is closed by default:
 *     <ul>
 *     <li>set to {@code "keep-alive"} if {@code keepAlive} is {@code true}.</li>
 *     <li>remove otherwise.</li>
 *     </ul></li>
 * </ul>
 */
public static void setKeepAlive(HttpMessage message, boolean keepAlive) {
    final ProtocolVersion version = message.getProtocolVersion();
    if (HttpVersion.valueOf(version.toString()).isKeepAliveDefault()) {
        if (keepAlive) {
            message.removeHeaders(Names.CONNECTION);
        } else {
            message.setHeader(Names.CONNECTION, Values.CLOSE);
        }
    } else {
        if (keepAlive) {
            message.setHeader(Names.CONNECTION, Values.KEEP_ALIVE);
        } else {
            message.removeHeaders(Names.CONNECTION);
        }
    }
}
 
开发者ID:jle,项目名称:andy,代码行数:36,代码来源:HttpHeaders.java


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