(
self,
status: int = None,
headers: Dict[str, str] = None,
body: Union[str, bytes] = None,
json: Any = None,
path: Union[str, Path] = None,
contentType: str = None,
response: "APIResponse" = None,
)
| 395 | ) |
| 396 | |
| 397 | async def _inner_fulfill( |
| 398 | self, |
| 399 | status: int = None, |
| 400 | headers: Dict[str, str] = None, |
| 401 | body: Union[str, bytes] = None, |
| 402 | json: Any = None, |
| 403 | path: Union[str, Path] = None, |
| 404 | contentType: str = None, |
| 405 | response: "APIResponse" = None, |
| 406 | ) -> None: |
| 407 | params = locals_to_params(locals()) |
| 408 | |
| 409 | if json is not None: |
| 410 | if body is not None: |
| 411 | raise Error("Can specify either body or json parameters") |
| 412 | body = json_utils.dumps(json) |
| 413 | |
| 414 | if response: |
| 415 | del params["response"] |
| 416 | params["status"] = ( |
| 417 | params["status"] if params.get("status") else response.status |
| 418 | ) |
| 419 | params["headers"] = ( |
| 420 | params["headers"] if params.get("headers") else response.headers |
| 421 | ) |
| 422 | from playwright._impl._fetch import APIResponse |
| 423 | |
| 424 | if body is None and path is None and isinstance(response, APIResponse): |
| 425 | if response._request._connection is self._connection: |
| 426 | params["fetchResponseUid"] = response._fetch_uid |
| 427 | else: |
| 428 | body = await response.body() |
| 429 | |
| 430 | length = 0 |
| 431 | if isinstance(body, str): |
| 432 | params["body"] = body |
| 433 | params["isBase64"] = False |
| 434 | length = len(body.encode()) |
| 435 | elif isinstance(body, bytes): |
| 436 | params["body"] = base64.b64encode(body).decode() |
| 437 | params["isBase64"] = True |
| 438 | length = len(body) |
| 439 | elif path: |
| 440 | del params["path"] |
| 441 | file_content = Path(path).read_bytes() |
| 442 | params["body"] = base64.b64encode(file_content).decode() |
| 443 | params["isBase64"] = True |
| 444 | length = len(file_content) |
| 445 | |
| 446 | headers = {k.lower(): str(v) for k, v in params.get("headers", {}).items()} |
| 447 | if params.get("contentType"): |
| 448 | headers["content-type"] = params["contentType"] |
| 449 | elif json: |
| 450 | headers["content-type"] = "application/json" |
| 451 | elif path: |
| 452 | headers["content-type"] = ( |
| 453 | mimetypes.guess_type(str(Path(path)))[0] or "application/octet-stream" |
| 454 | ) |
no test coverage detected