Class NetHttpResponse
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final class
A wrapper arround the baseInputStream
that validates EOF returned by the read calls. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final HttpURLConnection
private final int
private final String
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Closes the connection to the HTTP server.Returns the HTTP response content input stream ornull
for none.Returns the content encoding (for example"gzip"
) ornull
for none.long
Returns the content length or0
for none.Returns the content type ornull
for none.int
Returns the number of HTTP response headers.getHeaderName
(int index) Returns the HTTP response header name at the given zero-based index.getHeaderValue
(int index) Returns the HTTP response header value at the given zero-based index.Returns the HTTP reason phrase ornull
for none.int
Returns the response status code or<=0
for none.Returns the response status line ornull
for none.
-
Field Details
-
connection
-
responseCode
private final int responseCode -
responseMessage
-
headerNames
-
headerValues
-
-
Constructor Details
-
NetHttpResponse
NetHttpResponse(HttpURLConnection connection) throws IOException - Throws:
IOException
-
-
Method Details
-
getStatusCode
public int getStatusCode()Description copied from class:LowLevelHttpResponse
Returns the response status code or<=0
for none.- Specified by:
getStatusCode
in classLowLevelHttpResponse
-
getContent
Returns the HTTP response content input stream ornull
for none.Returns
URLConnection.getInputStream()
when it doesn't throwIOException
, otherwise it returnsHttpURLConnection.getErrorStream()
.Upgrade warning: in prior version 1.16
getContent()
returnedURLConnection.getInputStream()
only when the status code was successful. Starting with version 1.17 it returnsURLConnection.getInputStream()
when it doesn't throwIOException
, otherwise it returnsHttpURLConnection.getErrorStream()
Upgrade warning: in versions prior to 1.20
getContent()
returnedURLConnection.getInputStream()
orHttpURLConnection.getErrorStream()
, both of which silently returned -1 for read() calls when the connection got closed in the middle of receiving a response. This is highly likely a bug from JDK'sHttpURLConnection
. Since version 1.20, the bytes read off the wire will be checked and anIOException
will be thrown if the response is not fully delivered when the connection is closed by server for whatever reason, e.g., server restarts. Note though that this is a best-effort check: when the response is chunk encoded, we have to rely on the underlying HTTP library to behave correctly.- Specified by:
getContent
in classLowLevelHttpResponse
- Throws:
IOException
- I/O exception
-
getContentEncoding
Description copied from class:LowLevelHttpResponse
Returns the content encoding (for example"gzip"
) ornull
for none.- Specified by:
getContentEncoding
in classLowLevelHttpResponse
-
getContentLength
public long getContentLength()Description copied from class:LowLevelHttpResponse
Returns the content length or0
for none.- Specified by:
getContentLength
in classLowLevelHttpResponse
-
getContentType
Description copied from class:LowLevelHttpResponse
Returns the content type ornull
for none.- Specified by:
getContentType
in classLowLevelHttpResponse
-
getReasonPhrase
Description copied from class:LowLevelHttpResponse
Returns the HTTP reason phrase ornull
for none.- Specified by:
getReasonPhrase
in classLowLevelHttpResponse
-
getStatusLine
Description copied from class:LowLevelHttpResponse
Returns the response status line ornull
for none.- Specified by:
getStatusLine
in classLowLevelHttpResponse
-
getHeaderCount
public int getHeaderCount()Description copied from class:LowLevelHttpResponse
Returns the number of HTTP response headers.Note that multiple headers of the same name need to be supported, in which case each header value is treated as a separate header.
- Specified by:
getHeaderCount
in classLowLevelHttpResponse
-
getHeaderName
Description copied from class:LowLevelHttpResponse
Returns the HTTP response header name at the given zero-based index.- Specified by:
getHeaderName
in classLowLevelHttpResponse
-
getHeaderValue
Description copied from class:LowLevelHttpResponse
Returns the HTTP response header value at the given zero-based index.- Specified by:
getHeaderValue
in classLowLevelHttpResponse
-
disconnect
public void disconnect()Closes the connection to the HTTP server.- Overrides:
disconnect
in classLowLevelHttpResponse
- Since:
- 1.4
-