Object -
http
:
Response
Represents an HTTP response.
Methods
Entity
associated with the response.
Entity
to the response.
content-type
header to the response.
json
payload from the response.
xml
payload from the response.
text
payload from the response.
ByteChannel
, except in the case of multiparts.
byte[]
.
etag
header for the given payload.
last-modified
header.
json
as the payload.
xml
as the payload
string
as the payload.
byte[]
as the payload.
ByteChannel
as the payload.
Fields
- statusCode int (default 200)
-
The response status code
- reasonPhrase string
-
The status code reason phrase
- server string
-
The server header
- resolvedRequestedURI string
-
The ultimate request URI that was made to receive the response when redirect is on
- cacheControl ResponseCacheControl? (default ())
-
The cache-control directives for the response. This needs to be explicitly initialized if intending on utilizing HTTP caching. For incoming responses, this will already be populated if the response was sent with cache-control directives
Entity
associated with the response.
-
Return Type
(Entity | ClientError) The
Entity
of the response. Anhttp:ClientError
is returned, if entity construction fails
Entity
to the response.
Parameters
- e Entity
-
The
Entity
to be set to the response
Parameters
- headerName string
-
The header name
- position HeaderPosition (default <(leading|trailing)> <leading> leading)
-
Represents the position of the header as an optional parameter
-
Return Type
(boolean) true
if the specified header key exists
Parameters
- headerName string
-
The header name
- position HeaderPosition (default <(leading|trailing)> <leading> leading)
-
Represents the position of the header as an optional parameter. If the position is
mime:TRAILING
, the entity-body of theResponse
must be accessed initially.
-
Return Type
(string) The first header value for the specified header name. Panic if the header is not found. Use the
Response.hasHeader()
beforehand to check the existence of a header.
Parameters
- headerName string
-
The header name
- headerValue string
-
The header value
- position HeaderPosition (default <(leading|trailing)> <leading> leading)
-
Represents the position of the header as an optional parameter. If the position is
mime:TRAILING
, the entity-body of theResponse
must be accessed initially.
Parameters
- headerName string
-
The header name
- position HeaderPosition (default <(leading|trailing)> <leading> leading)
-
Represents the position of the header as an optional parameter. If the position is
mime:TRAILING
, the entity-body of theResponse
must be accessed initially.
-
Return Type
(string[]) The header values the specified header key maps to. Panic if the header is not found. Use the
Response.hasHeader()
beforehand to check the existence of a header.
Parameters
- headerName string
-
The header name
- headerValue string
-
The header value
- position HeaderPosition (default <(leading|trailing)> <leading> leading)
-
Represents the position of the header as an optional parameter. If the position is
mime:TRAILING
, the entity-body of theResponse
must be accessed initially.
Parameters
- key string
-
The header name
- position HeaderPosition (default <(leading|trailing)> <leading> leading)
-
Represents the position of the header as an optional parameter. If the position is
mime:TRAILING
, the entity-body of theResponse
must be accessed initially.
Parameters
- position HeaderPosition (default <(leading|trailing)> <leading> leading)
-
Represents the position of the header as an optional parameter. If the position is
mime:TRAILING
, the entity-body of theResponse
must be accessed initially.
Parameters
- position HeaderPosition (default <(leading|trailing)> <leading> leading)
-
Represents the position of the header as an optional parameter. If the position is
mime:TRAILING
, the entity-body of theResponse
must be accessed initially.
-
Return Type
(string[]) An array of all the header names
content-type
header to the response.
Parameters
- contentType string
-
Content type value to be set as the
content-type
header
content-type
header value).
-
Return Type
(string) Returns the
content-type
header value as a string
json
payload from the response. If the content type is not JSON, an http:ClientError
is returned.
-
Return Type
(json | ClientError) The
json
payload orhttp:ClientError
in case of errors
xml
payload from the response.
-
Return Type
(xml | ClientError) The
xml
payload orhttp:ClientError
in case of errors
text
payload from the response.
-
Return Type
(string | ClientError) The string representation of the message payload or
http:ClientError
in case of errors
ByteChannel
, except in the case of multiparts. To retrieve multiparts, use
Response.getBodyParts()
.
-
Return Type
(ReadableByteChannel | ClientError) A byte channel from which the message payload can be read or
http:ClientError
in case of errors
byte[]
.
-
Return Type
(byte[] | ClientError) The byte[] representation of the message payload or
http:ClientError
in case of errors
-
Return Type
(Entity[] | ClientError) The body parts as an array of entities or else an
http:ClientError
if there were any errors in constructing the body parts from the response
etag
header for the given payload. The ETag is generated using a CRC32 hash function.
Parameters
- payload json | xml | string | byte[]
-
The payload for which the ETag should be set
json
as the payload.
Parameters
- payload json
-
The
json
payload
- contentType string (default application/json)
-
The content type of the payload. Set this to override the default
content-type
header value forjson
xml
as the payload
Parameters
- payload xml
-
The
xml
payload
- contentType string (default application/xml)
-
The content type of the payload. Set this to override the default
content-type
header value forxml
string
as the payload.
Parameters
- payload string
-
The
string
payload
- contentType string (default text/plain)
-
The content type of the payload. Set this to override the default
content-type
header value forstring
byte[]
as the payload.
Parameters
- payload byte[]
-
The
byte[]
payload
- contentType string (default application/octet-stream)
-
The content type of the payload. Set this to override the default
content-type
header value forbyte[]
Parameters
- bodyParts Entity[]
-
The entities which make up the message body
- contentType string (default multipart/form-data)
-
The content type of the top level message. Set this to override the default
content-type
header value
Parameters
- filePath string
-
Path to the file to be set as the payload
- contentType string (default application/octet-stream)
-
The content type of the specified file. Set this to override the default
content-type
header value
ByteChannel
as the payload.
Parameters
- payload ReadableByteChannel
-
A
ByteChannel
through which the message payload can be read
- contentType string (default application/octet-stream)
-
The content type of the payload. Set this to override the default
content-type
header value
Parameters
- payload string | xml | json | byte[] | ReadableByteChannel | Entity[]
-
Payload can be of type
string
,xml
,json
,byte[]
,ByteChannel
orEntity[]
(i.e: a set of body parts)
Parameters
- cookie Cookie
-
The cookie, which is added to response
Parameters
- cookiesToRemove Cookie[]
-
Cookies to be deleted