Skip to content
Myr

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

8 files+41 added−10 removed

modified:http3/__init__.py+12 added-2 removed
1from .__version__ import __description__, __title__, __version__2from .api import delete, get, head, options, patch, post, put, request3from .client import AsyncClient, Client4from .concurrency import AsyncioBackend5from .config import (6 USER_AGENT,7 CertTypes,8 PoolLimits,9 SSLConfig,10 TimeoutConfig,
29 unmodified lines
40)41from .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)62from .status_codes import StatusCode, codes5152__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 lines
16from .dispatch.asgi import ASGIDispatch17from .dispatch.connection_pool import ConnectionPool18from .dispatch.threaded import ThreadedDispatcher19from .dispatch.wsgi import WSGIDispatch20from .exceptions import RedirectBodyUnavailable, RedirectLoop, TooManyRedirects20from .exceptions import (21 InvalidURL,22 RedirectBodyUnavailable,23 RedirectLoop,24 TooManyRedirects,25)26from .interfaces import AsyncDispatcher, ConcurrencyBackend, Dispatcher27from .models import (28 URL,29 AsyncRequest,
94 unmodified lines
124 if auth is None:125 auth = self.auth126127 url = request.url128129 if url.scheme not in ("http", "https"):130 raise InvalidURL('URL scheme must be "http" or "https".')131132 if auth is None and (url.username or url.password):133 auth = HTTPBasicAuth(username=url.username, password=url.password)134135 if auth is not None:
760 unmodified lines
modified:http3/config.py+4 added
3 unmodified lines
4import typing56import certifi78from .__version__ import __version__910CertTypes = typing.Union[str, typing.Tuple[str, str]]11VerifyTypes = typing.Union[str, bool]12TimeoutTypes = typing.Union[float, typing.Tuple[float, float, float], "TimeoutConfig"]131415USER_AGENT = f"python-http3/{__version__}"1617DEFAULT_CIPHERS = ":".join(18 [19 "ECDHE+AESGCM",20 "ECDHE+CHACHA20",
196 unmodified lines
modified:http3/models.py+5 added-3 removed
8 unmodified lines
910import chardet11import rfc39861213from .config import USER_AGENT14from .decoders import (15 ACCEPT_ENCODING,16 SUPPORTED_DECODERS,17 Decoder,
85 unmodified lines
103 # 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.")109110 @property
421 unmodified lines
532 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.headers537538 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 lines
548 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"))554555 for item in reversed(auto_headers):556 self.headers.raw.insert(0, item)557
599 unmodified lines
modified:scripts/publish+1 added-1 removed
1#!/bin/sh -e23export PACKAGE="http3"4export VERSION=`cat ${PACKAGE}/__init__.py | grep __version__ | sed "s/__version__ = //" | sed "s/'//g"`4export VERSION=`cat ${PACKAGE}/__version__.py | grep __version__ | sed "s/__version__ = //" | sed "s/'//g"`5export PREFIX=""6if [ -d 'venv' ] ; then7 export PREFIX="venv/bin/"8fi
20 unmodified lines
modified:tests/models/test_requests.py-3 removed
85 unmodified lines
86 with pytest.raises(http3.InvalidURL):87 http3.Request("GET", "example.org")8889 with pytest.raises(http3.InvalidURL):90 http3.Request("GET", "invalid://example.org")9192 with pytest.raises(http3.InvalidURL):90 http3.Request("GET", "http:///foo")
modified:tests/test_api.py+6 added
81 unmodified lines
82def test_delete(server):83 response = http3.delete("http://127.0.0.1:8000/")84 assert response.status_code == 20085 assert response.reason_phrase == "OK"868788@threadpool89def test_get_invalid_url(server):90 with pytest.raises(http3.InvalidURL):91 http3.get("invalid://example.org")