Skip to content
Myr

Version 0.28.0. (#3419)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tom Christie · committed by GitHub · parent a33c878 · Browse files · 6 files+98 added−41 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+98 added−41 removed

  • other:+98 added−41 removed

6 files+98 added−41 removed

modified:httpx/_transports/default.py+9 added-5 removed
51 unmodified lines
52 WriteError,53 WriteTimeout,54)55from .._models import Request, Response56from .._types import AsyncByteStream, ProxyTypes, SyncByteStream56from .._types import AsyncByteStream, CertTypes, ProxyTypes, SyncByteStream57from .._urls import URL58from .base import AsyncBaseTransport, BaseTransport5960T = typing.TypeVar("T", bound="HTTPTransport")
73 unmodified lines
134135class HTTPTransport(BaseTransport):136 def __init__(137 self,138 verify: ssl.SSLContext | bool = True,138 verify: ssl.SSLContext | str | bool = True,139 cert: CertTypes | None = None,140 trust_env: bool = True,141 http1: bool = True,142 http2: bool = False,143 limits: Limits = DEFAULT_LIMITS,144 proxy: ProxyTypes | None = None,
4 unmodified lines
149 ) -> None:150 import httpcore151152 proxy = Proxy(url=proxy) if isinstance(proxy, (str, URL)) else proxy151 ssl_context = create_ssl_context(verify=verify)153 ssl_context = create_ssl_context(verify=verify, cert=cert, trust_env=trust_env)154155 if proxy is None:156 self._pool = httpcore.ConnectionPool(157 ssl_context=ssl_context,
120 unmodified lines
278279class AsyncHTTPTransport(AsyncBaseTransport):280 def __init__(281 self,280 verify: ssl.SSLContext | bool = True,282 verify: ssl.SSLContext | str | bool = True,283 cert: CertTypes | None = None,284 trust_env: bool = True,285 http1: bool = True,286 http2: bool = False,287 limits: Limits = DEFAULT_LIMITS,288 proxy: ProxyTypes | None = None,
4 unmodified lines
293 ) -> None:294 import httpcore295296 proxy = Proxy(url=proxy) if isinstance(proxy, (str, URL)) else proxy293 ssl_context = create_ssl_context(verify=verify)297 ssl_context = create_ssl_context(verify=verify, cert=cert, trust_env=trust_env)298299 if proxy is None:300 self._pool = httpcore.AsyncConnectionPool(301 ssl_context=ssl_context,
105 unmodified lines
modified:httpx/_api.py+9 added-9 removed
49 unmodified lines
50 auth: AuthTypes | None = None,51 proxy: ProxyTypes | None = None,52 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,53 follow_redirects: bool = False,54 verify: ssl.SSLContext | bool = True,54 verify: ssl.SSLContext | str | bool = True,55 trust_env: bool = True,56) -> Response:57 """58 Sends an HTTP request.
76 unmodified lines
135 auth: AuthTypes | None = None,136 proxy: ProxyTypes | None = None,137 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,138 follow_redirects: bool = False,139 verify: ssl.SSLContext | bool = True,139 verify: ssl.SSLContext | str | bool = True,140 trust_env: bool = True,141) -> typing.Iterator[Response]:142 """143 Alternative to `httpx.request()` that streams the response body
35 unmodified lines
179 cookies: CookieTypes | None = None,180 auth: AuthTypes | None = None,181 proxy: ProxyTypes | None = None,182 follow_redirects: bool = False,183 verify: ssl.SSLContext | bool = True,183 verify: ssl.SSLContext | str | bool = True,184 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,185 trust_env: bool = True,186) -> Response:187 """
27 unmodified lines
215 cookies: CookieTypes | None = None,216 auth: AuthTypes | None = None,217 proxy: ProxyTypes | None = None,218 follow_redirects: bool = False,219 verify: ssl.SSLContext | bool = True,219 verify: ssl.SSLContext | str | bool = True,220 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,221 trust_env: bool = True,222) -> Response:223 """
27 unmodified lines
251 cookies: CookieTypes | None = None,252 auth: AuthTypes | None = None,253 proxy: ProxyTypes | None = None,254 follow_redirects: bool = False,255 verify: ssl.SSLContext | bool = True,255 verify: ssl.SSLContext | str | bool = True,256 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,257 trust_env: bool = True,258) -> Response:259 """
31 unmodified lines
291 cookies: CookieTypes | None = None,292 auth: AuthTypes | None = None,293 proxy: ProxyTypes | None = None,294 follow_redirects: bool = False,295 verify: ssl.SSLContext | bool = True,295 verify: ssl.SSLContext | str | bool = True,296 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,297 trust_env: bool = True,298) -> Response:299 """
32 unmodified lines
332 cookies: CookieTypes | None = None,333 auth: AuthTypes | None = None,334 proxy: ProxyTypes | None = None,335 follow_redirects: bool = False,336 verify: ssl.SSLContext | bool = True,336 verify: ssl.SSLContext | str | bool = True,337 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,338 trust_env: bool = True,339) -> Response:340 """
32 unmodified lines
373 cookies: CookieTypes | None = None,374 auth: AuthTypes | None = None,375 proxy: ProxyTypes | None = None,376 follow_redirects: bool = False,377 verify: ssl.SSLContext | bool = True,377 verify: ssl.SSLContext | str | bool = True,378 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,379 trust_env: bool = True,380) -> Response:381 """
29 unmodified lines
411 auth: AuthTypes | None = None,412 proxy: ProxyTypes | None = None,413 follow_redirects: bool = False,414 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,415 verify: ssl.SSLContext | bool = True,415 verify: ssl.SSLContext | str | bool = True,416 trust_env: bool = True,417) -> Response:418 """419 Sends a `DELETE` request.
19 unmodified lines
modified:httpx/_client.py+34 added-7 removed
31 unmodified lines
32from ._transports.default import AsyncHTTPTransport, HTTPTransport33from ._types import (34 AsyncByteStream,35 AuthTypes,36 CertTypes,37 CookieTypes,38 HeaderTypes,39 ProxyTypes,40 QueryParamTypes,
603 unmodified lines
644 auth: AuthTypes | None = None,645 params: QueryParamTypes | None = None,646 headers: HeaderTypes | None = None,647 cookies: CookieTypes | None = None,647 verify: ssl.SSLContext | bool = True,648 verify: ssl.SSLContext | str | bool = True,649 cert: CertTypes | None = None,650 trust_env: bool = True,651 http1: bool = True,652 http2: bool = False,653 proxy: ProxyTypes | None = None,654 mounts: None | (typing.Mapping[str, BaseTransport | None]) = None,
3 unmodified lines
658 max_redirects: int = DEFAULT_MAX_REDIRECTS,659 event_hooks: None | (typing.Mapping[str, list[EventHook]]) = None,660 base_url: URL | str = "",661 transport: BaseTransport | None = None,659 trust_env: bool = True,662 default_encoding: str | typing.Callable[[bytes], str] = "utf-8",663 ) -> None:664 super().__init__(665 auth=auth,
22 unmodified lines
688 proxy_map = self._get_proxy_map(proxy, allow_env_proxies)689690 self._transport = self._init_transport(691 verify=verify,692 cert=cert,693 trust_env=trust_env,694 http1=http1,695 http2=http2,696 limits=limits,697 transport=transport,
3 unmodified lines
701 if proxy is None702 else self._init_proxy_transport(703 proxy,704 verify=verify,705 cert=cert,706 trust_env=trust_env,707 http1=http1,708 http2=http2,709 limits=limits,710 )
7 unmodified lines
718 self._mounts = dict(sorted(self._mounts.items()))719720 def _init_transport(721 self,716 verify: ssl.SSLContext | bool = True,722 verify: ssl.SSLContext | str | bool = True,723 cert: CertTypes | None = None,724 trust_env: bool = True,725 http1: bool = True,726 http2: bool = False,727 limits: Limits = DEFAULT_LIMITS,728 transport: BaseTransport | None = None,
2 unmodified lines
731 return transport732733 return HTTPTransport(734 verify=verify,735 cert=cert,736 trust_env=trust_env,737 http1=http1,738 http2=http2,739 limits=limits,740 )741742 def _init_proxy_transport(743 self,744 proxy: Proxy,735 verify: ssl.SSLContext | bool = True,745 verify: ssl.SSLContext | str | bool = True,746 cert: CertTypes | None = None,747 trust_env: bool = True,748 http1: bool = True,749 http2: bool = False,750 limits: Limits = DEFAULT_LIMITS,751 ) -> BaseTransport:752 return HTTPTransport(753 verify=verify,754 cert=cert,755 trust_env=trust_env,756 http1=http1,757 http2=http2,758 limits=limits,759 proxy=proxy,
598 unmodified lines
1358 auth: AuthTypes | None = None,1359 params: QueryParamTypes | None = None,1360 headers: HeaderTypes | None = None,1361 cookies: CookieTypes | None = None,1348 verify: ssl.SSLContext | bool = True,1362 verify: ssl.SSLContext | str | bool = True,1363 cert: CertTypes | None = None,1364 http1: bool = True,1365 http2: bool = False,1366 proxy: ProxyTypes | None = None,1367 mounts: None | (typing.Mapping[str, AsyncBaseTransport | None]) = None,
34 unmodified lines
1402 proxy_map = self._get_proxy_map(proxy, allow_env_proxies)14031404 self._transport = self._init_transport(1405 verify=verify,1406 cert=cert,1407 trust_env=trust_env,1408 http1=http1,1409 http2=http2,1410 limits=limits,1411 transport=transport,
4 unmodified lines
1416 if proxy is None1417 else self._init_proxy_transport(1418 proxy,1419 verify=verify,1420 cert=cert,1421 trust_env=trust_env,1422 http1=http1,1423 http2=http2,1424 limits=limits,1425 )
6 unmodified lines
1432 self._mounts = dict(sorted(self._mounts.items()))14331434 def _init_transport(1435 self,1417 verify: ssl.SSLContext | bool = True,1436 verify: ssl.SSLContext | str | bool = True,1437 cert: CertTypes | None = None,1438 trust_env: bool = True,1439 http1: bool = True,1440 http2: bool = False,1441 limits: Limits = DEFAULT_LIMITS,1442 transport: AsyncBaseTransport | None = None,
2 unmodified lines
1445 return transport14461447 return AsyncHTTPTransport(1448 verify=verify,1449 cert=cert,1450 trust_env=trust_env,1451 http1=http1,1452 http2=http2,1453 limits=limits,1454 )14551456 def _init_proxy_transport(1457 self,1458 proxy: Proxy,1436 verify: ssl.SSLContext | bool = True,1459 verify: ssl.SSLContext | str | bool = True,1460 cert: CertTypes | None = None,1461 trust_env: bool = True,1462 http1: bool = True,1463 http2: bool = False,1464 limits: Limits = DEFAULT_LIMITS,1465 ) -> AsyncBaseTransport:1466 return AsyncHTTPTransport(1467 verify=verify,1468 cert=cert,1469 trust_env=trust_env,1470 http1=http1,1471 http2=http2,1472 limits=limits,1473 proxy=proxy,
548 unmodified lines
modified:httpx/_config.py+36 added-9 removed
1from __future__ import annotations23import os4import typing56from ._models import Headers6from ._types import HeaderTypes, TimeoutTypes7from ._types import CertTypes, HeaderTypes, TimeoutTypes8from ._urls import URL910if typing.TYPE_CHECKING:11 import ssl # pragma: no cover
7 unmodified lines
1920UNSET = UnsetType()212222def create_ssl_context(verify: ssl.SSLContext | bool = True) -> ssl.SSLContext:23def create_ssl_context(24 verify: ssl.SSLContext | str | bool = True,25 cert: CertTypes | None = None,26 trust_env: bool = True,27) -> ssl.SSLContext:28 import ssl29 import warnings3031 import certifi3233 if verify is True:34 if trust_env and os.environ.get("SSL_CERT_FILE"): # pragma: nocover35 ctx = ssl.create_default_context(cafile=os.environ["SSL_CERT_FILE"])36 elif trust_env and os.environ.get("SSL_CERT_DIR"): # pragma: nocover37 ctx = ssl.create_default_context(capath=os.environ["SSL_CERT_DIR"])38 else:39 # Default case...28 return ssl.create_default_context(cafile=certifi.where())40 ctx = ssl.create_default_context(cafile=certifi.where())41 elif verify is False:42 ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)43 ssl_context.check_hostname = False44 ssl_context.verify_mode = ssl.CERT_NONE45 return ssl_context46 elif isinstance(verify, str): # pragma: nocover35 # Explicitly handle this deprecated usage pattern.36 msg = (37 "verify should be a boolean or SSLContext, since version 0.28. "47 message = (48 "`verify=<str>` is deprecated. "49 "Use `verify=ssl.create_default_context(cafile=...)` "39 "or `verify=ssl.create_default_context(capath=...)`."50 "or `verify=ssl.create_default_context(capath=...)` instead."51 )41 raise RuntimeError(msg)52 warnings.warn(message, DeprecationWarning)53 if os.path.isdir(verify):54 return ssl.create_default_context(capath=verify)55 return ssl.create_default_context(cafile=verify)56 else:57 ctx = verify5843 return verify59 if cert: # pragma: nocover60 message = (61 "`cert=...` is deprecated. Use `verify=<ssl_context>` instead,"62 "with `.load_cert_chain()` to configure the certificate chain."63 )64 warnings.warn(message, DeprecationWarning)65 if isinstance(cert, str):66 ctx.load_cert_chain(cert)67 else:68 ctx.load_cert_chain(*cert)6970 return ctx717273class Timeout:74 """75 Timeout configuration.76
173 unmodified lines
modified:httpx/_types.py+1 added
55 unmodified lines
56 Tuple[Optional[float], Optional[float], Optional[float], Optional[float]],57 "Timeout",58]59ProxyTypes = Union["URL", str, "Proxy"]60CertTypes = Union[str, Tuple[str, str], Tuple[str, str, str]]6162AuthTypes = Union[63 Tuple[Union[str, bytes], Union[str, bytes]],64 Callable[["Request"], "Request"],
50 unmodified lines
modified:CHANGELOG.md+9 added-11 removed
2 unmodified lines
3All notable changes to this project will be documented in this file.45The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).67## 0.28.0 (...)7## 0.28.0 (28th November, 2024)89The 0.28 release includes a limited set of backwards incompatible changes.9The 0.28 release includes a limited set of deprecations.1011**Backwards incompatible changes**:11**Deprecations**:1213SSL configuration has been significantly simplified.13We are working towards a simplified SSL configuration API.1415* The `verify` argument no longer accepts string arguments.16* The `cert` argument has now been removed.17* The `SSL_CERT_FILE` and `SSL_CERT_DIR` environment variables are no longer automatically used.15*For users of the standard `verify=True` or `verify=False` cases, or `verify=<ssl_context>` case this should require no changes. The following cases have been deprecated...*1619For users of the standard `verify=True` or `verify=False` cases this should require no changes.17* The `verify` argument as a string argument is now deprecated and will raise warnings.18* The `cert` argument is now deprecated and will raise warnings.1921For information on configuring more complex SSL cases, please see the [SSL documentation](docs/advanced/ssl.md).20Our revised [SSL documentation](docs/advanced/ssl.md) covers how to implement the same behaviour with a more constrained API.2122**The following changes are also included**:2325* The undocumented `URL.raw` property has now been deprecated, and will raise warnings.24* The deprecated `proxies` argument has now been removed.25* The deprecated `app` argument has now been removed.28* Ensure JSON request bodies are compact. (#3363)26* JSON request bodies use a compact representation. (#3363)27* Review URL percent escape sets, based on WHATWG spec. (#3371, #3373)28* Ensure `certifi` and `httpcore` are only imported if required. (#3377)29* Treat `socks5h` as a valid proxy scheme. (#3178)30* Cleanup `Request()` method signature in line with `client.request()` and `httpx.request()`. (#3378)
1095 unmodified lines