Object -
http :
Response
Represents an HTTP response.
Methods
Gets the Entity
associated with the response.
Sets the provided Entity
to the response.
Checks whether the requested header key exists in the header map.
Returns the value of the specified header. If the specified header key maps to multiple values, the first of these values is returned.
Adds the specified header to the response. Existing header values are not replaced.
Gets all the header values to which the specified header key maps to.
Sets the specified header to the response. If a mapping already exists for the specified header key, the existing header value is replaced with the specified header value.
Removes the specified header from the response.
Removes all the headers from the response.
Gets all the names of the headers of the response.
Sets the content-type
header to the response.
Gets the type of the payload of the response (i.e: the content-type
header value).
Extract json
payload from the response. If the content type is not JSON, an error
is returned.
Extracts xml
payload from the response. If the the content type is not XML, an error
is returned.
Extracts text
payload from the response. If the content type is not of type text, an error
is returned.
Gets the response payload as a ByteChannel
, except in the case of multiparts. To retrieve multiparts, use
getBodyParts()
.
Gets the response payload as a byte[]
.
Extracts body parts from the response. If the content type is not a composite media type, an error is returned.
Sets the etag
header for the given payload. The ETag is generated using a CRC32 hash function.
Sets the current time as the last-modified
header.
Sets a json
as the payload.
Sets an xml
as the payload
Sets a string
as the payload.
Sets a byte[]
as the payload.
Set multiparts as the payload.
Sets the content of the specified file as the entity body of the response.
Sets a ByteChannel
as the payload.
Sets the response payload.
Fields
- statusCode int 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? ()
-
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
Gets the Entity
associated with the response.
Sets the provided Entity
to the response.
Parameters
- e Entity
-
The
Entity
to be set to the response
Checks whether the requested header key exists in the header map.
Parameters
- headerName string
-
The header name
-
Return Type
(boolean) Returns true if the specified header key exists
Returns the value of the specified header. If the specified header key maps to multiple values, the first of these values is returned.
Parameters
- headerName string
-
The header name
-
Return Type
(string) The first header value for the specified header name. An exception is thrown if no header is found. Use
hasHeader()
beforehand to check the existence of header.
Adds the specified header to the response. Existing header values are not replaced.
Gets all the header values to which the specified header key maps to.
Parameters
- headerName string
-
The header name
-
Return Type
(string[]) The header values the specified header key maps to. An exception is thrown if no header is found. Use
hasHeader()
beforehand to check the existence of header.
Sets the specified header to the response. If a mapping already exists for the specified header key, the existing header value is replaced with the specified header value.
Gets all the names of the headers of the response.
-
Return Type
(string[]) An array of all the header names
Sets the content-type
header to the response.
Parameters
- contentType string
-
Content type value to be set as the
content-type
header
Gets the type of the payload of the response (i.e: the content-type
header value).
-
Return Type
(string) Returns the
content-type
header value as a string
Extract json
payload from the response. If the content type is not JSON, an error
is returned.
Extracts xml
payload from the response. If the the content type is not XML, an error
is returned.
Extracts text
payload from the response. If the content type is not of type text, an error
is returned.
Gets the response payload as a ByteChannel
, except in the case of multiparts. To retrieve multiparts, use
getBodyParts()
.
-
Return Type
(ReadableByteChannel | error) A byte channel from which the message payload can be read or
error
in case of errors
Gets the response payload as a byte[]
.
Extracts body parts from the response. If the content type is not a composite media type, an error is returned.
Sets the etag
header for the given payload. The ETag is generated using a CRC32 hash function.
Sets a json
as the payload.
Sets an xml
as the payload
Sets a string
as the payload.
Sets a byte[]
as the payload.
Set multiparts as the payload.
Sets the content of the specified file as the entity body of the response.
Sets a ByteChannel
as the payload.
Parameters
- payload ReadableByteChannel
-
A
ByteChannel
through which the message payload can be read
- contentType string - application/octet-stream
-
The content type of the payload. Set this to override the default
content-type
header value