本文整理匯總了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;
}
示例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);
}
}
示例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);
}
}
}
示例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;
}
}
示例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");
}
}
}