本文整理汇总了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;
}
示例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;
}
示例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);
}
}
示例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);
}
}
}