Class NetHttpResponse

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private class  NetHttpResponse.SizeValidatingInputStream
      A wrapper arround the base InputStream that validates EOF returned by the read calls.
    • Constructor Summary

      Constructors 
      Constructor Description
      NetHttpResponse​(java.net.HttpURLConnection connection)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void disconnect()
      Closes the connection to the HTTP server.
      java.io.InputStream getContent()
      Returns the HTTP response content input stream or null for none.
      java.lang.String getContentEncoding()
      Returns the content encoding (for example "gzip") or null for none.
      long getContentLength()
      Returns the content length or 0 for none.
      java.lang.String getContentType()
      Returns the content type or null for none.
      int getHeaderCount()
      Returns the number of HTTP response headers.
      java.lang.String getHeaderName​(int index)
      Returns the HTTP response header name at the given zero-based index.
      java.lang.String getHeaderValue​(int index)
      Returns the HTTP response header value at the given zero-based index.
      java.lang.String getReasonPhrase()
      Returns the HTTP reason phrase or null for none.
      int getStatusCode()
      Returns the response status code or <=0 for none.
      java.lang.String getStatusLine()
      Returns the response status line or null for none.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • connection

        private final java.net.HttpURLConnection connection
      • responseCode

        private final int responseCode
      • responseMessage

        private final java.lang.String responseMessage
      • headerNames

        private final java.util.ArrayList<java.lang.String> headerNames
      • headerValues

        private final java.util.ArrayList<java.lang.String> headerValues
    • Constructor Detail

      • NetHttpResponse

        NetHttpResponse​(java.net.HttpURLConnection connection)
                 throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • getContent

        public java.io.InputStream getContent()
                                       throws java.io.IOException
        Returns the HTTP response content input stream or null for none.

        Returns URLConnection.getInputStream() when it doesn't throw IOException, otherwise it returns HttpURLConnection.getErrorStream().

        Upgrade warning: in prior version 1.16 getContent() returned URLConnection.getInputStream() only when the status code was successful. Starting with version 1.17 it returns URLConnection.getInputStream() when it doesn't throw IOException, otherwise it returns HttpURLConnection.getErrorStream()

        Upgrade warning: in versions prior to 1.20 getContent() returned URLConnection.getInputStream() or HttpURLConnection.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's HttpURLConnection. Since version 1.20, the bytes read off the wire will be checked and an IOException 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 class LowLevelHttpResponse
        Throws:
        java.io.IOException - I/O exception
      • 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 class LowLevelHttpResponse