Convenience method to synchronously fetch a URL. The given path will be appended to the local server's host and port. Any additional keyword arguments will be passed directly to `.AsyncHTTPClient.fetch` (and so could be used to pass ``method="POST"``, ``body="..."``
(
self, path: str, raise_error: bool = False, **kwargs: Any
)
| 464 | raise NotImplementedError() |
| 465 | |
| 466 | def fetch( |
| 467 | self, path: str, raise_error: bool = False, **kwargs: Any |
| 468 | ) -> HTTPResponse: |
| 469 | """Convenience method to synchronously fetch a URL. |
| 470 | |
| 471 | The given path will be appended to the local server's host and |
| 472 | port. Any additional keyword arguments will be passed directly to |
| 473 | `.AsyncHTTPClient.fetch` (and so could be used to pass |
| 474 | ``method="POST"``, ``body="..."``, etc). |
| 475 | |
| 476 | If the path begins with http:// or https://, it will be treated as a |
| 477 | full URL and will be fetched as-is. |
| 478 | |
| 479 | If ``raise_error`` is ``True``, a `tornado.httpclient.HTTPError` will |
| 480 | be raised if the response code is not 200. This is the same behavior |
| 481 | as the ``raise_error`` argument to `.AsyncHTTPClient.fetch`, but |
| 482 | the default is ``False`` here (it's ``True`` in `.AsyncHTTPClient`) |
| 483 | because tests often need to deal with non-200 response codes. |
| 484 | |
| 485 | .. versionchanged:: 5.0 |
| 486 | Added support for absolute URLs. |
| 487 | |
| 488 | .. versionchanged:: 5.1 |
| 489 | |
| 490 | Added the ``raise_error`` argument. |
| 491 | |
| 492 | .. deprecated:: 5.1 |
| 493 | |
| 494 | This method currently turns any exception into an |
| 495 | `.HTTPResponse` with status code 599. In Tornado 6.0, |
| 496 | errors other than `tornado.httpclient.HTTPError` will be |
| 497 | passed through, and ``raise_error=False`` will only |
| 498 | suppress errors that would be raised due to non-200 |
| 499 | response codes. |
| 500 | |
| 501 | """ |
| 502 | if path.lower().startswith(("http://", "https://")): |
| 503 | url = path |
| 504 | else: |
| 505 | url = self.get_url(path) |
| 506 | return self.io_loop.run_sync( |
| 507 | lambda: self.http_client.fetch(url, raise_error=raise_error, **kwargs), |
| 508 | timeout=get_async_test_timeout(), |
| 509 | ) |
| 510 | |
| 511 | def get_httpserver_options(self) -> Dict[str, Any]: |
| 512 | """May be overridden by subclasses to return additional |
nothing calls this directly
no test coverage detected