Coverage for human_requests/abstraction/response.py: 96%
27 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-13 21:41 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-13 21:41 +0000
1from dataclasses import dataclass
2from typing import AsyncContextManager, Callable, Literal, Optional
4from playwright.async_api import Page
6from .cookies import Cookie
7from .http import URL
8from .request import Request
11@dataclass(frozen=True)
12class Response:
13 """Represents the response of a request."""
15 request: Request
16 """The request that was made."""
18 url: URL
19 """The URL of the response. Due to redirects, it can differ from `request.url`."""
21 headers: dict
22 """The headers of the response."""
24 cookies: list[Cookie]
25 """The cookies of the response."""
27 body: str
28 """The body of the response."""
30 status_code: int
31 """The status code of the response."""
33 duration: float
34 """The duration of the request in seconds."""
36 _render_callable: Optional[Callable[..., AsyncContextManager[Page]]] = None
38 def render(
39 self,
40 wait_until: Literal["commit", "load", "domcontentloaded", "networkidle"] = "commit",
41 retry: int = 2,
42 ) -> AsyncContextManager[Page]:
43 """Renders the response content in the current browser.
44 It will look like we requested it through the browser from the beginning.
46 Recommended to use in cases when the server returns a JS challenge instead of a response."""
47 if self._render_callable:
48 return self._render_callable(self, wait_until=wait_until, retry=retry)
49 raise ValueError("Not set render callable for Response")