Class Response
java.lang.Object
org.schabi.newpipe.extractor.downloader.Response
A Data class used to hold the results from requests made by the Downloader implementation.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionEnsure the response code is 3xxensureResponseCodeInRange(int min, int max) Ensure the HTTP response code is within range of min and max inclusiveEnsure the response code is not 4xx or 5xxensureResponseCodeNotInRange(int min, int max) ensureResponseCodeNotInRange(int min, int max, Function<Response, HttpResponseException> errorSupplier) Ensure the response code is 2xxFor easy access to some header value that (usually) don't repeat itself.Used for detecting a possible redirection, limited to the latest one.intThrow exception if response code is a 4xx client errorthrowIfClientError(Function<Response, HttpResponseException> errorSupplier) Throw exception if response code is a 4xx client errorthrowIfResponseCode(int errorCode) throwIfResponseCode(int errorCode, Function<Response, HttpResponseException> errorSupplier) throwIfResponseCodeInRange(int min, int max) throwIfResponseCodeInRange(int min, int max, Function<Response, HttpResponseException> errorSupplier) Throw exception if response code is a 5xx server errorthrowIfServerError(Function<Response, HttpResponseException> errorSupplier) Throw exception if response code is a 5xx server error
-
Constructor Details
-
Response
-
-
Method Details
-
responseCode
public int responseCode() -
responseMessage
-
responseHeaders
-
responseBody
-
latestUrl
Used for detecting a possible redirection, limited to the latest one.- Returns:
- latest url known right before this response object was created
-
getHeader
For easy access to some header value that (usually) don't repeat itself.For getting all the values associated to the header, use
responseHeaders()(e.g.Set-Cookie).- Parameters:
name- the name of the header- Returns:
- the first value assigned to this header
-
ensureSuccessResponseCode
Ensure the response code is 2xx- Returns:
- this
Response - Throws:
HttpResponseException- if the response code is not 2xx
-
ensureRedirectResponseCode
Ensure the response code is 3xx- Returns:
- this
Response - Throws:
HttpResponseException- if the response code is not 3xx
-
ensureResponseCodeIsNotError
Ensure the response code is not 4xx or 5xx- Returns:
- this
Response - Throws:
HttpResponseException- if the response code is client or server error
-
ensureResponseCodeInRange
Ensure the HTTP response code is within range of min and max inclusive- Returns:
- this Response
- Throws:
HttpResponseException- if the code is outside the range
-
ensureResponseCodeNotInRange
public Response ensureResponseCodeNotInRange(int min, int max, Function<Response, HttpResponseException> errorSupplier) throws HttpResponseException- Throws:
HttpResponseException
-
ensureResponseCodeNotInRange
- Throws:
HttpResponseException
-
throwIfClientError
public Response throwIfClientError(Function<Response, HttpResponseException> errorSupplier) throws HttpResponseExceptionThrow exception if response code is a 4xx client error- Returns:
- this
Response - Throws:
HttpResponseException- if the response code is 4xx
-
throwIfClientError
Throw exception if response code is a 4xx client error- Returns:
- this
Response - Throws:
HttpResponseException- if the response code is 4xx
-
throwIfServerError
public Response throwIfServerError(Function<Response, HttpResponseException> errorSupplier) throws HttpResponseExceptionThrow exception if response code is a 5xx server error- Returns:
- this
Response - Throws:
HttpResponseException- if the response code is 5xx
-
throwIfServerError
Throw exception if response code is a 5xx server error- Returns:
- this
Response - Throws:
HttpResponseException- if the response code is 5xx
-
throwIfResponseCode
public Response throwIfResponseCode(int errorCode, Function<Response, HttpResponseException> errorSupplier) throws HttpResponseException- Throws:
HttpResponseException
-
throwIfResponseCode
- Throws:
HttpResponseException
-
throwIfResponseCodeInRange
public Response throwIfResponseCodeInRange(int min, int max, Function<Response, HttpResponseException> errorSupplier) throws HttpResponseException- Throws:
HttpResponseException
-
throwIfResponseCodeInRange
- Throws:
HttpResponseException
-