Package org.gcube.common.gxhttp.request
Class GXResponse
java.lang.Object
org.gcube.common.gxhttp.request.GXResponse
- All Implemented Interfaces:
AutoCloseable
The response to a
GXRequest: status, headers and body. The body is read in the same way
whatever the status, an error included.
The body is a stream on the connection: read it, or close() the response, to give the
connection back.
- Author:
- Luca Frosini (ISTI-CNR)
-
Method Details
-
getURI
- Returns:
- the URI the response comes from, the last one when the request was redirected
-
getStatus
public int getStatus()- Returns:
- the HTTP status code
-
isSuccessful
public boolean isSuccessful()- Returns:
- whether the status is a success (
2xx)
-
getHeaders
- Returns:
- every header, with case-insensitive names
-
getHeader
- Parameters:
name- the header name, case-insensitive- Returns:
- the first value of the header, or
nullwhen the response does not have it
-
getBody
- Returns:
- the body as a stream
-
getBodyAsString
Reads the whole body as UTF-8 text and closes it.- Returns:
- the body
- Throws:
IOException- if the body cannot be read
-
close
Closes the body, giving the connection back.- Specified by:
closein interfaceAutoCloseable- Throws:
IOException- if the body cannot be closed
-