Class NetHttpResponse
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final classA wrapper arround the baseInputStreamthat validates EOF returned by the read calls. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final HttpURLConnectionprivate final intprivate final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidCloses the connection to the HTTP server.Returns the HTTP response content input stream ornullfor none.Returns the content encoding (for example"gzip") ornullfor none.longReturns the content length or0for none.Returns the content type ornullfor none.intReturns 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 ornullfor none.intReturns the response status code or<=0for none.Returns the response status line ornullfor 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:LowLevelHttpResponseReturns the response status code or<=0for none.- Specified by:
getStatusCodein classLowLevelHttpResponse
-
getContent
Returns the HTTP response content input stream ornullfor 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 anIOExceptionwill 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:
getContentin classLowLevelHttpResponse- Throws:
IOException- I/O exception
-
getContentEncoding
Description copied from class:LowLevelHttpResponseReturns the content encoding (for example"gzip") ornullfor none.- Specified by:
getContentEncodingin classLowLevelHttpResponse
-
getContentLength
public long getContentLength()Description copied from class:LowLevelHttpResponseReturns the content length or0for none.- Specified by:
getContentLengthin classLowLevelHttpResponse
-
getContentType
Description copied from class:LowLevelHttpResponseReturns the content type ornullfor none.- Specified by:
getContentTypein classLowLevelHttpResponse
-
getReasonPhrase
Description copied from class:LowLevelHttpResponseReturns the HTTP reason phrase ornullfor none.- Specified by:
getReasonPhrasein classLowLevelHttpResponse
-
getStatusLine
Description copied from class:LowLevelHttpResponseReturns the response status line ornullfor none.- Specified by:
getStatusLinein classLowLevelHttpResponse
-
getHeaderCount
public int getHeaderCount()Description copied from class:LowLevelHttpResponseReturns 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:
getHeaderCountin classLowLevelHttpResponse
-
getHeaderName
Description copied from class:LowLevelHttpResponseReturns the HTTP response header name at the given zero-based index.- Specified by:
getHeaderNamein classLowLevelHttpResponse
-
getHeaderValue
Description copied from class:LowLevelHttpResponseReturns the HTTP response header value at the given zero-based index.- Specified by:
getHeaderValuein classLowLevelHttpResponse
-
disconnect
public void disconnect()Closes the connection to the HTTP server.- Overrides:
disconnectin classLowLevelHttpResponse- Since:
- 1.4
-