Minor tweaks in line with requests behavior (#110)
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 fe71e93 · Browse files · 8 files·+41 added−10 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
8 files+41 added−10 removed
- tests:+6 added−3 removed
- other:+35 added−7 removed
Provenance
- Commit
fe1f9ed- Tree
c3a1bf5- Author
Tom Christie <tom@tomchristie.com>- Committer
GitHub <noreply@github.com>- Parent
fe71e93
8 files changed+41 added−10 removed
modified:http3/__init__.py+12 added-2 removed
1+from .__version__ import __description__, __title__, __version__2 from .api import delete, get, head, options, patch, post, put, request3 from .client import AsyncClient, Client4 from .concurrency import AsyncioBackend5 from .config import (6+ USER_AGENT,7 CertTypes,8 PoolLimits,9 SSLConfig,10 TimeoutConfig,29 unmodified lines40 )41 from .models import (42 URL,43 AsyncRequest,44+ AsyncRequestData,45 AsyncResponse,46+ AsyncResponseContent,47+ AuthTypes,48 Cookies,49+ CookieTypes,50 Headers,51+ HeaderTypes,52 Origin,53 QueryParams,54+ QueryParamTypes,55 Request,56+ RequestData,57+ RequestFiles,58 Response,59+ ResponseContent,60+ URLTypes,61 )62 from .status_codes import StatusCode, codes51-52-__version__ = "0.6.5"added:http3/__version__.py+3 added
1+__title__ = "http3"2+__description__ = "A next generation HTTP client, for Python 3."3+__version__ = "0.6.6"modified:http3/client.py+10 added-1 removed
15 unmodified lines16 from .dispatch.asgi import ASGIDispatch17 from .dispatch.connection_pool import ConnectionPool18 from .dispatch.threaded import ThreadedDispatcher19 from .dispatch.wsgi import WSGIDispatch20-from .exceptions import RedirectBodyUnavailable, RedirectLoop, TooManyRedirects20+from .exceptions import (21+ InvalidURL,22+ RedirectBodyUnavailable,23+ RedirectLoop,24+ TooManyRedirects,25+)26 from .interfaces import AsyncDispatcher, ConcurrencyBackend, Dispatcher27 from .models import (28 URL,29 AsyncRequest,94 unmodified lines124 if auth is None:125 auth = self.auth126 127 url = request.url128+129+ if url.scheme not in ("http", "https"):130+ raise InvalidURL('URL scheme must be "http" or "https".')131+132 if auth is None and (url.username or url.password):133 auth = HTTPBasicAuth(username=url.username, password=url.password)134 135 if auth is not None:760 unmodified linesmodified:http3/config.py+4 added
3 unmodified lines4 import typing5 6 import certifi7 8+from .__version__ import __version__9+10 CertTypes = typing.Union[str, typing.Tuple[str, str]]11 VerifyTypes = typing.Union[str, bool]12 TimeoutTypes = typing.Union[float, typing.Tuple[float, float, float], "TimeoutConfig"]13 14 15+USER_AGENT = f"python-http3/{__version__}"16+17 DEFAULT_CIPHERS = ":".join(18 [19 "ECDHE+AESGCM",20 "ECDHE+CHACHA20",196 unmodified linesmodified:http3/models.py+5 added-3 removed
8 unmodified lines9 10 import chardet11 import rfc398612 13+from .config import USER_AGENT14 from .decoders import (15 ACCEPT_ENCODING,16 SUPPORTED_DECODERS,17 Decoder,85 unmodified lines103 # Enforce absolute URLs by default.104 if not allow_relative:105 if not self.scheme:106 raise InvalidURL("No scheme included in URL.")106- if self.scheme not in ("http", "https"):107- raise InvalidURL('URL scheme must be "http" or "https".')107 if not self.host:108 raise InvalidURL("No host included in URL.")109 110 @property421 unmodified lines532 has_content_length = (533 "content-length" in self.headers or "transfer-encoding" in self.headers534 )535 has_accept_encoding = "accept-encoding" in self.headers536+ has_connection = "connection" in self.headers537 538 if not has_host:539 auto_headers.append((b"host", self.url.authority.encode("ascii")))540 if not has_user_agent:541- auto_headers.append((b"user-agent", b"http3"))541+ auto_headers.append((b"user-agent", USER_AGENT.encode("ascii")))542 if not has_accept:543 auto_headers.append((b"accept", b"*/*"))544 if not has_content_length:545 if is_streaming:2 unmodified lines548 content_length = str(len(content)).encode()549 auto_headers.append((b"content-length", content_length))550 if not has_accept_encoding:551 auto_headers.append((b"accept-encoding", ACCEPT_ENCODING.encode()))552+ if not has_connection:553+ auto_headers.append((b"connection", b"keep-alive"))554 555 for item in reversed(auto_headers):556 self.headers.raw.insert(0, item)557 599 unmodified linesmodified:scripts/publish+1 added-1 removed
1 #!/bin/sh -e2 3 export PACKAGE="http3"4-export VERSION=`cat ${PACKAGE}/__init__.py | grep __version__ | sed "s/__version__ = //" | sed "s/'//g"`4+export VERSION=`cat ${PACKAGE}/__version__.py | grep __version__ | sed "s/__version__ = //" | sed "s/'//g"`5 export PREFIX=""6 if [ -d 'venv' ] ; then7 export PREFIX="venv/bin/"8 fi20 unmodified linesmodified:tests/models/test_requests.py-3 removed
85 unmodified lines86 with pytest.raises(http3.InvalidURL):87 http3.Request("GET", "example.org")88 89 with pytest.raises(http3.InvalidURL):90- http3.Request("GET", "invalid://example.org")91-92- with pytest.raises(http3.InvalidURL):90 http3.Request("GET", "http:///foo")modified:tests/test_api.py+6 added
81 unmodified lines82 def test_delete(server):83 response = http3.delete("http://127.0.0.1:8000/")84 assert response.status_code == 20085 assert response.reason_phrase == "OK"86+87+88+@threadpool89+def test_get_invalid_url(server):90+ with pytest.raises(http3.InvalidURL):91+ http3.get("invalid://example.org")