Commit Graph

203 Commits

Author SHA1 Message Date
Marcelo Trylesinski
daec2bdcdb
Use ruff instead of flake8, autoflake and isort (#2648)
* Use ruff instead of flake8, autoflake and isort

* Update pyproject.toml
2023-04-05 12:37:10 +02: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
Tom Christie
59914c7690
Add NetRCAuth() class. (#2535)
* NetRCAuth class

* Add docs for httpx.NetRCAuth()

* Drop failing cross-domain test for NetRCAuth()

* Update tests

* Update httpx/_auth.py

* Add tests for netrc file with no password
2023-01-12 11:27:46 +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
Tom Christie
7985f685ca
Use consistent import style (#2493) 2022-12-06 11:58: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
Martijn Pieters
049afe5b25
Typing: enable disallow_incomplete_defs (#2476)
The only places mypy reports issues is in the test suite.
2022-11-30 09:04:54 +00:00
rettier
8327e13454
reuse the digest auth state to avoid unnecessary requests (#2463)
* reuse the digest auth challenge to avoid sending twice as many requests

* fix for digest testcase

* ran testing/linting scripts

* codereview changes, removed tomchristie username from all authentication tests

Co-authored-by: Philipp Reitter <p.reitter@accessio.at>
Co-authored-by: Tom Christie <tom@tomchristie.com>
2022-11-29 17:05:37 +00:00
Adrian Garcia Badaracco
1b4e7fbb48
Typing: always fill in generic type parameters (#2468)
* Typing: always fill in generic type parameters

Being explicit about the parameters helps find bugs and makes the library
easier to use for users.

- Tell mypy to disallow generics without parameter values
- Give all generic types parameters values

* fix things that aren't coming in from other commits

* lint

Co-authored-by: Martijn Pieters <mj@zopatista.com>
Co-authored-by: Tom Christie <tom@tomchristie.com>
2022-11-29 16:36:03 +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
Tom Christie
9baf3a6cd2
Drop RawURL (#2241) 2022-05-30 14:54:47 +01:00
Tom Christie
1c33a2854e
Make charset auto-detection optional. (#2165)
* Add Response(..., default_encoding=...)

* Add tests for Response(..., default_encoding=...)

* Add Client(..., default_encoding=...)

* Switch default encoding to 'utf-8' instead of 'autodetect'

* Make charset_normalizer an optional dependancy, not a mandatory one.

* Documentation

* Use callable for default_encoding

* Update tests for new charset autodetection API

* Update docs for new charset autodetection API

* Update requirements

* Drop charset_normalizer from requirements
2022-05-23 16:27:32 +01:00
Tom Christie
3350d7e683
Close responses when on cancellations occur during reading. (#2156)
* Test case for clean stream closing on cancellations

* Test case for clean stream closing on cancellations

* Linting on tests

* responses should close on any BaseException
2022-03-31 13:41:40 +01: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
Adrian Garcia Badaracco
321d4aa509
Fix Headers.update to correctly handle repeated headers (#2038) 2022-01-21 08:35:10 -08:00
Tom Christie
8dc9b6bd59
SOCKS proxy support (#2034) 2022-01-19 14:58:19 +00:00
Tom Christie
7f0d43daad
Dont perform implicit close/warning on __del__ (#2026)
* Version 0.21.3

* Don't perform implict close on __del__
2022-01-13 10:37:37 +00:00
Kian Meng, Ang
82ba15b521
Fix typos (#1968) 2021-12-14 15:04:01 +01:00
Tom Christie
61188feeae
Version 0.21 (#1935)
* Integrate with httpcore 0.14

* Fix pool timeout test

* Add request extensions to API

* Add certificate and connection info to client, using 'trace' extension

* Fix test_pool_timeout flakiness
2021-11-15 14:30:54 +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
2d9c3580e0
Switch event hooks to also run on redirects. (#1806)
* Switch event hooks to also run on redirects

* Bump coverage

* Add pragma: no cover, because sometime ya just gotta be pragmatic

* Update docs with note about response.read()
2021-08-18 15:12:39 +01:00
Tom Christie
927c88d34f
Stricter enforcement of either 'with httpx.Client() as client' or 'client = httpx.Client()' lifespan styles. (#1800) 2021-08-13 15:17:15 +01:00
Antonio Larrosa
77193b2ab6
Add a network pytest mark for tests that use the network (#1669)
* Add a network pytest mark for tests that use the network

Sometimes it's useful to have the tests that use the network
marked so they can be skipped easily when we know the network
is not available.

This is useful for example on SUSE and openSUSE's build servers.
When building the httpx packages (actually, any package in the
distribution) the network is disabled so we can assure
reproducible builds (among other benefits). With this mark, it's
easier to skip tests that can not succeed.

* Add a better explanation for the network marker

Co-authored-by: Florimond Manca <15911462+florimondmanca@users.noreply.github.com>

Co-authored-by: Joe <nigelchiang@outlook.com>
Co-authored-by: Florimond Manca <15911462+florimondmanca@users.noreply.github.com>
Co-authored-by: Tom Christie <tom@tomchristie.com>
2021-08-13 14:13:43 +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
6e55ca1af9
Escalate 0.17 deprecation warnings to becoming fully deprecated. (#1597) 2021-04-26 11:03:11 +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
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
Jonas Lundberg
52dd95fb5c
Fix extenstions typo in AsyncHTTPTransport (#1549) 2021-04-01 15:32:20 +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
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
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
Florimond Manca
9005bd5df6
Properly encoded slashes when using base_url (#1407) 2020-12-02 13:01:11 +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
Tom Christie
07229b8dff
Close AsyncClient properly in test_async_next_request (#1361) 2020-10-14 08:38:53 +02: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
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
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
54f7708e2b
Event hooks (#1246)
* Add EventHooks internal datastructure

* Add support for 'request' and 'response' event hooks

* Support Client.event_hooks property

* Handle exceptions raised by response event hooks

* Docs for event hooks

* Only support 'request' and 'response' event hooks

* Add event_hooks to top-level API

* Event hooks

* Formatting

* Formatting

* Fix up event hooks test

* Add test case to confirm that redirects/event hooks don't currently play together correctly

* Refactor test cases

* Make response.request clear in response event hooks docs

* Drop merge marker

* Request event hook runs as soon as we have an auth-constructed request
2020-09-15 12:05:39 +01:00