类 HTTPResponseContext

  • 所有已实现的接口:
    AutoCloseable

    public class HTTPResponseContext
    extends Object
    implements AutoCloseable
    Raw blocking http response. The http headers already received, the http body not consumed, can be get as InputStream. It you do not consume http response body, with toStringResponse(), toBinaryResponse(), writeTo(Path) etc.., you need to close this raw response manually. This class is not thread-safe.
    作者:
    Liu Dong
    • 方法详细资料

      • charset

        public HTTPResponseContext charset​(Charset charset)
        Set response body read charset. If not set, would get charset from response headers. If not found, would use UTF-8.
        参数:
        charset - the charset used to decode response body. Cannot be null
      • autoDecompress

        public HTTPResponseContext autoDecompress​(boolean autoDecompress)
        If decompress http response body automatically. Default True.
      • handle

        public <T> HTTPResponse<T> handle​(ResponseHandler<T> responseHandler)
        Handle response body with handler, return a new response with content as handler result. ResponseHandler should consume all InputStream data, or connection may close and cannot reuse. The response is closed whether this call succeed or failed with exception.
      • toStringResponse

        public HTTPResponse<String> toStringResponse()
        Convert to response, with body as text. The origin raw response will be closed
      • toBinaryResponse

        public HTTPResponse<byte[]> toBinaryResponse()
        Convert to response, with body as byte array
      • writeTo

        public HTTPResponse<Void> writeTo​(Writer writer)
        Write response body to Writer, charset can be set using charset(Charset), or will use charset detected from response header if not set. Writer will not be closed.
      • discard

        public HTTPResponse<Void> discard()
        Consume and discard this response body.
      • handleAsReader

        public <T> HTTPResponse<T> handleAsReader​(Function<? super Reader,​T> handler)
        Handle response content as reader. The reader passed to handler will be closed when handler finished.
        类型参数:
        T - the response body type to convert to
        参数:
        handler - the handler
      • handleAsInput

        public <T> HTTPResponse<T> handleAsInput​(Function<? super InputStream,​T> handler)
        Handle response content as InputStream. The InputStream passed to handler will be closed when handler finished.
        类型参数:
        T - the response body type to convert to
        参数:
        handler - the handler