]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Minor tweaks in line with requests behavior (#110) 0.6.6
authorTom Christie <tom@tomchristie.com>
Wed, 3 Jul 2019 09:33:38 +0000 (10:33 +0100)
committerGitHub <noreply@github.com>
Wed, 3 Jul 2019 09:33:38 +0000 (10:33 +0100)
http3/__init__.py
http3/__version__.py [new file with mode: 0644]
http3/client.py
http3/config.py
http3/models.py
scripts/publish
tests/models/test_requests.py
tests/test_api.py

index 95b5e14509d8ae917dccd2edb6d032f4bb1332f9..abc03caf58b2e9185957262bdbae1d2892bcc6f9 100644 (file)
@@ -1,7 +1,9 @@
+from .__version__ import __description__, __title__, __version__
 from .api import delete, get, head, options, patch, post, put, request
 from .client import AsyncClient, Client
 from .concurrency import AsyncioBackend
 from .config import (
+    USER_AGENT,
     CertTypes,
     PoolLimits,
     SSLConfig,
@@ -39,14 +41,22 @@ from .interfaces import (
 from .models import (
     URL,
     AsyncRequest,
+    AsyncRequestData,
     AsyncResponse,
+    AsyncResponseContent,
+    AuthTypes,
     Cookies,
+    CookieTypes,
     Headers,
+    HeaderTypes,
     Origin,
     QueryParams,
+    QueryParamTypes,
     Request,
+    RequestData,
+    RequestFiles,
     Response,
+    ResponseContent,
+    URLTypes,
 )
 from .status_codes import StatusCode, codes
-
-__version__ = "0.6.5"
diff --git a/http3/__version__.py b/http3/__version__.py
new file mode 100644 (file)
index 0000000..2669a52
--- /dev/null
@@ -0,0 +1,3 @@
+__title__ = "http3"
+__description__ = "A next generation HTTP client, for Python 3."
+__version__ = "0.6.6"
index 69b96b252a43514ce338ccefe07ec7a35e7fbd04..36569da23ceb395f618af5f00f814a4762ae5412 100644 (file)
@@ -17,7 +17,12 @@ from .dispatch.asgi import ASGIDispatch
 from .dispatch.connection_pool import ConnectionPool
 from .dispatch.threaded import ThreadedDispatcher
 from .dispatch.wsgi import WSGIDispatch
-from .exceptions import RedirectBodyUnavailable, RedirectLoop, TooManyRedirects
+from .exceptions import (
+    InvalidURL,
+    RedirectBodyUnavailable,
+    RedirectLoop,
+    TooManyRedirects,
+)
 from .interfaces import AsyncDispatcher, ConcurrencyBackend, Dispatcher
 from .models import (
     URL,
@@ -120,6 +125,10 @@ class BaseClient:
             auth = self.auth
 
         url = request.url
+
+        if url.scheme not in ("http", "https"):
+            raise InvalidURL('URL scheme must be "http" or "https".')
+
         if auth is None and (url.username or url.password):
             auth = HTTPBasicAuth(username=url.username, password=url.password)
 
index 778051bac58992f7cb10357c57c3fdb867d5afc9..4b0fe9e28bc3c12d0c61ec6040fba87f549bc110 100644 (file)
@@ -5,11 +5,15 @@ import typing
 
 import certifi
 
+from .__version__ import __version__
+
 CertTypes = typing.Union[str, typing.Tuple[str, str]]
 VerifyTypes = typing.Union[str, bool]
 TimeoutTypes = typing.Union[float, typing.Tuple[float, float, float], "TimeoutConfig"]
 
 
+USER_AGENT = f"python-http3/{__version__}"
+
 DEFAULT_CIPHERS = ":".join(
     [
         "ECDHE+AESGCM",
index 1b5bb152e17fca6a4529f5c0a4d7109440cadceb..7981270eb97e37a09747c6e0978364e95e8b397b 100644 (file)
@@ -10,6 +10,7 @@ from urllib.parse import parse_qsl, urlencode
 import chardet
 import rfc3986
 
+from .config import USER_AGENT
 from .decoders import (
     ACCEPT_ENCODING,
     SUPPORTED_DECODERS,
@@ -103,8 +104,6 @@ class URL:
         if not allow_relative:
             if not self.scheme:
                 raise InvalidURL("No scheme included in URL.")
-            if self.scheme not in ("http", "https"):
-                raise InvalidURL('URL scheme must be "http" or "https".')
             if not self.host:
                 raise InvalidURL("No host included in URL.")
 
@@ -534,11 +533,12 @@ class BaseRequest:
             "content-length" in self.headers or "transfer-encoding" in self.headers
         )
         has_accept_encoding = "accept-encoding" in self.headers
+        has_connection = "connection" in self.headers
 
         if not has_host:
             auto_headers.append((b"host", self.url.authority.encode("ascii")))
         if not has_user_agent:
-            auto_headers.append((b"user-agent", b"http3"))
+            auto_headers.append((b"user-agent", USER_AGENT.encode("ascii")))
         if not has_accept:
             auto_headers.append((b"accept", b"*/*"))
         if not has_content_length:
@@ -549,6 +549,8 @@ class BaseRequest:
                 auto_headers.append((b"content-length", content_length))
         if not has_accept_encoding:
             auto_headers.append((b"accept-encoding", ACCEPT_ENCODING.encode()))
+        if not has_connection:
+            auto_headers.append((b"connection", b"keep-alive"))
 
         for item in reversed(auto_headers):
             self.headers.raw.insert(0, item)
index 9ec45d54536b6b2e694aa0900e2603d0d57a0477..cb02ec8f642dfb9558677d727373e6282d88f730 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh -e
 
 export PACKAGE="http3"
-export VERSION=`cat ${PACKAGE}/__init__.py | grep __version__ | sed "s/__version__ = //" | sed "s/'//g"`
+export VERSION=`cat ${PACKAGE}/__version__.py | grep __version__ | sed "s/__version__ = //" | sed "s/'//g"`
 export PREFIX=""
 if [ -d 'venv' ] ; then
     export PREFIX="venv/bin/"
index b5126bc70042782b2a730087b479a9cb18912e9b..6669801070911f0d52c3ef81acd0d87630e2ce11 100644 (file)
@@ -86,8 +86,5 @@ def test_invalid_urls():
     with pytest.raises(http3.InvalidURL):
         http3.Request("GET", "example.org")
 
-    with pytest.raises(http3.InvalidURL):
-        http3.Request("GET", "invalid://example.org")
-
     with pytest.raises(http3.InvalidURL):
         http3.Request("GET", "http:///foo")
index b417a817ec9d5c485af50c591b79d9e38ffddcca..0f89e56228a94721cf3d57af6f7bbd6fbb66d473 100644 (file)
@@ -83,3 +83,9 @@ def test_delete(server):
     response = http3.delete("http://127.0.0.1:8000/")
     assert response.status_code == 200
     assert response.reason_phrase == "OK"
+
+
+@threadpool
+def test_get_invalid_url(server):
+    with pytest.raises(http3.InvalidURL):
+        http3.get("invalid://example.org")