本文整理汇总了Java中org.apache.http.HttpMessage.getHeaders方法的典型用法代码示例。如果您正苦于以下问题:Java HttpMessage.getHeaders方法的具体用法?Java HttpMessage.getHeaders怎么用?Java HttpMessage.getHeaders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.HttpMessage
的用法示例。
在下文中一共展示了HttpMessage.getHeaders方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: recordCookie
import org.apache.http.HttpMessage; //导入方法依赖的package包/类
protected void recordCookie(HttpMessage httpMessage, Trace trace) {
org.apache.http.Header[] cookies = httpMessage.getHeaders("Cookie");
for (org.apache.http.Header header : cookies) {
final String value = header.getValue();
if (StringUtils.hasLength(value)) {
if (cookieSampler.isSampling()) {
final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
recorder.recordAttribute(AnnotationKey.HTTP_COOKIE, StringUtils.abbreviate(value, 1024));
}
// Can a cookie have 2 or more values?
// PMD complains if we use break here
return;
}
}
}
示例2: has
import org.apache.http.HttpMessage; //导入方法依赖的package包/类
protected boolean has(final String headerName, final String headerValueOrElement, final HttpMessage message) {
Header[] headers = message.getHeaders(headerName);
for (Header header : headers) {
if (header.getValue().equals(headerValueOrElement))
return true;
HeaderElement[] elements = header.getElements();
for (HeaderElement element : elements)
if (element.getName().equals(headerValueOrElement))
return true;
}
return false;
}
示例3: hasCacheControlParameterFrom
import org.apache.http.HttpMessage; //导入方法依赖的package包/类
protected boolean hasCacheControlParameterFrom(final HttpMessage msg, final String[] params) {
final Header[] cacheControlHeaders = msg.getHeaders(HeaderConstants.CACHE_CONTROL);
for (final Header header : cacheControlHeaders) {
for (final HeaderElement elem : header.getElements()) {
for (final String param : params) {
if (param.equalsIgnoreCase(elem.getName())) {
return true;
}
}
}
}
return false;
}
示例4: recordCookie
import org.apache.http.HttpMessage; //导入方法依赖的package包/类
protected void recordCookie(HttpMessage httpMessage, SpanEventRecorder recorder) {
org.apache.http.Header[] cookies = httpMessage.getHeaders("Cookie");
for (org.apache.http.Header header : cookies) {
final String value = header.getValue();
if (value != null && !value.isEmpty()) {
if (cookieSampler.isSampling()) {
recorder.recordAttribute(AnnotationKey.HTTP_COOKIE, StringUtils.abbreviate(value, 1024));
}
// Can a cookie have 2 or more values?
// PMD complains if we use break here
return;
}
}
}
示例5: hasCacheControlParameterFrom
import org.apache.http.HttpMessage; //导入方法依赖的package包/类
protected boolean hasCacheControlParameterFrom(HttpMessage msg,
String[] params) {
Header[] cacheControlHeaders = msg
.getHeaders(HeaderConstants.CACHE_CONTROL);
for (Header header : cacheControlHeaders) {
for (HeaderElement elem : header.getElements()) {
for (String param : params) {
if (param.equalsIgnoreCase(elem.getName())) {
return true;
}
}
}
}
return false;
}
示例6: determineLength
import org.apache.http.HttpMessage; //导入方法依赖的package包/类
public long determineLength(final HttpMessage message) throws HttpException {
if (message == null) {
throw new IllegalArgumentException("HTTP message may not be null");
}
HttpParams params = message.getParams();
boolean strict = params.isParameterTrue(CoreProtocolPNames.STRICT_TRANSFER_ENCODING);
Header transferEncodingHeader = message.getFirstHeader(HTTP.TRANSFER_ENCODING);
// We use Transfer-Encoding if present and ignore Content-Length.
// RFC2616, 4.4 item number 3
if (transferEncodingHeader != null) {
HeaderElement[] encodings = null;
try {
encodings = transferEncodingHeader.getElements();
} catch (ParseException px) {
throw new ProtocolException
("Invalid Transfer-Encoding header value: " +
transferEncodingHeader, px);
}
if (strict) {
// Currently only chunk and identity are supported
for (int i = 0; i < encodings.length; i++) {
String encoding = encodings[i].getName();
if (encoding != null && encoding.length() > 0
&& !encoding.equalsIgnoreCase(HTTP.CHUNK_CODING)
&& !encoding.equalsIgnoreCase(HTTP.IDENTITY_CODING)) {
throw new ProtocolException("Unsupported transfer encoding: " + encoding);
}
}
}
// The chunked encoding must be the last one applied RFC2616, 14.41
int len = encodings.length;
if (HTTP.IDENTITY_CODING.equalsIgnoreCase(transferEncodingHeader.getValue())) {
return IDENTITY;
} else if ((len > 0) && (HTTP.CHUNK_CODING.equalsIgnoreCase(
encodings[len - 1].getName()))) {
return CHUNKED;
} else {
if (strict) {
throw new ProtocolException("Chunk-encoding must be the last one applied");
}
return IDENTITY;
}
}
Header contentLengthHeader = message.getFirstHeader(HTTP.CONTENT_LEN);
if (contentLengthHeader != null) {
long contentlen = -1;
Header[] headers = message.getHeaders(HTTP.CONTENT_LEN);
if (strict && headers.length > 1) {
throw new ProtocolException("Multiple content length headers");
}
for (int i = headers.length - 1; i >= 0; i--) {
Header header = headers[i];
try {
contentlen = Long.parseLong(header.getValue());
break;
} catch (NumberFormatException e) {
if (strict) {
throw new ProtocolException("Invalid content length: " + header.getValue());
}
}
// See if we can have better luck with another header, if present
}
if (contentlen >= 0) {
return contentlen;
} else {
return IDENTITY;
}
}
return this.implicitLen;
}
示例7: determineLength
import org.apache.http.HttpMessage; //导入方法依赖的package包/类
public long determineLength(final HttpMessage message) throws HttpException {
Args.notNull(message, "HTTP message");
final Header transferEncodingHeader = message.getFirstHeader(HTTP.TRANSFER_ENCODING);
// We use Transfer-Encoding if present and ignore Content-Length.
// RFC2616, 4.4 item number 3
if (transferEncodingHeader != null) {
final HeaderElement[] encodings;
try {
encodings = transferEncodingHeader.getElements();
} catch (final ParseException px) {
throw new ProtocolException
("Invalid Transfer-Encoding header value: " +
transferEncodingHeader, px);
}
// The chunked encoding must be the last one applied RFC2616, 14.41
final int len = encodings.length;
if (HTTP.IDENTITY_CODING.equalsIgnoreCase(transferEncodingHeader.getValue())) {
return IDENTITY;
} else if ((len > 0) && (HTTP.CHUNK_CODING.equalsIgnoreCase(
encodings[len - 1].getName()))) {
return CHUNKED;
} else {
return IDENTITY;
}
}
final Header contentLengthHeader = message.getFirstHeader(HTTP.CONTENT_LEN);
if (contentLengthHeader != null) {
long contentlen = -1;
final Header[] headers = message.getHeaders(HTTP.CONTENT_LEN);
for (int i = headers.length - 1; i >= 0; i--) {
final Header header = headers[i];
try {
contentlen = Long.parseLong(header.getValue());
break;
} catch (final NumberFormatException ignore) {
}
// See if we can have better luck with another header, if present
}
if (contentlen >= 0) {
return contentlen;
} else {
return IDENTITY;
}
}
return this.implicitLen;
}