Package net.lenni0451.commons.httpclient
Class HttpResponse
- java.lang.Object
-
- net.lenni0451.commons.httpclient.HeaderStore<HttpResponse>
-
- net.lenni0451.commons.httpclient.HttpResponse
-
public class HttpResponse extends HeaderStore<HttpResponse>
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceHttpResponse.DecoderProviderA provider for decoders based on the encoding name.static interfaceHttpResponse.InputStreamMapperA function that maps an input stream to another input stream, e.g., for decompression.
-
Constructor Summary
Constructors Constructor Description HttpResponse(java.net.URL url, int statusCode, byte[] content, java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers)HttpResponse(java.net.URL url, int statusCode, java.io.InputStream inputStream, java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers)HttpResponse(java.net.URL url, int statusCode, HttpContent content, java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description HttpContentgetContent()java.lang.StringgetContentAsString()Deprecated.java.lang.StringgetContentAsString(java.nio.charset.Charset charset)Deprecated.java.util.Optional<ContentType>getContentType()Deprecated.HttpContentgetDecodedContent()Get the decoded content of the response.
Supported encodings are: identify (no encoding) gzip (also x-gzip) deflate Library support for the following encodings is also included, if the respective library is available on the classpath: brotli com.aayushatharva.brotli4j:brotli4j org.brotli:dec zstd io.airlift:aircompressor io.airlift:aircompressor-v3 com.github.luben:zstd-jniHttpContentgetDecodedContent(HttpResponse.DecoderProvider decoderProvider)Get the decoded content of the response.
Closing the returned content will also close the original content.
If the content is not encoded, or uses an unsupported encoding, the original content will be returned.
TheHttpHeaders.CONTENT_ENCODINGheader is renamed toOriginal-Content-Encodingif the content has been decoded.java.io.InputStreamgetInputStream()Deprecated.intgetStatusCode()java.lang.StringgetStatusMessage()java.net.URLgetURL()-
Methods inherited from class net.lenni0451.commons.httpclient.HeaderStore
appendHeader, appendHeader, appendHeader, clearHeaders, forEachHeader, getFirstHeader, getHeader, getHeaders, getLastHeader, hasHeader, hasHeader, hasHeader, removeHeader, setHeader, setHeader, setHeader
-
-
-
-
Constructor Detail
-
HttpResponse
public HttpResponse(java.net.URL url, int statusCode, byte[] content, java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers)
-
HttpResponse
public HttpResponse(java.net.URL url, int statusCode, java.io.InputStream inputStream, java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers)
-
HttpResponse
public HttpResponse(java.net.URL url, int statusCode, HttpContent content, java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers)
-
-
Method Detail
-
getURL
public java.net.URL getURL()
- Returns:
- The request url
-
getStatusCode
public int getStatusCode()
- Returns:
- The status code of the response
-
getStatusMessage
public java.lang.String getStatusMessage()
- Returns:
- The message of the status code
-
getContent
public HttpContent getContent()
- Returns:
- The content of the response
-
getDecodedContent
public HttpContent getDecodedContent()
Get the decoded content of the response.
Supported encodings are:- identify (no encoding)
- gzip (also x-gzip)
- deflate
- brotli
- com.aayushatharva.brotli4j:brotli4j
- org.brotli:dec
- zstd
- io.airlift:aircompressor
- io.airlift:aircompressor-v3
- com.github.luben:zstd-jni
- Returns:
- The decoded content
- See Also:
getDecodedContent(DecoderProvider)
-
getDecodedContent
public HttpContent getDecodedContent(HttpResponse.DecoderProvider decoderProvider)
Get the decoded content of the response.
Closing the returned content will also close the original content.
If the content is not encoded, or uses an unsupported encoding, the original content will be returned.
TheHttpHeaders.CONTENT_ENCODINGheader is renamed toOriginal-Content-Encodingif the content has been decoded.- Parameters:
decoderProvider- The provider for content decoders- Returns:
- The decoded content
-
getInputStream
@Deprecated @ScheduledForRemoval public java.io.InputStream getInputStream()
Deprecated.UsegetContent()andHttpContent.getAsStream()instead.
-
getContentAsString
@Deprecated @ScheduledForRemoval public java.lang.String getContentAsString()
Deprecated.UsegetContent()andHttpContent.getAsString()instead.
-
getContentAsString
@Deprecated @ScheduledForRemoval public java.lang.String getContentAsString(java.nio.charset.Charset charset)
Deprecated.UsegetContent()andHttpContent.getAsString(Charset)instead.
-
getContentType
@Deprecated @ScheduledForRemoval public java.util.Optional<ContentType> getContentType()
Deprecated.UsegetContent()andHttpContent.getType()instead.
-
-