Class HttpComponentsHttpResponse
- All Implemented Interfaces:
HttpResponse,Response
public class HttpComponentsHttpResponse extends AbstractHttpResponse
AbstractHttpResponse that implements
missing methods by wrapping an Apache HTTP Components HttpResponse.
A typical use case of this class is storing in a WarcRecord the
content of an Apache HTTP Components HttpResponse. The nested
class HttpComponentsHttpResponse.HttpResponseHeaderMap can be used in other classes to expose
as a standard Java map the header-related methods of an Apache HTTP Components HttpResponse.
To be able to return a MeasurableInputStream, this class caches the
result of the underlying Apache HTTP Components HttpResponse. The cache
is never shrunk, but clear() will trim it to length zero. You can override
contentAsStream() to provide different ways of perform the caching.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHttpComponentsHttpResponse.HttpResponseHeaderMapA wrapper class exposing headers inHttpResponse.headers()format by delegating to anHttpResponse. -
Field Summary
Fields Modifier and Type Field Description protected FastByteArrayOutputStreamcachedContentA cache for the content of the entity returned byhttpResponse.protected booleancontentReadyWhether the content of the entity returned byhttpResponsehas been cached incachedContent.protected HttpComponentsHttpResponse.HttpResponseHeaderMapheaderMapThe header map wrappinghttpResponse's headers.protected org.apache.http.HttpResponsehttpResponseThe response wrapped by thisHttpComponentsHttpResponse.protected URIurlThe URL associated withhttpResponse.Fields inherited from class it.unimi.dsi.law.warc.util.AbstractHttpResponse
randomFields inherited from interface it.unimi.dsi.law.warc.util.HttpResponse
DIGEST_HEADER, GUESSED_CHARSET_HEADER, HEADER_CHARSET, ISDUPLICATE_HEADER -
Constructor Summary
Constructors Constructor Description HttpComponentsHttpResponse()Creates a new instance.HttpComponentsHttpResponse(URI url, org.apache.http.HttpResponse httpResponse)Creates a new instance wrapping a given Apache HTTP ComponentsHttpResponse. -
Method Summary
Modifier and Type Method Description voidclear()Clears thisHttpComponentsHttpResponse, in particular trimming the content cache.voidconsume()InvokesEntityUtils.consume(HttpEntity)on the entity returned by the underlying Apache HTTP ComponentsHttpResponse.MeasurableInputStreamcontentAsStream()Returns the content of this response as a stream.booleanfromWarcRecord(WarcRecord record)Fills this response with the content of aWarcRecord(optional operation).Map<String,String>headers()Returns the headers of this response.voidset(URI url, org.apache.http.HttpResponse httpResponse)Sets the response wrapped by this instance.intstatus()Returns the response status.org.apache.http.StatusLinestatusLine()Returns the response status line.URIuri()Returns the URI associated with this response.Methods inherited from class it.unimi.dsi.law.warc.util.AbstractHttpResponse
toWarcRecord
-
Field Details
-
url
The URL associated withhttpResponse. -
httpResponse
protected org.apache.http.HttpResponse httpResponseThe response wrapped by thisHttpComponentsHttpResponse. -
headerMap
The header map wrappinghttpResponse's headers. -
cachedContent
A cache for the content of the entity returned byhttpResponse. -
contentReady
protected boolean contentReadyWhether the content of the entity returned byhttpResponsehas been cached incachedContent.
-
-
Constructor Details
-
HttpComponentsHttpResponse
public HttpComponentsHttpResponse()Creates a new instance.Use
set(URI, HttpResponse)to wrap an Apache HTTP ComponentsHttpResponse. -
HttpComponentsHttpResponse
Creates a new instance wrapping a given Apache HTTP ComponentsHttpResponse.- Parameters:
url- the URL forhttpResponse.httpResponse- the response to be wrapped.
-
-
Method Details
-
set
Sets the response wrapped by this instance.- Parameters:
url- the URL forhttpResponse.httpResponse- the response to be wrapped.
-
consume
InvokesEntityUtils.consume(HttpEntity)on the entity returned by the underlying Apache HTTP ComponentsHttpResponse.- Throws:
IOException
-
status
public int status()Description copied from interface:HttpResponseReturns the response status.- Returns:
- the status of this response.
-
statusLine
public org.apache.http.StatusLine statusLine()Description copied from interface:HttpResponseReturns the response status line.- Returns:
- the status line of this response.
-
headers
Description copied from interface:HttpResponseReturns the headers of this response.Warning: as of LAW 3.0, and contrarily to previous behaviour, the map is case-sensitive. Use the predefined names in
HttpHeadersorHttpHeadersto avoid typing and casing mistakes.- Returns:
- the headers of this response.
-
contentAsStream
Description copied from interface:HttpResponseReturns the content of this response as a stream.- Returns:
- the content of this response as a stream.
- Throws:
IOException
-
uri
Description copied from interface:ResponseReturns the URI associated with this response.- Returns:
- the URI associated with this response.
-
fromWarcRecord
Description copied from interface:ResponseFills this response with the content of aWarcRecord(optional operation).- Parameters:
record- the record.- Returns:
- true iff the
record-typeof the given record isresponse. - Throws:
IOException
-
clear
public void clear()Clears thisHttpComponentsHttpResponse, in particular trimming the content cache.
-