Class HttpConnection.Response

    • Field Detail

      • statusCode

        private final int statusCode
      • statusMessage

        private final java.lang.String statusMessage
      • byteData

        private java.nio.ByteBuffer byteData
      • conn

        private java.net.HttpURLConnection conn
      • charset

        private java.lang.String charset
      • contentType

        private final java.lang.String contentType
      • executed

        private boolean executed
      • inputStreamRead

        private boolean inputStreamRead
      • numRedirects

        private int numRedirects
      • xmlContentTypeRxp

        private static final java.util.regex.Pattern xmlContentTypeRxp
    • Constructor Detail

      • Response

        Response()
        Internal only! Creates a dummy HttpConnection.Response, useful for testing. All actual responses are created from the HttpURLConnection and fields defined.
    • Method Detail

      • charset

        public java.lang.String charset()
        Description copied from interface: Connection.Response
        Get the character set name of the response, derived from the content-type header.
        Specified by:
        charset in interface Connection.Response
        Returns:
        character set name if set, null if not
      • charset

        public HttpConnection.Response charset​(java.lang.String charset)
        Description copied from interface: Connection.Response
        Set / override the response character set. When the document body is parsed it will be with this charset.
        Specified by:
        charset in interface Connection.Response
        Parameters:
        charset - to decode body as
        Returns:
        this Response, for chaining
      • contentType

        public java.lang.String contentType()
        Description copied from interface: Connection.Response
        Get the response content type (e.g. "text/html");
        Specified by:
        contentType in interface Connection.Response
        Returns:
        the response content type, or null if one was not set
      • prepareParse

        private java.io.InputStream prepareParse()
        Called from parse() or streamParser(), validates and prepares the input stream, and aligns common settings.
      • streamParser

        public StreamParser streamParser()
                                  throws java.io.IOException
        Description copied from interface: Connection.Response
        Returns a StreamParser that will parse the Response progressively.
        Specified by:
        streamParser in interface Connection.Response
        Returns:
        a StreamParser, prepared to parse this response.
        Throws:
        java.io.IOException - if an IO exception occurs preparing the parser.
      • prepareByteData

        private void prepareByteData()
      • body

        public java.lang.String body()
        Description copied from interface: Connection.Response
        Get the body of the response as a plain string.
        Specified by:
        body in interface Connection.Response
        Returns:
        body
      • bodyStream

        public java.io.BufferedInputStream bodyStream()
        Description copied from interface: Connection.Response
        Get the body of the response as a (buffered) InputStream. You should close the input stream when you're done with it.

        Other body methods (like bufferUp, body, parse, etc) will generally not work in conjunction with this method, as it consumes the InputStream.

        Any configured max size or maximum read timeout applied to the connection will not be applied to this stream, unless Connection.Response.bufferUp() is called prior.

        This method is useful for writing large responses to disk, without buffering them completely into memory first.

        Specified by:
        bodyStream in interface Connection.Response
        Returns:
        the response body input stream
      • createConnection

        private static java.net.HttpURLConnection createConnection​(HttpConnection.Request req)
                                                            throws java.io.IOException
        Throws:
        java.io.IOException
      • safeClose

        private void safeClose()
        Call on completion of stream read, to close the body (or error) stream. The connection.disconnect allows keep-alives to work (as the underlying connection is actually held open, despite the name).
      • createHeaderMap

        private static java.util.LinkedHashMap<java.lang.String,​java.util.List<java.lang.String>> createHeaderMap​(java.net.HttpURLConnection conn)
      • processResponseHeaders

        void processResponseHeaders​(java.util.Map<java.lang.String,​java.util.List<java.lang.String>> resHeaders)
      • fixHeaderEncoding

        private static java.lang.String fixHeaderEncoding​(java.lang.String val)
        Servers may encode response headers in UTF-8 instead of RFC defined 8859. This method attempts to detect that and re-decode the string as UTF-8.
        Parameters:
        val - a header value string that may have been incorrectly decoded as 8859.
        Returns:
        a potentially re-decoded string.
      • looksLikeUtf8

        private static boolean looksLikeUtf8​(byte[] input)
      • setOutputContentType

        private static java.lang.String setOutputContentType​(Connection.Request req)
      • writePost

        private static void writePost​(Connection.Request req,
                                      java.io.OutputStream outputStream,
                                      java.lang.String boundary)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • serialiseRequestUrl

        private static void serialiseRequestUrl​(Connection.Request req)
                                         throws java.io.IOException
        Throws:
        java.io.IOException