MCPcopy
hub / github.com/encode/httpx / send

Method send

httpx/_client.py:1594–1643  ·  view source on GitHub ↗

Send a request. The request is sent as-is, unmodified. Typically you'll want to build one with `AsyncClient.build_request()` so that any client-level configuration is merged into the request, but passing an explicit `httpx.Request()` is supported as well.

(
        self,
        request: Request,
        *,
        stream: bool = False,
        auth: AuthTypes | UseClientDefault | None = USE_CLIENT_DEFAULT,
        follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT,
    )

Source from the content-addressed store, hash-verified

1592 await response.aclose()
1593
1594 async def send(
1595 self,
1596 request: Request,
1597 *,
1598 stream: bool = False,
1599 auth: AuthTypes | UseClientDefault | None = USE_CLIENT_DEFAULT,
1600 follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT,
1601 ) -> Response:
1602 """
1603 Send a request.
1604
1605 The request is sent as-is, unmodified.
1606
1607 Typically you'll want to build one with `AsyncClient.build_request()`
1608 so that any client-level configuration is merged into the request,
1609 but passing an explicit `httpx.Request()` is supported as well.
1610
1611 See also: [Request instances][0]
1612
1613 [0]: /advanced/clients/#request-instances
1614 """
1615 if self._state == ClientState.CLOSED:
1616 raise RuntimeError("Cannot send a request, as the client has been closed.")
1617
1618 self._state = ClientState.OPENED
1619 follow_redirects = (
1620 self.follow_redirects
1621 if isinstance(follow_redirects, UseClientDefault)
1622 else follow_redirects
1623 )
1624
1625 self._set_timeout(request)
1626
1627 auth = self._build_request_auth(request, auth)
1628
1629 response = await self._send_handling_auth(
1630 request,
1631 auth=auth,
1632 follow_redirects=follow_redirects,
1633 history=[],
1634 )
1635 try:
1636 if not stream:
1637 await response.aread()
1638
1639 return response
1640
1641 except BaseException as exc:
1642 await response.aclose()
1643 raise exc
1644
1645 async def _send_handling_auth(
1646 self,

Callers 2

requestMethod · 0.95
streamMethod · 0.95

Calls 5

_send_handling_authMethod · 0.95
_set_timeoutMethod · 0.80
_build_request_authMethod · 0.80
areadMethod · 0.45
acloseMethod · 0.45

Tested by

no test coverage detected