# Response ## Definition Responses can be used to capture values to perform subsequent requests, or add asserts to HTTP responses. Response on requests are optional, a Hurl file can just consist of a sequence of [requests]. A response describes the expected HTTP response, with mandatory [version and status], followed by optional [headers], [captures], [asserts] and [body]. Assertions in the expected HTTP response describe values of the received HTTP response. Captures capture values from the received HTTP response and populate a set of named variables that can be used in the following entries. ## Example ```hurl GET https://example.org HTTP 200 Last-Modified: Wed, 21 Oct 2015 07:28:00 GMT [Asserts] xpath "normalize-space(//head/title)" startsWith "Welcome" xpath "//li" count == 18 ``` ## Structure
HTTP 200
content-length: 206
accept-ranges: bytes
user-agent: Test
[Captures]
...
[Asserts]
...
{
  "type": "FOO",
  "value": 356789,
  "ordered": true,
  "index": 10
}
## Capture and Assertion With the response section, one can optionally [capture value from headers, body], or [add assert on status code, body or headers]. ### Body compression Hurl outputs the raw HTTP body to stdout by default. If response body is compressed (using [br, gzip, deflate]), the binary stream is output, without any modification. One can use [`--compressed` option] to request a compressed response and automatically get the decompressed body. Captures and asserts work automatically on the decompressed body, so you can request compressed data (using [`Accept-Encoding`] header by example) and add assert and captures on the decoded body as if there weren't any compression. ## Timings HTTP response timings are exposed through Hurl structured output (see [`--json`]) and HTML report (see [`--report-html`]). On each response, libcurl response timings are available: - __time_namelookup__: the time it took from the start until the name resolving was completed. You can use [`--resolve`] to exclude DNS performance from the measure. - __time_connect__: The time it took from the start until the TCP connect to the remote host (or proxy) was completed. - __time_appconnect__: The time it took from the start until the SSL/SSH/etc connect/handshake to the remote host was completed. The client is then ready to send its HTTP GET request. - __time_starttransfer__: The time it took from the start until the first byte was just about to be transferred (just before Hurl reads the first byte from the network). This includes time_pretransfer and also the time the server needed to calculate the result. - __time_total__: The total time that the full operation lasted. All timings are in microsecond.
Response timings explanation Response timings explanation
Courtesy of CloudFlare [requests]: /docs/request.md [version and status]: /docs/asserting-response.md#version-status [headers]: /docs/asserting-response.md#headers [captures]: /docs/capturing-response.md#captures [asserts]: /docs/asserting-response.md#asserts [body]: /docs/asserting-response.md#body [capture value from headers, body]: /docs/capturing-response.md [add assert on status code, body or headers]: /docs/asserting-response.md [br, gzip, deflate]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding [`--compressed` option]: /docs/manual.md#compressed [`Accept-Encoding`]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding [`--json`]: /docs/manual.md#json [`--report-html`]: /docs/manual.md#report-html [`--resolve`]: /docs/manual.md#resolve