Package org.jsoup.helper
Class HttpConnection.Response
- java.lang.Object
-
- org.jsoup.helper.HttpConnection.Base<Connection.Response>
-
- org.jsoup.helper.HttpConnection.Response
-
- All Implemented Interfaces:
Connection.Base<Connection.Response>,Connection.Response
- Enclosing class:
- HttpConnection
public static class HttpConnection.Response extends HttpConnection.Base<Connection.Response> implements Connection.Response
-
-
Field Summary
Fields Modifier and Type Field Description private java.io.InputStreambodyStreamprivate java.nio.ByteBufferbyteDataprivate java.lang.Stringcharsetprivate java.net.HttpURLConnectionconnprivate java.lang.StringcontentTypeprivate booleanexecutedprivate booleaninputStreamReadprivate static java.lang.StringLOCATIONprivate static intMAX_REDIRECTSprivate intnumRedirectsprivate Connection.Requestreqprivate intstatusCodeprivate java.lang.StringstatusMessageprivate static java.util.regex.PatternxmlContentTypeRxp-
Fields inherited from class org.jsoup.helper.HttpConnection.Base
cookies, headers, method, url
-
-
Constructor Summary
Constructors Modifier Constructor Description (package private)Response()privateResponse(HttpConnection.Response previousResponse)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Stringbody()Get the body of the response as a plain string.byte[]bodyAsBytes()Get the body of the response as an array of bytes.java.io.BufferedInputStreambodyStream()Get the body of the response as a (buffered) InputStream.Connection.ResponsebufferUp()Read the body of the response into a local buffer, so thatConnection.Response.parse()may be called repeatedly on the same connection response (otherwise, once the response is read, its InputStream will have been drained and may not be re-read).java.lang.Stringcharset()Get the character set name of the response, derived from the content-type header.HttpConnection.Responsecharset(java.lang.String charset)Set / override the response character set.java.lang.StringcontentType()Get the response content type (e.g.private static java.net.HttpURLConnectioncreateConnection(Connection.Request req)private static java.util.LinkedHashMap<java.lang.String,java.util.List<java.lang.String>>createHeaderMap(java.net.HttpURLConnection conn)(package private) static HttpConnection.Responseexecute(Connection.Request req)(package private) static HttpConnection.Responseexecute(Connection.Request req, HttpConnection.Response previousResponse)private static java.lang.StringgetRequestCookieString(Connection.Request req)Documentparse()Read and parse the body of the response as a Document.private voidprepareByteData()(package private) voidprocessResponseHeaders(java.util.Map<java.lang.String,java.util.List<java.lang.String>> resHeaders)private voidsafeClose()Call on completion of stream read, to close the body (or error) stream.private static voidserialiseRequestUrl(Connection.Request req)private static java.lang.StringsetOutputContentType(Connection.Request req)private voidsetupFromConnection(java.net.HttpURLConnection conn, HttpConnection.Response previousResponse)intstatusCode()Get the status code of the response.java.lang.StringstatusMessage()Get the status message of the response.private static voidwritePost(Connection.Request req, java.io.OutputStream outputStream, java.lang.String bound)-
Methods inherited from class org.jsoup.helper.HttpConnection.Base
addHeader, cookie, cookie, cookies, hasCookie, hasHeader, hasHeaderWithValue, header, header, headers, headers, method, method, multiHeaders, removeCookie, removeHeader, url, url
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jsoup.Connection.Base
addHeader, cookie, cookie, cookies, hasCookie, hasHeader, hasHeaderWithValue, header, header, headers, headers, method, method, multiHeaders, removeCookie, removeHeader, url, url
-
-
-
-
Field Detail
-
MAX_REDIRECTS
private static final int MAX_REDIRECTS
- See Also:
- Constant Field Values
-
LOCATION
private static final java.lang.String LOCATION
- See Also:
- Constant Field Values
-
statusCode
private int statusCode
-
statusMessage
private java.lang.String statusMessage
-
byteData
private java.nio.ByteBuffer byteData
-
bodyStream
private java.io.InputStream bodyStream
-
conn
private java.net.HttpURLConnection conn
-
charset
private java.lang.String charset
-
contentType
private java.lang.String contentType
-
executed
private boolean executed
-
inputStreamRead
private boolean inputStreamRead
-
numRedirects
private int numRedirects
-
req
private Connection.Request req
-
xmlContentTypeRxp
private static final java.util.regex.Pattern xmlContentTypeRxp
-
-
Constructor Detail
-
Response
Response()
-
Response
private Response(HttpConnection.Response previousResponse) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
execute
static HttpConnection.Response execute(Connection.Request req) throws java.io.IOException
- Throws:
java.io.IOException
-
execute
static HttpConnection.Response execute(Connection.Request req, HttpConnection.Response previousResponse) throws java.io.IOException
- Throws:
java.io.IOException
-
statusCode
public int statusCode()
Description copied from interface:Connection.ResponseGet the status code of the response.- Specified by:
statusCodein interfaceConnection.Response- Returns:
- status code
-
statusMessage
public java.lang.String statusMessage()
Description copied from interface:Connection.ResponseGet the status message of the response.- Specified by:
statusMessagein interfaceConnection.Response- Returns:
- status message
-
charset
public java.lang.String charset()
Description copied from interface:Connection.ResponseGet the character set name of the response, derived from the content-type header.- Specified by:
charsetin interfaceConnection.Response- Returns:
- character set name
-
charset
public HttpConnection.Response charset(java.lang.String charset)
Description copied from interface:Connection.ResponseSet / override the response character set. When the document body is parsed it will be with this charset.- Specified by:
charsetin interfaceConnection.Response- Parameters:
charset- to decode body as- Returns:
- this Response, for chaining
-
contentType
public java.lang.String contentType()
Description copied from interface:Connection.ResponseGet the response content type (e.g. "text/html");- Specified by:
contentTypein interfaceConnection.Response- Returns:
- the response content type
-
parse
public Document parse() throws java.io.IOException
Description copied from interface:Connection.ResponseRead and parse the body of the response as a Document. If you intend to parse the same response multiple times, you shouldConnection.Response.bufferUp()first.- Specified by:
parsein interfaceConnection.Response- Returns:
- a parsed Document
- Throws:
java.io.IOException- on error
-
prepareByteData
private void prepareByteData()
-
body
public java.lang.String body()
Description copied from interface:Connection.ResponseGet the body of the response as a plain string.- Specified by:
bodyin interfaceConnection.Response- Returns:
- body
-
bodyAsBytes
public byte[] bodyAsBytes()
Description copied from interface:Connection.ResponseGet the body of the response as an array of bytes.- Specified by:
bodyAsBytesin interfaceConnection.Response- Returns:
- body bytes
-
bufferUp
public Connection.Response bufferUp()
Description copied from interface:Connection.ResponseRead the body of the response into a local buffer, so thatConnection.Response.parse()may be called repeatedly on the same connection response (otherwise, once the response is read, its InputStream will have been drained and may not be re-read). CallingConnection.Response.body()orConnection.Response.bodyAsBytes()has the same effect.- Specified by:
bufferUpin interfaceConnection.Response- Returns:
- this response, for chaining
-
bodyStream
public java.io.BufferedInputStream bodyStream()
Description copied from interface:Connection.ResponseGet 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 not work in conjunction with this method.This method is useful for writing large responses to disk, without buffering them completely into memory first.
- Specified by:
bodyStreamin interfaceConnection.Response- Returns:
- the response body input stream
-
createConnection
private static java.net.HttpURLConnection createConnection(Connection.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).
-
setupFromConnection
private void setupFromConnection(java.net.HttpURLConnection conn, HttpConnection.Response previousResponse) throws java.io.IOException- Throws:
java.io.IOException
-
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)
-
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 bound) throws java.io.IOException
- Throws:
java.io.IOException
-
getRequestCookieString
private static java.lang.String getRequestCookieString(Connection.Request req)
-
serialiseRequestUrl
private static void serialiseRequestUrl(Connection.Request req) throws java.io.IOException
- Throws:
java.io.IOException
-
-