Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
f974ebd
Removed deprecated TLS versions (#155)
halbow Jul 27, 2019
2cc8bea
Added support for Google's Brotli library (#156)
halbow Jul 27, 2019
7e9110b
Add additional flake8 plugins (#157)
cansarigol Jul 28, 2019
3ba2e8c
Switch hosts on HSTS preload to HTTPS (#151)
sethmlarson Jul 28, 2019
72e6f47
Allow setting headers at the Client level (#159)
StephenBrown2 Jul 29, 2019
44beaa1
Make Origin use scheme, not is_ssl (#168)
StephenBrown2 Jul 29, 2019
fb17459
Fixed multipart header params encoding (#167)
Jul 29, 2019
db6731a
Remove 'URIReference' from public interfaces (#170)
lovelydinosaur Jul 30, 2019
3382297
Expose base classes for alternate backends (#178)
sethmlarson Jul 30, 2019
66754ad
Tweak query param types (#175)
lovelydinosaur Jul 30, 2019
40849bf
Update IDNA encoding to 2008 spec (#161)
StephenBrown2 Jul 31, 2019
d1b1d35
Convert DataEvent.data from bytearray to bytes (#182)
sethmlarson Jul 31, 2019
919e8d3
added netrc support (#177)
Aug 1, 2019
9142a89
Move HSTS preload checking to client (#184)
sethmlarson Aug 1, 2019
92fbe5f
Added base class HTTPError with request/response attribute (#162)
halbow Aug 6, 2019
625ad12
Check `~/.netrc` and `~/_netrc` files by default (#189)
Aug 6, 2019
c7a5ce7
Enable mypy to discover type hints as specified in PEP 561 (#194)
andrewmwhite Aug 6, 2019
079ab33
Create a Contributing page in the documentation (#190)
humrochagf Aug 6, 2019
de91fdf
Ignore Content-Encoding headers that are invalid (#196)
rinti Aug 9, 2019
fde30b8
Use pathlib.Path instead of os.path functions (#188)
Aug 9, 2019
ebbc003
Fix invalid Content-Encoding header test (#197)
pquentin Aug 9, 2019
95dad24
Remove "Host" header on redirects if URL origin has changed (#199)
Aug 13, 2019
80dc3e2
Use nox for automation and CI (#128)
sethmlarson Aug 13, 2019
1b82d63
Add flake8-comprehensions to nox check task (#200)
Aug 13, 2019
e51b212
Move all tooling configuration to setup.cfg (#204)
humrochagf Aug 13, 2019
bebedcb
Explicitly check is_redirect in simple test case (#208)
behrtam Aug 14, 2019
c5248e6
Run SSLConfig cert loading in threadpool (#209)
Aug 15, 2019
7156c36
Add additional info to Contributing Guide (#213)
humrochagf Aug 15, 2019
45177d2
Rely on IRIReference.encode() for IDNA encoding (#210)
Aug 15, 2019
9536b76
Fail unit tests without 100% coverage (#206)
Aug 15, 2019
af907e8
Implement Response.stream_text() (#183)
sethmlarson Aug 15, 2019
df8874b
Accept SSLContext into SSLConfig(verify=...) (#215)
sethmlarson Aug 15, 2019
cad9c03
Added links property to BaseResponse (#211)
euri10 Aug 16, 2019
e64fcad
Add --diff flag to Black for easier debugging (#219)
euri10 Aug 16, 2019
3451028
Fix typos in docstrings
skshetry Aug 17, 2019
23f11aa
Use chained comparison in status codes for error and success
skshetry Aug 17, 2019
04d5ffb
Add trust_env property to BaseClient (#187)
Aug 17, 2019
21939fd
Documented netrc support (#225)
Aug 17, 2019
43f66d5
Skip coverage on breaks right before returns for Python 3.8 (#226)
sethmlarson Aug 17, 2019
345a46d
Add CHANGELOG.md for tracking releases (#227)
sethmlarson Aug 17, 2019
c35dbce
Release 0.7.0 (#228)
sethmlarson Aug 17, 2019
b46d9ea
Install package locally in test-requirements.txt (#231)
florimondmanca Aug 18, 2019
caba785
Release 0.7.1 (#234)
sethmlarson Aug 18, 2019
9c7d23c
Enforce that sync client uses asyncio-based backend (#232)
florimondmanca Aug 18, 2019
a960a2a
Release semaphore if connection is dropped (#230)
oldani Aug 18, 2019
ef9fc0f
Drop `raise_app_exceptions` Client argument. (#238)
lovelydinosaur Aug 19, 2019
79425b2
added control to calling decode for empty contents (#237)
Aug 19, 2019
0e49f23
Initial pass at configuring supported protocol versions
lovelydinosaur Aug 19, 2019
7fea072
Use correct protocol idents when loading ssl context
lovelydinosaur Aug 19, 2019
2ed70eb
Simplify ASGI concurrency (#248)
lovelydinosaur Aug 20, 2019
a0aff8d
fixed __repr__ function of Headers and Url classes (#222)
Aug 20, 2019
cf098f8
Merge branch 'protocol-support' of https://github.com/encode/httpx in…
lovelydinosaur Aug 20, 2019
f72fa68
'Protocols' -> 'HTTPVersions'
lovelydinosaur Aug 20, 2019
b2397ff
Turn concurrency.py into its own sub-package (#244)
florimondmanca Aug 20, 2019
fc27fd2
Test coverage for HTTPVersionConfig
lovelydinosaur Aug 20, 2019
a770102
Added http_versions to dispatch interface
lovelydinosaur Aug 20, 2019
4bfe54d
Drop unneccessary 'sorted'
lovelydinosaur Aug 20, 2019
193196b
Merge branch 'master' into protocol-support
lovelydinosaur Aug 20, 2019
b343ee4
Add Client(http_versions=...) support
lovelydinosaur Aug 20, 2019
dfbfa7c
Drop Protocol str enum class in favor of plain old strings
lovelydinosaur Aug 20, 2019
1800500
Address review comments
lovelydinosaur Aug 20, 2019
7408c44
Drop unused import
lovelydinosaur Aug 20, 2019
c1ec1c3
Response.protocol -> Response.http_version (#250)
lovelydinosaur Aug 20, 2019
e69ee77
Drop Protocol str enum class in favor of plain old strings (#251)
lovelydinosaur Aug 20, 2019
e0b523d
Merge pull request #241 from encode/protocol-support
lovelydinosaur Aug 20, 2019
fc261e8
Add BaseQueue interface (#257)
florimondmanca Aug 20, 2019
4ea4af6
Raise TypeError if invalid parameter for HTTPVersionConfig (#253)
Aug 20, 2019
c0554e9
Refactor interfaces (#252)
lovelydinosaur Aug 21, 2019
2e91d8c
Add BaseEvent interface (#260)
florimondmanca Aug 21, 2019
14eb81f
Unify BaseReader and BaseWriter as BaseStream
florimondmanca Aug 20, 2019
fdb1359
Encapsulate http_version into BaseStream
florimondmanca Aug 21, 2019
3069227
Merge pull request #255 from encode/refactor/stream-interface
lovelydinosaur Aug 21, 2019
80eafe8
Remove usage of loop.create_task in ASGIDispatch (#261)
florimondmanca Aug 21, 2019
20cb8af
Travis sudo no longer required for Xenial (#266)
hugovk Aug 22, 2019
31748a3
Add backend param to ASGIDispatcher (#270)
florimondmanca Aug 23, 2019
46402dd
Rely on codecov for 100% project coverage (#264)
sethmlarson Aug 23, 2019
a4b93b9
Add missing async test cases (#269)
florimondmanca Aug 23, 2019
1872ae8
Add ConcurrencyBackend.start_tls() (#263)
sethmlarson Aug 24, 2019
3674058
Parametrize tests with concurrency backend (#273)
florimondmanca Aug 25, 2019
8ea32e6
Add tests to known first parties in isort config (#279)
florimondmanca Aug 26, 2019
e7aa6d6
Force HTTP/1.1 on short-lived connections (#284)
sethmlarson Aug 27, 2019
33032df
Stop running nox on first error (#286)
jtmiclat Aug 27, 2019
6f4f186
Add easier debug logging for users (#277)
sethmlarson Aug 27, 2019
1f4b8dd
Allow per file running of tests (#287)
jtmiclat Aug 27, 2019
9e420a5
Automatically convert Client.cookies and Client.headers on set (#274)
toppk Aug 28, 2019
8c456e4
Release 0.7.2 (#291)
sethmlarson Aug 29, 2019
e9b2099
Fix typos in comments (#294)
minho42 Aug 29, 2019
994403b
Serve test server in thread (#292)
florimondmanca Aug 29, 2019
a464627
Tighten up response.next() (#297)
florimondmanca Aug 31, 2019
e34d280
Add server.url property in tests (#300)
theruziev Sep 1, 2019
db7f2d0
Add support for SSLKEYLOGFILE (#301)
tomasfarias Sep 1, 2019
40e6e8c
Refactor client functionality into middleware (#268)
florimondmanca Sep 1, 2019
b8c5e7a
Add os.environ fixture (#308)
sethmlarson Sep 2, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
.mypy_cache/
__pycache__/
htmlcov/
site/
*.egg-info/
venv/
.nox
32 changes: 24 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
sudo: required
dist: xenial
language: python

cache: pip

python:
- "3.6"
- "3.7"
branches:
only:
- master

matrix:
include:
- python: 3.7
env: NOX_SESSION=check
- python: 3.7
env: NOX_SESSION=docs

- python: 3.6
env: NOX_SESSION=test-3.6
- python: 3.7
env: NOX_SESSION=test-3.7
- python: 3.8-dev
env: NOX_SESSION=test-3.8
dist: bionic # Required to get OpenSSL 1.1.1+

install:
- pip install -U -r requirements.txt
- pip install --upgrade nox

script:
- scripts/test
- nox -s ${NOX_SESSION}

after_script:
- pip install codecov
- codecov
- if [ -f .coverage ]; then
python -m pip install codecov;
codecov --required;
fi
80 changes: 80 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Changelog

## 0.7.2 (August 28, 2019)

- Enforce using `httpx.AsyncioBackend` for the synchronous client. (Pull #232)
- `httpx.ConnectionPool` will properly release a dropped connection. (Pull #230)
- Remove the `raise_app_exceptions` argument from `Client`. (Pull #238)
- `DecodeError` will no longer be raised for an empty body encoded with Brotli. (Pull #237)
- Added `http_versions` parameter to `Client`. (Pull #250)
- Only use HTTP/1.1 on short-lived connections like `httpx.get()`. (Pull #284)
- Convert `Client.cookies` and `Client.headers` when set as a property. (Pull #274)
- Setting `HTTPX_DEBUG=1` enables debug logging on all requests. (Pull #277)

## 0.7.1 (August 18, 2019)

- Include files with source distribution to be installable. (Pull #233)

## 0.7.0 (August 17, 2019)

- Add the `trust_env` property to `BaseClient`. (Pull #187)
- Add the `links` property to `BaseResponse`. (Pull #211)
- Accept `ssl.SSLContext` instances into `SSLConfig(verify=...)`. (Pull #215)
- Add `Response.stream_text()` with incremental encoding detection. (Pull #183)
- Properly updated the `Host` header when a redirect changes the origin. (Pull #199)
- Ignore invalid `Content-Encoding` headers. (Pull #196)
- Use `~/.netrc` and `~/_netrc` files by default when `trust_env=True`. (Pull #189)
- Create exception base class `HTTPError` with `request` and `response` properties. (Pull #162)
- Add HSTS preload list checking within `BaseClient` to upgrade HTTP URLs to HTTPS. (Pull #184)
- Switch IDNA encoding from IDNA 2003 to IDNA 2008. (Pull #161)
- Expose base classes for alternate concurrency backends. (Pull #178)
- Improve Multipart parameter encoding. (Pull #167)
- Add the `headers` proeprty to `BaseClient`. (Pull #159)
- Add support for Google's `brotli` library. (Pull #156)
- Remove deprecated TLS versions (TLSv1 and TLSv1.1) from default `SSLConfig`. (Pull #155)
- Fix `URL.join(...)` to work similarly to RFC 3986 URL joining. (Pull #144)

## 0.6.8 (July 25, 2019)

- Check for disconnections when searching for an available
connection in `ConnectionPool.keepalive_connections` (Pull #145)
- Allow string comparison for `URL` objects (Pull #139)
- Add HTTP status codes 418 and 451 (Pull #135)
- Add support for client certificate passwords (Pull #118)
- Enable post-handshake client cert authentication for TLSv1.3 (Pull #118)
- Disable using `commonName` for hostname checking for OpenSSL 1.1.0+ (Pull #118)
- Detect encoding for `Response.json()` (Pull #116)

## 0.6.7 (July 8, 2019)

- Check for connection aliveness on re-acquiry (Pull #111)

## 0.6.6 (July 3, 2019)

- Improve `USER_AGENT` (Pull #110)
- Add `Connection: keep-alive` by default to HTTP/1.1 connections. (Pull #110)

## 0.6.5 (June 27, 2019)

- Include `Host` header by default. (Pull #109)
- Improve HTTP protocol detection. (Pull #107)

## 0.6.4 (June 25, 2019)

- Implement read and write timeouts (Pull #104)

## 0.6.3 (June 24, 2019)

- Handle early connection closes (Pull #103)

## 0.6.2 (June 23, 2019)

- Use urllib3's `DEFAULT_CIPHERS` for the `SSLConfig` object. (Pull #100)

## 0.6.1 (June 21, 2019)

- Add support for setting a `base_url` on the `Client`.

## 0.6.0 (June 21, 2019)

- Honor `local_flow_control_window` for HTTP/2 connections (Pull #98)
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include README.md
include CHANGELOG.md
include LICENSE.md
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ Let's get started...
<Response [200 OK]>
>>> r.status_code
200
>>> r.protocol
'HTTP/2'
>>> r.http_version
'HTTP/1.1'
>>> r.headers['content-type']
'text/html; charset=UTF-8'
>>> r.text
Expand Down Expand Up @@ -65,7 +65,7 @@ Plus all the standard features of `requests`...
* HTTP(S) Proxy Support *(TODO)*
* Connection Timeouts
* Streaming Downloads
* .netrc Support *(TODO)*
* .netrc Support
* Chunked Requests

## Installation
Expand All @@ -90,6 +90,10 @@ the specific topics on making [Parallel Requests](https://www.encode.io/httpx/pa

The [Developer Interface](https://www.encode.io/httpx/api/) provides a comprehensive API reference.

## Contribute

If you want to contribute with HTTPX check out the [Contributing Guide](https://www.encode.io/httpx/contributing/) to learn how to start.

## Dependencies

The httpx project relies on these excellent libraries:
Expand Down
8 changes: 8 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
coverage:
status:
patch:
default:
target: '100'
project:
default:
target: '100'
43 changes: 43 additions & 0 deletions docs/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,46 @@ r = client.get('http://example/')
assert r.status_code == 200
assert r.text == "Hello World!"
```

For some more complex cases you might need to customize the WSGI or ASGI
dispatch. This allows you to:

* Inspect 500 error responses, rather than raise exceptions, by setting `raise_app_exceptions=False`.
* Mount the WSGI or ASGI application at a subpath, by setting `script_name` (WSGI) or `root_path` (ASGI).
* Use a given the client address for requests, by setting `remote_addr` (WSGI) or `client` (ASGI).

For example:

```python
# Instantiate a client that makes WSGI requests with a client IP of "1.2.3.4".
dispatch = httpx.WSGIDispatch(app=app, remote_addr="1.2.3.4")
client = httpx.Client(dispatch=dispatch)
```

## .netrc Support

HTTPX supports .netrc file. In `trust_env=True` cases, if auth parameter is
not defined, HTTPX tries to add auth into request's header from .netrc file.

As default `trust_env` is true. To set false:
```python
>>> httpx.get('https://example.org/', trust_env=False)
```

If `NETRC` environment is empty, HTTPX tries to use default files.
(`~/.netrc`, `~/_netrc`)

To change `NETRC` environment:
```python
>>> import os
>>> os.environ["NETRC"] = "my_default_folder/.my_netrc"
```

.netrc file content example:
```
machine netrcexample.org
login example-username
password example-password

...
```
17 changes: 13 additions & 4 deletions docs/api.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Developer Interface

## Main Interface
## Helper Functions

!!! note
Only use these functions if you're testing HTTPX in a console
or making a small number of requests. Using a `Client` will
enable HTTP/2 and connection pooling for more efficient and
long-lived connections.

* `get(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`
* `options(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`
Expand All @@ -13,14 +19,16 @@

## `Client`

*An HTTP client, with connection pooling, redirects, cookie persistence, etc.*
*An HTTP client, with connection pooling, HTTP/2, redirects, cookie persistence, etc.*

```python
>>> client = httpx.Client()
>>> response = client.get('https://example.org')
```

* `def __init__([auth], [cookies], [verify], [cert], [timeout], [pool_limits], [max_redirects], [app], [dispatch])`
* `def __init__([auth], [headers], [cookies], [verify], [cert], [timeout], [pool_limits], [max_redirects], [app], [dispatch])`
* `.headers` - **Headers**
* `.cookies` - **Cookies**
* `def .get(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`
* `def .options(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`
* `def .head(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`
Expand All @@ -39,7 +47,7 @@
* `def __init__(...)`
* `.status_code` - **int**
* `.reason_phrase` - **str**
* `.protocol` - `"HTTP/2"` or `"HTTP/1.1"`
* `.http_version` - `"HTTP/2"` or `"HTTP/1.1"`
* `.url` - **URL**
* `.headers` - **Headers**
* `.content` - **bytes**
Expand Down Expand Up @@ -110,6 +118,7 @@ True
```

* `def __init__(url)`
* `.scheme` - **str**
* `.is_ssl` - **bool**
* `.host` - **str**
* `.port` - **int**
Expand Down
116 changes: 116 additions & 0 deletions docs/contributing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# Contributing

Thank you for being interested in contributing with HTTPX.
There are many ways you can contribute with the project:

- Try HTTPX and [report bugs/issues you find](https://github.com/encode/httpx/issues/new)
- [Implement new features](https://github.com/encode/httpx/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22)
- [Review Pull Requests of others](https://github.com/encode/httpx/pulls)
- Write documentation
- Participate in discussions

## Reporting Bugs or Other Issues

Found something that HTTPX should support?
Stumbled upon some unexpected behavior?

Feel free to open an issue at the
[issue tracker](https://github.com/encode/httpx/issues).
Try to be more descriptive as you can and in case of a bug report,
provide as much information as possible like:

- OS platform
- Python version
- Installed dependencies and versions (`python -m pip freeze`)
- Code snippet
- Error traceback

## Development

To start developing HTTPX create a **fork** of the
[HTTPX repository](https://github.com/encode/httpx) on GitHub.

Then clone your fork with the following command replacing `YOUR-USERNAME` with
your GitHub username:

```shell
$ git clone https://github.com/YOUR-USERNAME/httpx
```

With the repository cloned you can access its folder, set up the
virtual environment, install the project requirements,
and then install HTTPX on edit mode:

```shell
$ cd httpx
$ python3 -m venv venv
$ source venv/bin/activate
$ pip install -r test-requirements.txt
$ pip install -e .
```

!!! note
Feel free to replace this step with your development environment setup
(pyenv, pipenv, virtualenvwrapper, docker, etc).

## Testing and Linting

We use [nox](https://nox.thea.codes/en/stable/) to automate testing, linting,
and documentation building workflow. Make sure you have it installed
at your system before starting.

Install nox with:

```shell
$ python3 -m pip install --user nox
```

Alternatively, use [pipx](https://github.com/pipxproject/pipx) if you prefer
to keep it into an isolated environment:

```shell
$ pipx install nox
```

Now, with nox installed run the complete pipeline with:

```shell
$ nox
```

!!! warning
The test suite spawns a testing server at the port **8000**.
Make sure this isn't being used, so the tests can run properly.

To run the code auto-formatting separately:

```shell
$ nox -s lint
```

Also, if you need to run the tests only:

```shell
$ nox -s test
```

You can also run a single test script like this:

```shell
$ nox -s test -- tests/test_multipart.py
```

## Documenting

To work with the documentation, make sure you have `mkdocs` and
`mkdocs-material` installed on your environment:

```shell
$ pip install mkdocs mkdocs-material
```

To spawn the docs server run:

```shell
$ mkdocs serve
```
Loading