Commit Graph

69 Commits

Author SHA1 Message Date
James Braza
2318fd822c
Enabling ruff C416 (#3001)
* Enabled C416 in ruff

* Ran ruff on all files

* Ran ruff format

* Update pyproject.toml

---------

Co-authored-by: Tom Christie <tom@tomchristie.com>
2023-12-13 11:30:39 +00:00
Adrian Garcia Badaracco
f0fd91925b
fix type annotation for MockTransport (#2581)
* fix type annotation for MockTransport

* add type ignore

* better type checks

* better type checks

* add pragma

---------

Co-authored-by: Tom Christie <tom@tomchristie.com>
2023-02-09 16:05:07 +00:00
Thomas Grainger
e27d1b8333
replace pytest-asyncio and pytest-trio with anyio (#2512)
* replace pytest-asyncio with anyio

* remove pytest-trio also

* Update setup.cfg

* use anyio.Lock in test_auth

Co-authored-by: Tom Christie <tom@tomchristie.com>
2023-01-02 12:53:30 +00:00
Martijn Pieters
933551c519
Typing: enable disallow_untyped_calls (#2479)
* Typing: enable disallow_untyped_calls

Only the test suite needed adjusting to add type hints.

* Update setup.cfg

Co-authored-by: Tom Christie <tom@tomchristie.com>
2022-12-02 10:47:42 +00:00
Adrian Garcia Badaracco
16e2830624
use # pragma: no cover instead of # pragma: nocover (#2471)
Co-authored-by: Tom Christie <tom@tomchristie.com>
2022-11-29 10:23:18 -06:00
waterfountain1996
4401d55ecf
Preserve Authorization header on HTTPS redirect (#1850) (#2074)
* Preserve Authorization header on HTTPS redirect (#1850)

* Update httpx/_client.py

Co-authored-by: Tom Christie <tom@tomchristie.com>
2022-02-09 11:18:21 +00:00
Tom Christie
ff9813e84d
Transport API as plain request -> response method. (#1840)
* Responses as context managers

* timeout -> request.extensions

* Transport API -> request/response signature

* Fix top-level httpx.stream()

* Drop response context manager methods

* Simplify ASGI tests

* Black formatting
2021-09-13 13:34:46 +01:00
Tom Christie
47266d763b
Switch follow redirects default (#1808)
* Switch default on allow_redirects to False

* allow_redirects -> follow_redirects

* Update follow_redirects default in top-level API

* Update docs on follow_redirects
2021-09-13 13:21:22 +01: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
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
Tom Christie
07229b8dff
Close AsyncClient properly in test_async_next_request (#1361) 2020-10-14 08:38:53 +02: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
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
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
Tom Christie
f3c29416f1
Support Response(text=...), Response(html=...), Response(json=...) (#1297)
* Refactor content_streams internally

* Tidy up multipart

* Use ByteStream annotation internally

* Support Response(text=...), Response(html=...), Response(json=...)

* Add tests for Response(text=..., html=..., json=...)
2020-09-21 11:19:19 +01:00
Tom Christie
fbb21fb1ae
Drop ContentStream (#1295)
* Drop ContentStream
2020-09-18 08:41:09 +01:00
Tom Christie
feb404f86b
Seperate content=... and data=... parameters (#1266)
* Seperate content=... and data=... parameters

* Update compatibility.md
2020-09-15 13:36:10 +01:00
Tom Christie
c2afd2d9bf
Refactor tests to use MockTransport(<handler_function>) (#1281)
* Support Response(content=<bytes iterator>)

* Update test for merged master

* Add MockTransport for test cases

* Use MockTransport for redirect tests

* Reduce change footprint

* Reduce change footprint

* Clean up headers slightly

* Update requirements.txt

Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
2020-09-12 11:16:10 +01:00
Tom Christie
4d950e5780
Swap auth/redirects ordering (#1267)
* Internal refactoring to swap auth/redirects ordering

* Test for auth with cross domain redirect
2020-09-10 09:12:05 +01:00
Eduardo Enriquez
aad8209928
Replace httpx.URL for str in tests (#1237)
Co-authored-by: Eduardo Enriquez (eduzen) <eduardo.enriquez@freshbooks.com>
2020-08-30 08:01:37 +02:00
Tom Christie
28c72050e0
Better test case consistency. Prefer import httpx and httpx.Client. (#1222)
* Prefer httpx.Client over httpx.AsyncClient in test cases, unless required.

* Prefer httpx.Client in test_headers

* Consistent httpx imports and httpx.Client usage

* Use 'import httpx' consistently in tests. Prefer httpx.Client.
2020-08-26 14:10:23 +01:00
Florimond Manca
09c3e90e3b
Add test for HEAD redirect behavior (#1184) 2020-08-16 08:12:17 +02:00
Joe
45de714592
Map rfc3986 exceptions (#1163)
* Map rfc3896 exceptions
2020-08-11 09:44:56 +01:00
Tom Christie
876e722b24
Update to httpcore 0.10 (#1126)
* Keep HTTPError as a base class for .request() and .raise_for_status()

* Updates for httpcore 0.10

* Update httpx/_exceptions.py

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

* Use httpcore.SimpleByteStream/httpcore.IteratorByteStream

* Use httpcore.PlainByteStream

* Merge master

* Update to httpcore 0.10.x

Co-authored-by: Stephen Brown II <Stephen.Brown2@gmail.com>
2020-08-07 14:14:11 +01:00
Tom Christie
c089480260
URL.port becomes Optional[int] (#1080)
* URL.port becomes Optional[int], not int

* Minor _transport_for_url refactor

* Add docstring
2020-07-24 11:42:13 +01:00
Florimond Manca
0296c2bbb9
Type check tests (#1054) 2020-07-07 11:10:43 +02:00
Florimond Manca
3230cb3133
Add missing Response.next() (#1055) 2020-07-07 10:54:50 +02:00
Taneli Hukkinen
6cf9039593
Improve list/dict comprehensions (#1036)
* Improve list/dict comprehensions

* Dont make needless list() conversions before bytes.join()

Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
2020-07-02 17:45:00 +02:00
Josep Cugat
620b0670db
Increase test coverage - take 2 (#1012)
* Fix HttpError -> HTTPError typo

* Increased test coverage

* Increase coverage threshold

* Reuse sync/async transport code in test_auth.py

* Removed close_client check inside StreamContextManager

It's never set as True when used in async

* Reuse sync/async transport code in test_redirects.py
2020-06-02 10:24:45 +01:00
Josep Cugat
89a8100b6c
Replace remaining occurrences of dispatch with transport (#1010)
* Replace remaining occurrences of dispatch with transport

* Remove unused AsyncDispatcher

Was removed in #804

* Remove hard_limit warning in test
2020-05-30 23:18:48 +02:00
Josep Cugat
093cb42500
Improve error when redirecting with custom schemes (#1002)
Fixes #822
2020-05-28 13:11:17 +02:00
Tom Christie
3046e920ea
Httpcore interface (#804)
* First pass as switching dispatchers over to httpcore interface

* Updates for httpcore interface

* headers in dispatch API as plain list of bytes

* Integrate against httpcore 0.6

* Integrate against httpcore interface

* Drop UDS, since not supported by httpcore

* Fix base class for mock dispatchers in tests

* Merge master and mark as potential '0.13.dev0' release
2020-04-08 13:32:10 +01:00
Tom Christie
631ba97635
Revert "Add content-length header for empty bytestream (#866)" (#898)
This reverts commit 939f3ce7ce.
2020-04-08 13:15:22 +01:00
Dima Boger
939f3ce7ce
Add content-length header for empty bytestream (#866)
Also, fixed related tests
2020-03-28 16:05:06 +01:00
Piotr Staroszczyk
efe9f61bc2
Drop RedirectLoop exception (#819)
* drop RedirectLoop exception

* tests is package to allow run it easly

* bring back test for redirect loop
2020-02-24 10:09:52 +00:00
Florimond Manca
82dc6f32f8 Switch to private module names (#785)
* Rename modules

* Update names in package

* Fix tests

* Review docs
2020-01-28 14:34:43 +00:00
Tom Christie
1f8fb28d93
Handle redirect with malformed Location headers missing host. (#774) 2020-01-17 11:42:51 +00:00
Tom Christie
5a63540e8a
Fix for streaming a redirect response body with allow_redirects=False (#766) 2020-01-17 09:45:37 +00:00
Tom Christie
e19bd9bc4b
Dispatcher -> AsyncDispatcher (#725)
* Dispatcher -> AsyncDispatcher

* Fix invalid renamings

* Fix invalid renamings
2020-01-06 12:08:14 +00:00
Florimond Manca
910aa9094c
Repurpose RedirectBodyUnavailable as RequestBodyUnavailable (#690) 2020-01-03 22:25:55 +01:00
Tom Christie
b8394f1e00
Bump coverage (#705)
* Bump coverage

* Tests for iterative text decoding with 'aiter_text'

* nocover on xfail exception cases

* nocover API that is pending deprecation

* Tweak test to removed uncovered line

* Ingest request body in RedirectBodyUnavailable test case
2020-01-01 15:33:24 +00:00
Florimond Manca
e284b84bf9 Rename Client to AsyncClient (with compat synonym) (#680)
* Rename Client to AsyncClient (with compat synonym)

* Document motivation for AsyncClient renaming

Co-authored-by: Tom Christie <tom@tomchristie.com>
2019-12-29 15:34:23 +00:00
Florimond Manca
3462999366 Rename 'next' to 'anext' on Response (#676)
* Rename 'next' to 'anext' on Response

* Drop iscoroutinefunction() check

Co-authored-by: Tom Christie <tom@tomchristie.com>
2019-12-29 15:34:07 +00:00
Florimond Manca
d0427bead0
Clean up 'backend' fixture (#664)
* Clean up 'backend' fixture

* Add docstring to 'async_environment' fixture
2019-12-21 16:08:40 +01:00
Tom Christie
cee1fccaca
Use Streams API for both requests and responses. (#648)
* Internal ContentStreams API
2019-12-20 16:05:04 +00:00
Tom Christie
8d4f182500
Added RequestContent (#636)
* Request Content

* Added RequestContent interface

* Docstrings on 'encode(data, files, json)'

* Update httpx/content.py

Co-Authored-By: Florimond Manca <florimond.manca@gmail.com>

* can_rewind -> can_replay
2019-12-18 10:51:34 +00:00
Florimond Manca
ab41a5d5c3
Refactor tests in the light of backend auto-detection (#615)
* Refactor tests in the light of backend auto-detection

* Test passing explicit backend separately

* Drop 'backend=backend'

* Fix usage of asyncio.run() on 3.6
2019-12-07 15:17:35 +01:00
Tom Christie
d15dc0b1f8
Tighten up top-level API to only expose public API (#608)
* Tighten up top-level API to only expose public API

* Leave HTTPProxyMode for backwards compat, raising warnings.

* Add missing import
2019-12-06 15:20:01 +00:00
Tom Christie
206c5372a6
Drop sync (#544)
Drop sync client
2019-11-27 10:43:42 +00:00
Tom Christie
5aca0c0172
Fix redirect cookie behavior (#529)
* Fix redirect cookie behavior
* Drop flake8-comprehensions
* Add redirect cookie tests
2019-11-15 21:31:15 +00:00