Commit Graph

42 Commits

Author SHA1 Message Date
Tom Christie
47f4a96ffa
Handle empty zstd responses (#3412) 2024-11-22 11:42:51 +00:00
Michiel W. Beijen
392dbe45f0
Add support for zstd decoding (#3139)
This adds support for zstd decoding using the python package zstandard.
This is similar to how it is implemented in urllib3. I also chose the
optional installation option httpx[zstd] to mimic the same option in
urllib3.

zstd decoding is similar to brotli, but in benchmarks it is supposed to
be even faster. The zstd compression is described in RFC 8878.

See https://github.com/encode/httpx/discussions/1986

Co-authored-by: Kamil Monicz <kamil@monicz.dev>
2024-03-21 10:17:15 +00:00
Kar Petrosyan
371b6e946c
Use __future__.annotations (#3068)
* Switch to new typing style

* lint
2024-01-24 14:30:22 +00:00
James Braza
1e11096473
Fixed iter_text adding an empty string (#2998) 2023-12-11 22:34:25 +00:00
Michał Górny
f653b2f0cf
Inline Brotli samples in tests (#2935)
Inline the compressed Brotli samples in tests to make them independent
of Brotli implementation.  This makes it possible to run the test suite
both against Brotli and brotlicffi.

Fixes #2906
2023-11-10 15:07:05 +00:00
Florimond Manca
cca62060cb
Drop private imports from test_decoders.py (#2570)
Co-authored-by: Tom Christie <tom@tomchristie.com>
2023-04-19 14:16:29 +01:00
Gianni Tedesco
85c5898d8e
Change LineDecoder to match stdlib splitlines, resulting in significant speed up (#2423)
* Replace quadratic algo in LineDecoder

Leading to enormous speedups when doing things such as
Response(...).iter_lines() as described on issue #2422

* Update httpx/_decoders.py

* Update _decoders.py

Handle text ending in `\r` more gracefully.
Return as much content as possible.

* Update test_decoders.py

* Update _decoders.py

* Update _decoders.py

* Update _decoders.py

* Update httpx/_decoders.py

Co-authored-by: cdeler <serj.krotov@gmail.com>

* Update _decoders.py

---------

Co-authored-by: Tom Christie <tom@tomchristie.com>
Co-authored-by: cdeler <serj.krotov@gmail.com>
2023-03-16 14:29:15 +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
563a1031f5
Remove some private imports from test_decoders (#2496) 2022-12-06 18:22:04 +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
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
d5143120d1
Use either brotli or brotlicffi. (#1618)
* Use either brotli (recommended for CPython) or brotlicffi (Recommended for PyPy and others)

* Add comments in places where we switch behaviour depending on brotli/brotlicffi

Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
2021-08-13 11:52:45 +01:00
Tom Christie
acb5e6ac50
Add charset_normalizer detection. (#1791)
* Add charset_normalizer detection

* Tweak JSON tests for slightly different charset decoding behaviour

* Add charset-normalizer to docs
2021-08-13 11:38:53 +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
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
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
d0fe113945
Drop chardet (#1269)
* Internal refactoring to swap auth/redirects ordering

* Drop chardet for charset detection

* Drop chardet in favour of simpler charset autodetection

* Revert unintentionally included changes

* Update test case

* Refactor to prefer different decoding style

* Update text decoding docs/docstrings

* Resolve typo

* Update docs/quickstart.md

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

Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
2020-09-15 11:20:19 +01:00
Tom Christie
5ee6135256
Support Response(content=<bytes iterator>) (#1265)
* Support Response(content=<bytes iterator>)

* Update test for merged master
2020-09-11 10:28:18 +01:00
Tom Christie
de502a44c6
Drop Response(..., request=...) style in test cases. (#1243)
* Drop Response(..., request=...) style in test cases except where required

* Lowercase variable name
2020-09-02 10:10:32 +01:00
tbascoul
e0b4528b17
Make the response's request parameter optional (#1238)
* Make the response's request parameter optional

* Fix _models coverage

* Move DecodingError in _models

* Update httpx/_models.py

* Update _models.py

* Update test_responses.py

* Update test_responses.py

Co-authored-by: Tom Christie <tom@tomchristie.com>
2020-09-01 15:14:57 +01:00
Tom Christie
9409900898
Exception hierarchy (#1095)
* Exception heirachy

* Exception heirarchy

* Formatting tweaks

* Update httpx/_exceptions.py

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

* Update httpx/_exceptions.py

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

* Update httpx/_exceptions.py

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

* Update httpx/_exceptions.py

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

Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
2020-07-31 12:57:49 +01:00
Tom Christie
20f4911e80
Fixes for LineDecoding (#1075)
* Fixes #1033 - Ensure that text that spans 3 invocations before newline is handled - don't clobber the buffer between invocations that haven't seen any lines.
This seems like a one character fix + the test.

* Update the tests.

* Undo formatting/indentation.

* Update long comment.

* Fix trailing cr line decoding

Co-authored-by: Sheridan C Rawlins <scr@verizonmedia.com>
2020-07-23 09:45:35 +01:00
Sheridan C Rawlins
ad5e6eb8b0
Fixes #1033 - Ensure that text that spans 3 invocations before newline is handled - don't clobber the buffer between invocations that haven't seen any lines. (#1034)
Fixes #1033 - Ensure that text that spans 3 invocations before newline is handled - don't clobber the buffer between invocations that haven't seen any lines.
2020-07-21 10:33:45 +01: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
780d1843ca
Support both zlib and deflate encodings (#758)
* Support both zlib and deflate encodings

* Helpful test docstrings
2020-01-14 09:00:52 +00:00
Tom Christie
f5eaec7ab3
More coverage improvements (#711)
* More coverage improvements

* Drop redundant 'sleep' usage in test utils
2020-01-02 15:33:26 +00: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
f9d18a8758 Rename 'read/close' to 'aread/aclose' on Response (#674)
* Switch to aread/aclose on responses

* Linting

Co-authored-by: Tom Christie <tom@tomchristie.com>
2019-12-29 15:14:53 +00:00
Florimond Manca
56c8edaf66
Make 'request' non-optional on responses (#666)
* Make 'request' non-optional on Response

* Lint

* Remove remaining mention to null request
2019-12-21 15:38:25 +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
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
248aa580a1
Add Response.stream_lines (#575) 2019-11-30 18:02:46 +00:00
Tom Christie
206c5372a6
Drop sync (#544)
Drop sync client
2019-11-27 10:43:42 +00:00
Can Sarıgöl
79425b28d0 added control to calling decode for empty contents (#237)
* added tests for all decoder

* fixed BrotliDecoder for b"" value
2019-08-19 16:12:00 +01:00
Seth Michael Larson
af907e85e1
Implement Response.stream_text() (#183) 2019-08-14 21:56:17 -05:00
Quentin Pradet
ebbc003c55 Fix invalid Content-Encoding header test (#197) 2019-08-09 08:10:59 -05:00
Andreas Bernacca
de91fdfa16 Ignore Content-Encoding headers that are invalid (#196) 2019-08-08 21:33:55 -05:00
Tom Christie
2d09d5b36c
Renaming -> httpx (#129)
* Renaming -> httpx

* Renaming to httpx
2019-07-19 15:15:16 +01:00
Tom Christie
c9747aa357
http3 (#86)
* Start fleshing out documentation

* Docs work

* http3

* Update docs

* Include lowercase status codes, for requests compat

* Updating docs

* Docs tweaks
2019-06-12 15:02:16 +01:00
Tom Christie
0cbf3c7581
Sync or Async dispatch (#83)
* Support thread-pooled dispatch

* Add ConcurrencyBackend.run

* Initial work towards support byte-iterators on sync request data

* Test case for byte iterator content

* byte iterator support for RequestData

* Add BaseResponse

* Bridge sync/async data in SyncResponse

* Add BaseClient

* SyncResponse -> Response

* Tweaking type annotation

* Distinct classes for Request, AsyncRequest

* Tweak is_streaming, content in BaseRequest

* Stream handling moves to client

* Handle mediating to AsyncResponse from a standard sync Dispatcher class

* Working on thread-pooled dispatcher

* Support threaded dispatch, inc. streaming requests/responses

* Increase test coverage

* Coverage and tweaks

* Include Accept and User-Agent headers by default
2019-06-10 12:26:03 +01:00
Tom Christie
4c5511313c Response.content 2019-04-30 14:58:43 +01:00
Tom Christie
dea4d42c6d Rejig test and tighten up models API 2019-04-30 13:52:37 +01:00