Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 0.20 #1890

Merged
merged 5 commits into from Oct 13, 2021
Merged

Version 0.20 #1890

merged 5 commits into from Oct 13, 2021

Conversation

tomchristie
Copy link
Member

Let's push the 1.0 pre-release to a 0.20 version instead.


0.20.0 (13th October, 2021)

The 0.20.0 release adds an integrated command-line client, and also includes some design changes. The most notable of these is that redirect responses are no longer automatically followed, unless specifically requested.

This design decision prioritises a more explicit approach to redirects, in order to avoid code that unintentionally issues multiple requests as a result of misconfigured URLs.

For example, previously a client configured to send requests to http://api.github.com/ would end up sending every API request twice, as each request would be redirected to https://api.github.com/.

If you do want auto-redirect behaviour, you can enable this either by configuring the client instance with Client(follow_redirects=True), or on a per-request basis, with .get(..., follow_redirects=True).

This change is a classic trade-off between convenience and precision, with no "right" answer. See discussion #1785 for more context.

The other major design change is an update to the Transport API, which is the low-level interface against which requests are sent. Previously this interface used only primitive datastructures, like so...

(status_code, headers, stream, extensions) = transport.handle_request(method, url, headers, stream, extensions)
try
    ...
finally:
    stream.close()

Now the interface is much simpler...

response = transport.handle_request(request)
try
    ...
finally:
    response.close()

Changed

  • The allow_redirects flag is now follow_redirects and defaults to False.
  • The raise_for_status() method will now raise an exception for any responses except those with 2xx status codes. Previously only 4xx and 5xx status codes would result in an exception.
  • The low-level transport API changes to the much simpler response = transport.handle_request(request).
  • The client.send() method no longer accepts a timeout=... argument, but the client.build_request() does. This required by the signature change of the Transport API. The request timeout configuration is now stored on the request instance, as request.extensions['timeout'].

Added

  • Added the httpx command-line client.
  • Response instances now include .is_informational, .is_success, .is_redirect, .is_client_error, and .is_server_error properties for checking 1xx, 2xx, 3xx, 4xx, and 5xx response types. Note that the behaviour of .is_redirect is slightly different in that it now returns True for all 3xx responses, in order to allow for a consistent set of properties onto the different HTTP status code types. The response.has_redirect_location location may be used to determine responses with properly formed URL redirects.

Fixed

@tomchristie tomchristie merged commit 35164b7 into master Oct 13, 2021
@tomchristie tomchristie deleted the version-0.20.0 branch October 13, 2021 09:43
@@ -4,6 +4,8 @@
# Reference: https://github.com/encode/httpx/pull/1721#discussion_r661241588
-e .[cli,http2,brotli]

charset-normalizer==2.0.6
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I stumbled here after a quick lookup at the changelog.
What I would recommend you is to use more predictable source bytes for your tests.

>>> from charset_normalizer import detect
>>> k = "Bсеки човек има право на образование. Oбразованието!".encode("cp1251")
>>> detect(k)
{'encoding': 'windows-1251', 'language': 'Russian', 'confidence': 1.0}
>>> k = "Bсеки човек има право на образование. Oбразованието!".encode("koi8_r")
>>> detect(k)
{'encoding': 'KOI8-R', 'language': 'Russian', 'confidence': 1.0}
>>> k = "Bсеки човек има право на образование. Oбразованието!".encode("utf_8")
>>> detect(k)
{'encoding': 'utf-8', 'language': 'Russian', 'confidence': 1.0}
>>> k = "Bсеки човек има право на образование. Oбразованието!".encode("kz1048")
>>> detect(k)
{'encoding': 'windows-1251', 'language': 'Russian', 'confidence': 1.0}
>>> k = "Bсеки човек има право на образование. Oбразованието!".encode("ptcp154")
>>> detect(k)
{'encoding': 'windows-1251', 'language': 'Russian', 'confidence': 1.0}
>>> from charset_normalizer import from_bytes
>>> from_bytes(k).best().could_be_from_charset
['cp1251', 'kz1048', 'mac_cyrillic', 'ptcp154']

More reliable than "Accented: Österreich abcdefghijklmnopqrstuzwxyz".
Hopefully, that will help. I can personally ensure that this case will not regress or mutate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants