# HTTP request and response reference

## Response properties

The `response` object holds the information about a received HTTP Response (response content, headers, status, and so on) and provides access to the [headers](#headers-reference) and [contentType](#content-type-reference) nested objects.

| Property | Description |
| --- | --- |
|  `body` (string \| [TextStreamResponse](#textstreamresponse_reference) \| DOM Document \| object)  |  Response content, which can be a string, a TextStreamResponse object, a DOM `Document`, or a JSON object.  |
|  `headers` ([ResponseHeaders](#headers-reference))  |  The [response headers storage                     object](#headers-reference).  |
|  `status` (int)  |  Response status, for example, 200 or 404.  |
|  `contentType` ([ContentType](#content-type-reference))  | The [contentType object](#content-type-reference), which holds the data on the Content-Type response header value. |

## Headers object

The `ResponseHeaders` object is used for retrieving the data about response headers' values.

### Methods

| Method | Parameters | Description |
| --- | --- | --- |
| valueOf |     `headerName` (string)                          |     Retrieves the first value of the `headerName` response header or `null` if the `headerName` response header does not exist.     |
| valuesOf |     `headerName` (string)                          |     Retrieves the array containing all values of the `headerName` response header. Returns an empty array if the `headerName` response header does not exist.     |

## ContentType object

The `ContentType` data object contains information from the Content-Type response header.

### Properties

| Property | Description |
| --- | --- |
|  `mimeType` (string)  |  The MIME type of the response, for example, text/plain,  text/xml, application/json.  |
|  `charset` (string)  |  The string representation of the response charset, for example, utf-8.  |

## TextStreamResponse object

The `TextStreamResponse` interface is used to process a response as a text stream. It lets you implement two methods:

* `onEachLine(subscriber, onFinish)`, which loops through each line in the stream.

* `onEachMessage(subscriber, onFinish)`, which subscribes to each message sent by the server. This can be used for WebSocket, GRPC, and GraphQL over WebSocket.

### Arguments

| Argument | Usage in onEachLine | Usage in onEachMessage |
| --- | --- | --- |
|  `subscriber`  |     Function to process the streamlines. It takes two arguments:        * `line`: a string or a JSON object received as part of the stream.    * `unsubscribe`: a function that terminates execution of the current `onEachLine` block. It can be used to stop stream processing when a certain condition is met.    |     Function to process the stream messages. It takes three arguments:        * `message`: a string or a JSON object received as part of the stream.    * `unsubscribe`: a function that terminates execution of the current `onEachMessage` block. It can be used to stop stream processing when a certain condition is met.    * `output` (optional): a function that takes a string (message) and sends its argument back to the server.    |
|  `onFinish`  |  Function to be executed after the end of the stream.  |

For examples on how to use it, refer to [Response handling examples](http-response-handling-examples.html) or click Examples in an `.http` file and select WebSocket Requests or GraphQL Requests.

## Cookies

The HTTP Client offers methods for working with cookies returned in the `Set-Cookie` headers of an HTTP response:

| Method | Parameters | Description |
| --- | --- | --- |
| `response.cookies()` | - | Returns an array of all cookies set by the server. |
| `response.cookiesByName(name)` | `name` (string) | Returns an array of cookies filtered by the specified name. |

You can use these methods to extract specific cookies from a response and reuse their values in the following requests, for example, by [storing a cookie as a variable](http-response-handling-examples.html#cookie-in-a-variable). You can also verify that a server sets the expected cookies after actions such as login or logout, inspect cookie attributes for debugging purposes, or assert that certain cookies are present as part of an automated test flow.

## Request properties

The `request` object holds the information about the HTTP request and can be used both in pre-request scripts and in response handler scripts.

| Property | When used in pre-request scripts | When used in response handler scripts |
| --- | --- | --- |
|  `body()`  |    The request [body](exploring-http-syntax.html#provide-request-body) obtained using one of two methods:        * `getRaw()`: returns the request body in the raw format: If the body contains variables, their names are displayed instead of their values. For example: ```JAVASCRIPT client.log(request.body.getRaw()); ```    * `tryGetSubstituted()`: returns the request body with all known variables replaced with their values. ```JAVASCRIPT client.log(request.body.tryGetSubstituted()); ```    |     The request [body](exploring-http-syntax.html#provide-request-body) as a string. For example:       ```JAVASCRIPT client.log(request.body()) ```    |
|  `environment`  |  Has the `get(name)` method, which retrieves a value of the [environment variable](http-client-variables.html#environment-variables) identified by its `name` or returns `null` if it does not exist.  |
|  `headers`  |    Has two methods:       * `all`: returns the array containing the values of all headers of the current request.    * `findByName(name)`: retrieves the value of the header identified by the `name` parameter.    |
|     Each of the elements of the array is a request header with the following methods:        * `name`: the header name, such as `Content-Type`.    * `getRawValue`: returns the header value in the raw format: If the header contains variables, their names are displayed instead of their values.    * `tryGetSubstitutedValue()`: returns the header with all known variables replaced with their values.    |     Each of the elements of the array is a request header with the following methods:        * `name`: the header name, such as `Content-Type`.    * `value()`: the header value, such as `application/json`.    |
|  `method`  |  The HTTP method (such as GET or POST) used in the request. For example: `client.log(request.method)`  |
|  `url()`  |    The request URL obtained using one of two methods:        * `getRaw()`: returns the request URL in the raw format: If the URL contains variables, their names are displayed instead of their values. For example: ```JAVASCRIPT client.log(request.url.getRaw()); ```    * `tryGetSubstituted()`: returns the request URL with all known variables replaced with their values. ```JAVASCRIPT client.log(request.url.tryGetSubstituted()); ```    |     The request URL as a string. For example:       ```JAVASCRIPT client.log(request.url()) ```    |
|  `variables`  |  Has the `get(name)` method, which retrieves a value of the [per-request variable](http-client-variables.html#per_request_variables) identified by its `name` or returns `null` if it does not exist.  |
|  `iteration()`  |     [Get the number (index) of the current iteration](http-client-variables.html#iteration-example)       For variables that represent a collection.     |
|  `templateValue(Integer)`  |  [Get the value of a collection element by its index in the loop.](http-client-variables.html#templatevalue-example)  |

