playwright/docs/src/api/class-response.md

154 lines
4.5 KiB
Markdown
Raw Normal View History

# class: Response
2022-07-05 16:24:50 -08:00
* since: v1.8
[Response] class represents responses which are received by page.
## async method: Response.allHeaders
2022-07-05 16:24:50 -08:00
* since: v1.15
- returns: <[Object]<[string], [string]>>
An object with all the response HTTP headers associated with this response.
## async method: Response.body
2022-07-05 16:24:50 -08:00
* since: v1.8
- returns: <[Buffer]>
Returns the buffer with response body.
## async method: Response.finished
2022-07-05 16:24:50 -08:00
* since: v1.8
- returns: <[null]|[string]>
Waits for this response to finish, returns always `null`.
## method: Response.frame
2022-07-05 16:24:50 -08:00
* since: v1.8
- returns: <[Frame]>
Returns the [Frame] that initiated this response.
## method: Response.fromServiceWorker
2022-07-05 16:24:50 -08:00
* since: v1.23
- returns: <[boolean]>
Indicates whether this Response was fulfilled by a Service Worker's Fetch Handler (i.e. via [FetchEvent.respondWith](https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent/respondWith)).
## method: Response.headers
2022-07-05 16:24:50 -08:00
* since: v1.8
- returns: <[Object]<[string], [string]>>
An object with the response HTTP headers. The header names are lower-cased.
Note that this method does not return security-related headers, including cookie-related ones.
You can use [`method: Response.allHeaders`] for complete list of headers that include `cookie` information.
## async method: Response.headersArray
2022-07-05 16:24:50 -08:00
* since: v1.15
- returns: <[Array]<[Object]>>
- `name` <[string]> Name of the header.
- `value` <[string]> Value of the header.
2021-09-11 13:27:00 -07:00
An array with all the request HTTP headers associated with this response. Unlike [`method: Response.allHeaders`], header names are NOT lower-cased.
Headers with multiple entries, such as `Set-Cookie`, appear in the array multiple times.
2021-09-11 13:27:00 -07:00
## async method: Response.headerValue
2022-07-05 16:24:50 -08:00
* since: v1.15
2021-09-11 13:27:00 -07:00
- returns: <[null]|[string]>
Returns the value of the header matching the name. The name is case insensitive. If multiple headers have
the same name (except `set-cookie`), they are returned as a list separated by `, `. For `set-cookie`, the `\n` separator is used. If no headers are found, `null` is returned.
### param: Response.headerValue.name
2022-07-05 16:24:50 -08:00
* since: v1.15
2021-09-11 13:27:00 -07:00
- `name` <[string]>
Name of the header.
## async method: Response.headerValues
2022-07-05 16:24:50 -08:00
* since: v1.15
2021-09-11 13:27:00 -07:00
- returns: <[Array]<[string]>>
Returns all values of the headers matching the name, for example `set-cookie`. The name is case insensitive.
### param: Response.headerValues.name
2022-07-05 16:24:50 -08:00
* since: v1.15
2021-09-11 13:27:00 -07:00
- `name` <[string]>
Name of the header.
## async method: Response.json
2022-07-05 16:24:50 -08:00
* since: v1.8
2021-05-24 13:40:02 -07:00
* langs: js, python
- returns: <[Serializable]>
Returns the JSON representation of response body.
This method will throw if the response body is not parsable via `JSON.parse`.
2021-05-24 13:40:02 -07:00
## async method: Response.json
2022-07-05 16:24:50 -08:00
* since: v1.8
2021-05-24 13:40:02 -07:00
* langs: csharp
- returns: <[null]|[JsonElement]>
2021-05-24 13:40:02 -07:00
Returns the JSON representation of response body.
This method will throw if the response body is not parsable via `JSON.parse`.
## method: Response.ok
2022-07-05 16:24:50 -08:00
* since: v1.8
- returns: <[boolean]>
Contains a boolean stating whether the response was successful (status in the range 200-299) or not.
## method: Response.request
2022-07-05 16:24:50 -08:00
* since: v1.8
- returns: <[Request]>
Returns the matching [Request] object.
## async method: Response.securityDetails
2022-07-05 16:24:50 -08:00
* since: v1.13
- returns: <[null]|[Object]>
- `issuer` ?<[string]> Common Name component of the Issuer field.
from the certificate. This should only be used for informational purposes. Optional.
- `protocol` ?<[string]> The specific TLS protocol used. (e.g. `TLS 1.3`). Optional.
- `subjectName` ?<[string]> Common Name component of the Subject
field from the certificate. This should only be used for informational purposes. Optional.
- `validFrom` ?<[float]> Unix timestamp (in seconds) specifying
when this cert becomes valid. Optional.
- `validTo` ?<[float]> Unix timestamp (in seconds) specifying
when this cert becomes invalid. Optional.
Returns SSL and other security information.
## async method: Response.serverAddr
2022-07-05 16:24:50 -08:00
* since: v1.13
- returns: <[null]|[Object]>
- `ipAddress` <[string]> IPv4 or IPV6 address of the server.
- `port` <[int]>
Returns the IP address and port of the server.
## method: Response.status
2022-07-05 16:24:50 -08:00
* since: v1.8
- returns: <[int]>
Contains the status code of the response (e.g., 200 for a success).
## method: Response.statusText
2022-07-05 16:24:50 -08:00
* since: v1.8
- returns: <[string]>
Contains the status text of the response (e.g. usually an "OK" for a success).
## async method: Response.text
2022-07-05 16:24:50 -08:00
* since: v1.8
- returns: <[string]>
Returns the text representation of response body.
## method: Response.url
2022-07-05 16:24:50 -08:00
* since: v1.8
- returns: <[string]>
Contains the URL of the response.