Commit Graph

454 Commits

Author SHA1 Message Date
Tom Christie
b43af721cd
Treat warnings as errors (#1687)
* Treat warnings as errors

* Defensive programming in Client.__del__ to avoid possible warnings on partially initialized instances

* Linting

* Ignore linting getattr errors in __del__

* getattr requires a default

* Tighten up closing of auth_flow generators

* Switch multipart test to open file in a context manager

* Ignore warnings on uvicorn

* Drop -Werror from addopts

* Warings specified entirely in 'filterwarnings' section

* Use ssl.PROTOCOL_TLS_CLIENT instead of deprecated ssl.PROTOCOL_TLS

* Push 'check_hostname = False' above 'context.verify_mode = ssl.CERT_NONE'

* Introduce set_minimum_tls_version_1_2 compatible across different python versions

* Commenting

* Add missing annotation

* Exclude _compat from coverage

Co-authored-by: Joe <nigelchiang@outlook.com>
Co-authored-by: jianghang <jianghang@didiglobal.com>
2021-06-16 15:34:12 +01:00
Marcelo Trylesinski
3231211aa3
👷 Add Python 3.10 beta to the CI (#1682)
* 👷 Add Python 3.10 beta to the CI
* ⬆️ Upgrade pytest from 5.* to 6.*
2021-06-15 11:59:30 +01:00
Tom Christie
2129a9789a
Prefer Content-Length over Transfer-Encoding: chunked for content=<file-like> cases. (#1619)
* Add failing test case for 'content=io.BytesIO(...)'

* Refactor peek_filelike_length to return an Optional[int]

* Peek filelength on file-like objects when rendering 'content=...'
2021-04-30 10:40:42 +01:00
Tom Christie
760af43b4f
Update brotli support to use the brotlicffi package (#1605)
* Update brotli support to use the brotlicffi package
2021-04-28 10:09:29 +01:00
Tom Christie
0a8b44e67d
Perform port normalization for http, https, ws, wss, and ftp schemes (#1603) 2021-04-27 14:06:23 +01:00
Tom Christie
e67b0dd15b
Expand URL interface (#1601)
* Expand URL interface

* Add URL query param manipulation methods
2021-04-27 09:01:14 +01:00
Tom Christie
2abb2f214a
Immutable QueryParams (#1600)
* Tweak QueryParams implementation

* Immutable QueryParams
2021-04-26 14:57:02 +01:00
Tom Christie
8fe32c52de
Tweak QueryParams implementation (#1598) 2021-04-26 14:06:12 +01:00
Tom Christie
6e55ca1af9
Escalate 0.17 deprecation warnings to becoming fully deprecated. (#1597) 2021-04-26 11:03:11 +01:00
Tom Christie
39d8ee619e
Differentiate between 'url.host' and 'url.raw_host' (#1590)
* Differentiate between 'url.host' and 'url.raw_host'
2021-04-23 11:00:53 +01:00
Tom Christie
d98e9e7ae7
Support HTTPCore 0.13 (#1588)
* Support HTTPCore 0.13

* Update httpcore minimum version

* Call into 'handle_async_request', not 'arequest'

* Drop unintentional commit

* Update tests
2021-04-21 14:43:18 +01:00
Hannes Ljungberg
2d571046e1
Make Request and Response picklable (#1579)
* Make Request and Response picklable

* fixup! Make Request and Response picklable

* Apply suggestions from code review

* Apply suggestions from code review

* Update tests/models/test_requests.py

Co-authored-by: Tom Christie <tom@tomchristie.com>
2021-04-21 11:11:00 +01:00
Tom Christie
9b8f5af759
httpx.ResponseClosed -> httpx.StreamClosed (#1584)
* ResponseClosed -> StreamClosed

* Update docs for StreamClosed
2021-04-21 10:51:35 +01:00
Tom Christie
6a99f6f2b3
Deprecate per-request cookies (#1574)
* Deprecate per-request cookies

* Update docs/compatibility.md

Co-authored-by: Stephen Brown II <Stephen.Brown2@gmail.com>

* Update httpx/_client.py

Co-authored-by: Stephen Brown II <Stephen.Brown2@gmail.com>

* Update compatibility.md

Co-authored-by: Stephen Brown II <Stephen.Brown2@gmail.com>
2021-04-19 11:18:32 +01:00
Tom Christie
966550b342
For non-streaming cases, populate request.content automatically. (#1583)
* For non-streaming cases, populate request.content

* Linting
2021-04-19 11:13:45 +01:00
Tom Christie
397aad98fd
Escalate the distinction between data=... and content=... to be stricter (#1573) 2021-04-16 10:06:12 +01:00
Tom Christie
073a3284ab
Drop 'Response(on_close=...)' from API (#1572) 2021-04-16 10:03:37 +01:00
Tom Christie
110ce85652
Stream interface (#1550)
* Add SyncByteStream, AsyncByteStream to interface

* request.stream and response.stream as httpx.SyncByteStream/httpx.AsyncByteStream

* Update httpx/_transports/base.py

Co-authored-by: Florimond Manca <florimond.manca@gmail.com>

* Update httpx/_transports/default.py

Co-authored-by: Florimond Manca <florimond.manca@gmail.com>

* Move response classes in transports to module level

Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
2021-04-13 13:14:04 +01:00
Jonas Lundberg
52dd95fb5c
Fix extenstions typo in AsyncHTTPTransport (#1549) 2021-04-01 15:32:20 +01:00
Tom Christie
c26425aa58
Handle data={"key": [None|int|float|bool]} cases. (#1539)
* Fix Content-Length for unicode file contents with multipart

* Handle bool and None cases for URLEncoded data

* Handle int, float, bool, and None for multipart or urlencoded data

* Update httpx/_utils.py

Co-authored-by: Florimond Manca <florimond.manca@gmail.com>

Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
2021-03-26 12:54:04 +00:00
Tom Christie
c75ddc26c7
Fix Content-Length for unicode file contents with multipart (#1537) 2021-03-25 15:35:02 +00:00
Tom Christie
1a6e254f72
Transport API (#1522)
* Added httpx.BaseTransport and httpx.AsyncBaseTransport

* Test coverage and default transports to calling .close on __exit__

* BaseTransport documentation

* Use 'handle_request' for the transport API.

* Docs tweaks

* Docs tweaks

* Minor docstring tweak

* Transport API docs

* Drop 'Optional' on Transport API

* Docs tweaks

* Tweak CHANGELOG

* Drop erronous example.py

* Push httpcore exception wrapping out of client into transport (#1524)

* Push httpcore exception wrapping out of client into transport

* Include close/aclose extensions in docstring

* Comment about the request property on RequestError exceptions

* Extensions reason_phrase and http_version as bytes (#1526)

* Extensions reason_phrase and http_version as bytes

* Update BaseTransport docstring

* Neaten up our try...except structure for ensuring responses (#1525)

* Fix CHANGELOG typo

Co-authored-by: Florimond Manca <florimond.manca@gmail.com>

* Fix CHANGELOG typo

Co-authored-by: Florimond Manca <florimond.manca@gmail.com>

* stream: Iterator[bytes] -> stream: Iterable[bytes]

* Use proper bytestream interfaces when calling into httpcore

* Grungy typing workaround due to httpcore using Iterator instead of Iterable in bytestream types

* Update docs/advanced.md

Co-authored-by: Florimond Manca <florimond.manca@gmail.com>

* Consistent typing imports across tranports

* Update docs/advanced.md

Co-authored-by: Florimond Manca <florimond.manca@gmail.com>

Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
2021-03-24 12:36:34 +00:00
Tom Christie
6cb1672459
Fix some cases of merging with base_url (#1532)
* Fix some cases of merging with base_url

* Fix for joining relative URLs

* Improve code comment in _merge_url implementation
2021-03-24 10:51:33 +00:00
Adam Hooper
0f280af8b1
map_exceptions in request.aclose() (#1465)
* map_exceptions in request.aclose()
2021-02-17 11:32:43 +00:00
Tom Christie
084f35648b
Allow handler to optionally be async when MockTransport is used with AsyncClient (#1449) 2021-02-17 11:10:21 +00:00
Aber
02a692aba5
Handle default ports in WSGITransport (#1469)
* Maybe port is `None`

https://www.python.org/dev/peps/pep-3333/#environ-variables

> SERVER_NAME, SERVER_PORT
> When HTTP_HOST is not set, these variables can be combined to determine a default. See the URL Reconstruction section below for more detail. SERVER_NAME and SERVER_PORT are required strings and must never be empty.

* Add unit test

* Compute default port

Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
2021-02-16 13:33:17 +01:00
Tom Christie
89fb0cbc69
Add HTTPTransport and AsyncHTTPTransport (#1399)
* Add keepalive_expiry to Limits config

* keepalive_expiry should be optional. In line with httpcore.

* HTTPTransport and AsyncHTTPTransport

* Update docs for httpx.HTTPTransport()

* Update type hints

* Fix docs typo

* Additional mount example

* Tweak context manager methods

* Add 'httpx.HTTPTransport(proxy=...)'

* Use explicit keyword arguments throughout httpx.HTTPTransport

Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
2021-01-08 10:23:56 +00:00
Tom Christie
9c7c2ace99
Add httpx.MockTransport() (#1401)
* Add httpx.MockTransport

* Add docs on MockTransport

* Add pointer to RESPX

* Add note on pytest-httpx

* Tweak existing docs example to use 'httpx.MockTransport'

Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
2021-01-06 11:04:26 +00:00
SarunasAzna
86964054d6
Allow tuple as input of query parameters. (#1426)
* Allow tuple as input of query parameters.

In the documentation it is stated that params can be dict, string or two
tuples. This allows to used two tuples. Previously it was possible to
use only tuple inside a list.

* tests for two tuples

* use isinstance to check the type of query params

* change list|tuple to in Sequence

* update documentation

* fix typing
2020-12-12 18:38:37 +01:00
Andrés Álvarez
28cbe77676
Add repr to Cookies for displaying available cookies (#1411)
* Add repr to Cookies for displaying available cookies

* Add unit test

* Simplify repr

* Remove file
2020-12-03 22:06:42 +01:00
Florimond Manca
9005bd5df6
Properly encoded slashes when using base_url (#1407) 2020-12-02 13:01:11 +00:00
Tom Christie
d0835da230
Add keepalive_expiry to Limits config (#1398)
* Add keepalive_expiry to Limits config

* keepalive_expiry should be optional. In line with httpcore.
2020-11-25 15:32:37 +00:00
Tom Christie
27df5e49c7
Support for chunk_size (#1277)
* Support iter_raw(chunk_size=...) and aiter_raw(chunk_size=...)

* Unit tests for ByteChunker

* Support iter_bytes(chunk_size=...)

* Add TextChunker

* Support iter_text(chunk_size=...)

* Fix merge with master

Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
2020-11-25 15:28:06 +00:00
Tom Christie
c4d2e6fa28
Add support for Mount API (#1362)
* Add support for Mount API

* Add test cases

* Add test case for all: mounted transport

* Use 'transport' variable, in preference to 'proxy'

* Add docs for mounted transports
2020-11-24 10:35:51 +00:00
plotski
589c6e0f2f
Include invalid name/value when raising TypeError in DataField (#1368) 2020-11-05 10:46:22 +00:00
Florimond Manca
2f54548dad
Drop unecessary host="localhost" in https_server fixture to fix CI build (#1367) 2020-10-24 23:25:31 +02:00
Tom Christie
07229b8dff
Close AsyncClient properly in test_async_next_request (#1361) 2020-10-14 08:38:53 +02:00
Simon Willison
ca5f524943
Add raw_path to scope in ASGITransport (#1357)
* Add raw_path to scope in ASGITransport, closes #1356

* Tweaked test
2020-10-09 16:46:26 +01:00
Tom Christie
0123bca335
Force lowercase ASGI headers (#1351)
Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
2020-10-08 12:04:10 +01:00
cdeler
7fda99fcef
Correctly handle ipv6 addresses as a part of URL (#1349)
* Correctly handle ipv6 addresses as a host

* Fixed typo

* Added an extra rfc reference

* Update tests/models/test_url.py

* Update tests/models/test_url.py
2020-10-08 11:37:13 +03:00
Tom Christie
c725387b2d
Preserve header casing (#1338) 2020-10-06 14:57:10 +01:00
Tom Christie
0eed6a3734
Drop .next()/.anext() in favour of response.next_request (#1339)
* Drop response.next()/response.anext() in favour of response.next_request

* Drop NotRedirectResponse
2020-10-06 14:53:07 +01:00
Tom Christie
2a2bbe58a6
Tighten client closed-state behaviour (#1346)
Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
2020-10-06 13:38:05 +01:00
Tom Christie
3f51392bea
Add response.next_request (#1334)
* Add response.next_request

* Add response.next_request

* Add response.next_request to the docs
2020-10-01 13:52:03 +01:00
Musale Martin
815ef94ed9
Support header comparisons with dict or list. (#1326)
* Support header comparisons with dict or list.

* Add check for no headers item

* Fixup testcases affected by headers comparison using dict or list

* Update test_responses.py

Co-authored-by: Tom Christie <tom@tomchristie.com>
2020-09-25 12:28:34 +01:00
Tom Christie
666cbbdfe8
Fix automatic .read() when Response instances are created with content=<str> (#1324) 2020-09-25 11:29:17 +01:00
Tom Christie
320bfe1d0e
Fix warning test case (#1322) 2020-09-24 18:50:30 +02:00
Tom Christie
d25f2bfeff
Fix stream unsetting auth (#1312)
* Fix ASGITransport path escaping

* Add failing test case for auth with streaming

* Fix .stream setting auth=None
2020-09-23 11:25:54 +01:00
Tom Christie
e53f995994
Fix ASGITransport path escaping (#1307) 2020-09-23 09:37:19 +01:00
Tom Christie
f932af9172
Version 0.15.0 (#1301)
* Version 0.15.0

* Update CHANGELOG.md

Co-authored-by: Jamie Hewland <jamie.hewland@hpe.com>

* Escalate deprecations into removals.

* Deprecate overly verbose timeout parameter names

* Fully deprecate max_keepalive in favour of explicit max_keepalive_connections

* Fully deprecate PoolLimits in favour of Limits

* Deprecate instantiating 'Timeout' without fully explicit values

* Include deprecation notes in changelog

* Use httpcore 0.11.x

Co-authored-by: Jamie Hewland <jamie.hewland@hpe.com>
2020-09-22 11:44:28 +01:00