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.

Adds the specified header to the response.

Gets all the header values to which the specified header key maps to.

Sets the specified header to the response.

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.

Extract json payload from the response.

Extracts xml payload from the response.

Extracts text payload from the response.

Gets the response payload as a ByteChannel, except in the case of multiparts.

Gets the response payload as a byte[].

Extracts body parts from the response.

Sets the etag header for the given payload.

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.

Adds the cookie to response.

Deletes the cookies in the client's cookie store.

Gets cookies from the response.

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

getEntity

()

returns Entity | ClientError

Gets the Entity associated with the response.

  • Return Type

    (Entity | ClientError)
  • The Entity of the response. An http:ClientError is returned, if entity construction fails

setEntity

Sets the provided Entity to the response.

Parameters

  • e Entity
  • The Entity to be set to the response

hasHeader

(string headerName, HeaderPosition position)

returns boolean

Checks whether the requested header key exists in the header map.

Parameters

  • headerName string
  • The header name

  • position HeaderPosition (default mime:LEADING)
  • Represents the position of the header as an optional parameter

  • Return Type

    (boolean)
  • true if the specified header key exists

getHeader

(string headerName, HeaderPosition position)

returns string

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

  • position HeaderPosition (default mime:LEADING)
  • Represents the position of the header as an optional parameter. If the position is mime:TRAILING, the entity-body of the Response 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.

addHeader

Adds the specified header to the response. Existing header values are not replaced. Panic if an illegal header is passed.

Parameters

  • headerName string
  • The header name

  • headerValue string
  • The header value

  • position HeaderPosition (default mime:LEADING)
  • Represents the position of the header as an optional parameter. If the position is mime:TRAILING, the entity-body of the Response must be accessed initially.

getHeaders

(string headerName, HeaderPosition position)

returns string[]

Gets all the header values to which the specified header key maps to.

Parameters

  • headerName string
  • The header name

  • position HeaderPosition (default mime:LEADING)
  • Represents the position of the header as an optional parameter. If the position is mime:TRAILING, the entity-body of the Response 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.

setHeader

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. Panic if an illegal header is passed.

Parameters

  • headerName string
  • The header name

  • headerValue string
  • The header value

  • position HeaderPosition (default mime:LEADING)
  • Represents the position of the header as an optional parameter. If the position is mime:TRAILING, the entity-body of the Response must be accessed initially.

removeHeader

Removes the specified header from the response.

Parameters

  • key string
  • The header name

  • position HeaderPosition (default mime:LEADING)
  • Represents the position of the header as an optional parameter. If the position is mime:TRAILING, the entity-body of the Response must be accessed initially.

removeAllHeaders

Removes all the headers from the response.

Parameters

  • position HeaderPosition (default mime:LEADING)
  • Represents the position of the header as an optional parameter. If the position is mime:TRAILING, the entity-body of the Response must be accessed initially.

getHeaderNames

(HeaderPosition position)

returns string[]

Gets all the names of the headers of the response.

Parameters

  • position HeaderPosition (default mime:LEADING)
  • Represents the position of the header as an optional parameter. If the position is mime:TRAILING, the entity-body of the Response must be accessed initially.

  • Return Type

    (string[])
  • An array of all the header names

setContentType

Sets the content-type header to the response.

Parameters

  • contentType string
  • Content type value to be set as the content-type header

getContentType

()

returns string

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

getJsonPayload

()

returns json | ClientError

Extract json payload from the response. If the content type is not JSON, an http:ClientError is returned.

  • Return Type

    (json | ClientError)
  • The json payload or http:ClientError in case of errors

getXmlPayload

()

returns xml | ClientError

Extracts xml payload from the response.

  • Return Type

    (xml | ClientError)
  • The xml payload or http:ClientError in case of errors

getTextPayload

()

returns string | ClientError

Extracts text payload from the response.

  • Return Type

    (string | ClientError)
  • The string representation of the message payload or http:ClientError in case of errors

getByteChannel

()

returns ReadableByteChannel | ClientError

Gets the response payload as a ByteChannel, except in the case of multiparts. To retrieve multiparts, use Response.getBodyParts().

getBinaryPayload

()

returns byte[] | ClientError

Gets the response payload as a byte[].

  • Return Type

    (byte[] | ClientError)
  • The byte[] representation of the message payload or http:ClientError in case of errors

getBodyParts

()

returns Entity[] | ClientError

Extracts body parts from the response. If the content type is not a composite media type, an error is returned.

  • 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

setETag

Sets the 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

setLastModified

Sets the current time as the last-modified header.

setJsonPayload

Sets a 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 for json

setXmlPayload

Sets an 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 for xml

setTextPayload

Sets a 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 for string

setBinaryPayload

Sets a 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 for byte[]

setBodyParts

Set multiparts as the payload.

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

setFileAsPayload

Sets the content of the specified file as the entity body of the response.

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

setByteChannel

Sets a ByteChannel as the payload.

Parameters

  • contentType string (default application/octet-stream)
  • The content type of the payload. Set this to override the default content-type header value

setPayload

Sets the response payload.

Parameters

  • payload string | xml | json | byte[] | ReadableByteChannel | Entity[]
  • Payload can be of type string, xml, json, byte[], ByteChannel or Entity[] (i.e: a set of body parts)

addCookie

Adds the cookie to response.

Parameters

  • cookie Cookie
  • The cookie, which is added to response

removeCookiesFromRemoteStore

Deletes the cookies in the client's cookie store.

Parameters

  • cookiesToRemove Cookie[]
  • Cookies to be deleted

getCookies

()

returns Cookie[]

Gets cookies from the response.

  • Return Type

    (Cookie[])
  • An array of cookie objects, which are included in the response