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 class
HttpComponentsHttpResponse.HttpResponseHeaderMap
A wrapper class exposing headers inHttpResponse.headers()
format by delegating to anHttpResponse
. -
Field Summary
Fields Modifier and Type Field Description protected FastByteArrayOutputStream
cachedContent
A cache for the content of the entity returned byhttpResponse
.protected boolean
contentReady
Whether the content of the entity returned byhttpResponse
has been cached incachedContent
.protected HttpComponentsHttpResponse.HttpResponseHeaderMap
headerMap
The header map wrappinghttpResponse
's headers.protected org.apache.http.HttpResponse
httpResponse
The response wrapped by thisHttpComponentsHttpResponse
.protected URI
url
The URL associated withhttpResponse
.Fields inherited from class it.unimi.dsi.law.warc.util.AbstractHttpResponse
random
Fields 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 void
clear()
Clears thisHttpComponentsHttpResponse
, in particular trimming the content cache.void
consume()
InvokesEntityUtils.consume(HttpEntity)
on the entity returned by the underlying Apache HTTP ComponentsHttpResponse
.MeasurableInputStream
contentAsStream()
Returns the content of this response as a stream.boolean
fromWarcRecord(WarcRecord record)
Fills this response with the content of aWarcRecord
(optional operation).Map<String,String>
headers()
Returns the headers of this response.void
set(URI url, org.apache.http.HttpResponse httpResponse)
Sets the response wrapped by this instance.int
status()
Returns the response status.org.apache.http.StatusLine
statusLine()
Returns the response status line.URI
uri()
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 byhttpResponse
has 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:HttpResponse
Returns the response status.- Returns:
- the status of this response.
-
statusLine
public org.apache.http.StatusLine statusLine()Description copied from interface:HttpResponse
Returns the response status line.- Returns:
- the status line of this response.
-
headers
Description copied from interface:HttpResponse
Returns 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
HttpHeaders
orHttpHeaders
to avoid typing and casing mistakes.- Returns:
- the headers of this response.
-
contentAsStream
Description copied from interface:HttpResponse
Returns the content of this response as a stream.- Returns:
- the content of this response as a stream.
- Throws:
IOException
-
uri
Description copied from interface:Response
Returns the URI associated with this response.- Returns:
- the URI associated with this response.
-
fromWarcRecord
Description copied from interface:Response
Fills this response with the content of aWarcRecord
(optional operation).- Parameters:
record
- the record.- Returns:
- true iff the
record-type
of the given record isresponse
. - Throws:
IOException
-
clear
public void clear()Clears thisHttpComponentsHttpResponse
, in particular trimming the content cache.
-