Compare commits
No commits in common. "master" and "gh-pages" have entirely different histories.
236
.github/CONTRIBUTING.md
vendored
236
.github/CONTRIBUTING.md
vendored
@ -1,236 +0,0 @@
|
||||
# Contributing
|
||||
|
||||
Thank you for being interested in contributing to HTTPX.
|
||||
There are many ways you can contribute to 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 behaviour?
|
||||
|
||||
Contributions should generally start out with [a discussion](https://github.com/encode/httpx/discussions).
|
||||
Possible bugs may be raised as a "Potential Issue" discussion, feature requests may
|
||||
be raised as an "Ideas" discussion. We can then determine if the discussion needs
|
||||
to be escalated into an "Issue" or not, or if we'd consider a pull request.
|
||||
|
||||
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
|
||||
|
||||
You should always try to reduce any examples to the *simplest possible case*
|
||||
that demonstrates the issue.
|
||||
|
||||
Some possibly useful tips for narrowing down potential issues...
|
||||
|
||||
- Does the issue exist on HTTP/1.1, or HTTP/2, or both?
|
||||
- Does the issue exist with `Client`, `AsyncClient`, or both?
|
||||
- When using `AsyncClient` does the issue exist when using `asyncio` or `trio`, or both?
|
||||
|
||||
## 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
|
||||
```
|
||||
|
||||
You can now install the project and its dependencies using:
|
||||
|
||||
```shell
|
||||
$ cd httpx
|
||||
$ scripts/install
|
||||
```
|
||||
|
||||
## Testing and Linting
|
||||
|
||||
We use custom shell scripts to automate testing, linting,
|
||||
and documentation building workflow.
|
||||
|
||||
To run the tests, use:
|
||||
|
||||
```shell
|
||||
$ scripts/test
|
||||
```
|
||||
|
||||
!!! warning
|
||||
The test suite spawns testing servers on ports **8000** and **8001**.
|
||||
Make sure these are not in use, so the tests can run properly.
|
||||
|
||||
You can run a single test script like this:
|
||||
|
||||
```shell
|
||||
$ scripts/test -- tests/test_multipart.py
|
||||
```
|
||||
|
||||
To run the code auto-formatting:
|
||||
|
||||
```shell
|
||||
$ scripts/lint
|
||||
```
|
||||
|
||||
Lastly, to run code checks separately (they are also run as part of `scripts/test`), run:
|
||||
|
||||
```shell
|
||||
$ scripts/check
|
||||
```
|
||||
|
||||
## Documenting
|
||||
|
||||
Documentation pages are located under the `docs/` folder.
|
||||
|
||||
To run the documentation site locally (useful for previewing changes), use:
|
||||
|
||||
```shell
|
||||
$ scripts/docs
|
||||
```
|
||||
|
||||
## Resolving Build / CI Failures
|
||||
|
||||
Once you've submitted your pull request, the test suite will automatically run, and the results will show up in GitHub.
|
||||
If the test suite fails, you'll want to click through to the "Details" link, and try to identify why the test suite failed.
|
||||
|
||||
<p align="center" style="margin: 0 0 10px">
|
||||
<img src="https://raw.githubusercontent.com/encode/httpx/master/docs/img/gh-actions-fail.png" alt='Failing PR commit status'>
|
||||
</p>
|
||||
|
||||
Here are some common ways the test suite can fail:
|
||||
|
||||
### Check Job Failed
|
||||
|
||||
<p align="center" style="margin: 0 0 10px">
|
||||
<img src="https://raw.githubusercontent.com/encode/httpx/master/docs/img/gh-actions-fail-check.png" alt='Failing GitHub action lint job'>
|
||||
</p>
|
||||
|
||||
This job failing means there is either a code formatting issue or type-annotation issue.
|
||||
You can look at the job output to figure out why it's failed or within a shell run:
|
||||
|
||||
```shell
|
||||
$ scripts/check
|
||||
```
|
||||
|
||||
It may be worth it to run `$ scripts/lint` to attempt auto-formatting the code
|
||||
and if that job succeeds commit the changes.
|
||||
|
||||
### Docs Job Failed
|
||||
|
||||
This job failing means the documentation failed to build. This can happen for
|
||||
a variety of reasons like invalid markdown or missing configuration within `mkdocs.yml`.
|
||||
|
||||
### Python 3.X Job Failed
|
||||
|
||||
<p align="center" style="margin: 0 0 10px">
|
||||
<img src="https://raw.githubusercontent.com/encode/httpx/master/docs/img/gh-actions-fail-test.png" alt='Failing GitHub action test job'>
|
||||
</p>
|
||||
|
||||
This job failing means the unit tests failed or not all code paths are covered by unit tests.
|
||||
|
||||
If tests are failing you will see this message under the coverage report:
|
||||
|
||||
`=== 1 failed, 435 passed, 1 skipped, 1 xfailed in 11.09s ===`
|
||||
|
||||
If tests succeed but coverage doesn't reach our current threshold, you will see this
|
||||
message under the coverage report:
|
||||
|
||||
`FAIL Required test coverage of 100% not reached. Total coverage: 99.00%`
|
||||
|
||||
## Releasing
|
||||
|
||||
*This section is targeted at HTTPX maintainers.*
|
||||
|
||||
Before releasing a new version, create a pull request that includes:
|
||||
|
||||
- **An update to the changelog**:
|
||||
- We follow the format from [keepachangelog](https://keepachangelog.com/en/1.0.0/).
|
||||
- [Compare](https://github.com/encode/httpx/compare/) `master` with the tag of the latest release, and list all entries that are of interest to our users:
|
||||
- Things that **must** go in the changelog: added, changed, deprecated or removed features, and bug fixes.
|
||||
- Things that **should not** go in the changelog: changes to documentation, tests or tooling.
|
||||
- Try sorting entries in descending order of impact / importance.
|
||||
- Keep it concise and to-the-point. 🎯
|
||||
- **A version bump**: see `__version__.py`.
|
||||
|
||||
For an example, see [#1006](https://github.com/encode/httpx/pull/1006).
|
||||
|
||||
Once the release PR is merged, create a
|
||||
[new release](https://github.com/encode/httpx/releases/new) including:
|
||||
|
||||
- Tag version like `0.13.3`.
|
||||
- Release title `Version 0.13.3`
|
||||
- Description copied from the changelog.
|
||||
|
||||
Once created this release will be automatically uploaded to PyPI.
|
||||
|
||||
If something goes wrong with the PyPI job the release can be published using the
|
||||
`scripts/publish` script.
|
||||
|
||||
## Development proxy setup
|
||||
|
||||
To test and debug requests via a proxy it's best to run a proxy server locally.
|
||||
Any server should do but HTTPCore's test suite uses
|
||||
[`mitmproxy`](https://mitmproxy.org/) which is written in Python, it's fully
|
||||
featured and has excellent UI and tools for introspection of requests.
|
||||
|
||||
You can install `mitmproxy` using `pip install mitmproxy` or [several
|
||||
other ways](https://docs.mitmproxy.org/stable/overview-installation/).
|
||||
|
||||
`mitmproxy` does require setting up local TLS certificates for HTTPS requests,
|
||||
as its main purpose is to allow developers to inspect requests that pass through
|
||||
it. We can set them up follows:
|
||||
|
||||
1. [`pip install trustme-cli`](https://github.com/sethmlarson/trustme-cli/).
|
||||
2. `trustme-cli -i example.org www.example.org`, assuming you want to test
|
||||
connecting to that domain, this will create three files: `server.pem`,
|
||||
`server.key` and `client.pem`.
|
||||
3. `mitmproxy` requires a PEM file that includes the private key and the
|
||||
certificate so we need to concatenate them:
|
||||
`cat server.key server.pem > server.withkey.pem`.
|
||||
4. Start the proxy server `mitmproxy --certs server.withkey.pem`, or use the
|
||||
[other mitmproxy commands](https://docs.mitmproxy.org/stable/) with different
|
||||
UI options.
|
||||
|
||||
At this point the server is ready to start serving requests, you'll need to
|
||||
configure HTTPX as described in the
|
||||
[proxy section](https://www.python-httpx.org/advanced/#http-proxying) and
|
||||
the [SSL certificates section](https://www.python-httpx.org/advanced/#ssl-certificates),
|
||||
this is where our previously generated `client.pem` comes in:
|
||||
|
||||
```
|
||||
import httpx
|
||||
|
||||
ssl_context = httpx.SSLContext()
|
||||
ssl_context.load_verify_locations("/path/to/client.pem")
|
||||
|
||||
with httpx.Client(proxy="http://127.0.0.1:8080/", ssl_context=ssl_context) as client:
|
||||
response = client.get("https://example.org")
|
||||
print(response.status_code) # should print 200
|
||||
```
|
||||
|
||||
Note, however, that HTTPS requests will only succeed to the host specified
|
||||
in the SSL/TLS certificate we generated, HTTPS requests to other hosts will
|
||||
raise an error like:
|
||||
|
||||
```
|
||||
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate
|
||||
verify failed: Hostname mismatch, certificate is not valid for
|
||||
'duckduckgo.com'. (_ssl.c:1108)
|
||||
```
|
||||
|
||||
If you want to make requests to more hosts you'll need to regenerate the
|
||||
certificates and include all the hosts you intend to connect to in the
|
||||
seconds step, i.e.
|
||||
|
||||
`trustme-cli -i example.org www.example.org duckduckgo.com www.duckduckgo.com`
|
||||
1
.github/FUNDING.yml
vendored
1
.github/FUNDING.yml
vendored
@ -1 +0,0 @@
|
||||
github: encode
|
||||
16
.github/ISSUE_TEMPLATE/1-issue.md
vendored
16
.github/ISSUE_TEMPLATE/1-issue.md
vendored
@ -1,16 +0,0 @@
|
||||
---
|
||||
name: Issue
|
||||
about: Please only raise an issue if you've been advised to do so after discussion. Thanks! 🙏
|
||||
---
|
||||
|
||||
The starting point for issues should usually be a discussion...
|
||||
|
||||
https://github.com/encode/httpx/discussions
|
||||
|
||||
Possible bugs may be raised as a "Potential Issue" discussion, feature requests may be raised as an "Ideas" discussion. We can then determine if the discussion needs to be escalated into an "Issue" or not.
|
||||
|
||||
This will help us ensure that the "Issues" list properly reflects ongoing or needed work on the project.
|
||||
|
||||
---
|
||||
|
||||
- [ ] Initially raised as discussion #...
|
||||
11
.github/ISSUE_TEMPLATE/config.yml
vendored
11
.github/ISSUE_TEMPLATE/config.yml
vendored
@ -1,11 +0,0 @@
|
||||
# Ref: https://help.github.com/en/github/building-a-strong-community/configuring-issue-templates-for-your-repository#configuring-the-template-chooser
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: Discussions
|
||||
url: https://github.com/encode/httpx/discussions
|
||||
about: >
|
||||
The "Discussions" forum is where you want to start. 💖
|
||||
- name: Chat
|
||||
url: https://gitter.im/encode/community
|
||||
about: >
|
||||
Our community chat forum.
|
||||
12
.github/PULL_REQUEST_TEMPLATE.md
vendored
12
.github/PULL_REQUEST_TEMPLATE.md
vendored
@ -1,12 +0,0 @@
|
||||
<!-- Thanks for contributing to HTTPX! 💚
|
||||
Given this is a project maintained by volunteers, please read this template to not waste your time, or ours! 😁 -->
|
||||
|
||||
# Summary
|
||||
|
||||
<!-- Write a small summary about what is happening here. -->
|
||||
|
||||
# Checklist
|
||||
|
||||
- [ ] I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
|
||||
- [ ] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
|
||||
- [ ] I've updated the documentation accordingly.
|
||||
14
.github/dependabot.yml
vendored
14
.github/dependabot.yml
vendored
@ -1,14 +0,0 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "pip"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "monthly"
|
||||
groups:
|
||||
python-packages:
|
||||
patterns:
|
||||
- "*"
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: monthly
|
||||
29
.github/workflows/publish.yml
vendored
29
.github/workflows/publish.yml
vendored
@ -1,29 +0,0 @@
|
||||
name: Publish
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
name: "Publish release"
|
||||
runs-on: "ubuntu-latest"
|
||||
|
||||
environment:
|
||||
name: deploy
|
||||
|
||||
steps:
|
||||
- uses: "actions/checkout@v4"
|
||||
- uses: "actions/setup-python@v6"
|
||||
with:
|
||||
python-version: 3.9
|
||||
- name: "Install dependencies"
|
||||
run: "scripts/install"
|
||||
- name: "Build package & docs"
|
||||
run: "scripts/build"
|
||||
- name: "Publish to PyPI & deploy docs"
|
||||
run: "scripts/publish"
|
||||
env:
|
||||
TWINE_USERNAME: __token__
|
||||
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
|
||||
34
.github/workflows/test-suite.yml
vendored
34
.github/workflows/test-suite.yml
vendored
@ -1,34 +0,0 @@
|
||||
---
|
||||
name: Test Suite
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["master"]
|
||||
pull_request:
|
||||
branches: ["master", "version-*"]
|
||||
|
||||
jobs:
|
||||
tests:
|
||||
name: "Python ${{ matrix.python-version }}"
|
||||
runs-on: "ubuntu-latest"
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
|
||||
|
||||
steps:
|
||||
- uses: "actions/checkout@v4"
|
||||
- uses: "actions/setup-python@v6"
|
||||
with:
|
||||
python-version: "${{ matrix.python-version }}"
|
||||
allow-prereleases: true
|
||||
- name: "Install dependencies"
|
||||
run: "scripts/install"
|
||||
- name: "Run linting checks"
|
||||
run: "scripts/check"
|
||||
- name: "Build package & docs"
|
||||
run: "scripts/build"
|
||||
- name: "Run tests"
|
||||
run: "scripts/test"
|
||||
- name: "Enforce coverage"
|
||||
run: "scripts/coverage"
|
||||
12
.gitignore
vendored
12
.gitignore
vendored
@ -1,12 +0,0 @@
|
||||
*.pyc
|
||||
.coverage
|
||||
.pytest_cache/
|
||||
.mypy_cache/
|
||||
__pycache__/
|
||||
htmlcov/
|
||||
site/
|
||||
*.egg-info/
|
||||
venv*/
|
||||
.python-version
|
||||
build/
|
||||
dist/
|
||||
988
404.html
Normal file
988
404.html
Normal file
@ -0,0 +1,988 @@
|
||||
|
||||
<!doctype html>
|
||||
<html lang="en" class="no-js">
|
||||
<head>
|
||||
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
|
||||
<meta name="description" content="A next-generation HTTP client for Python.">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<link rel="icon" href="/assets/images/favicon.png">
|
||||
<meta name="generator" content="mkdocs-1.6.1, mkdocs-material-9.5.47">
|
||||
|
||||
|
||||
|
||||
<title>HTTPX</title>
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="/assets/stylesheets/main.6f8fc17f.min.css">
|
||||
|
||||
|
||||
<link rel="stylesheet" href="/assets/stylesheets/palette.06af60db.min.css">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
|
||||
<style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="/css/custom.css">
|
||||
|
||||
<script>__md_scope=new URL("/",location),__md_hash=e=>[...e].reduce(((e,_)=>(e<<5)-e+_.charCodeAt(0)),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<body dir="ltr" data-md-color-scheme="default" data-md-color-primary="indigo" data-md-color-accent="indigo">
|
||||
|
||||
|
||||
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
|
||||
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
|
||||
<label class="md-overlay" for="__drawer"></label>
|
||||
<div data-md-component="skip">
|
||||
|
||||
</div>
|
||||
<div data-md-component="announce">
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<header class="md-header md-header--shadow" data-md-component="header">
|
||||
<nav class="md-header__inner md-grid" aria-label="Header">
|
||||
<a href="/." title="HTTPX" class="md-header__button md-logo" aria-label="HTTPX" data-md-component="logo">
|
||||
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54"/></svg>
|
||||
|
||||
</a>
|
||||
<label class="md-header__button md-icon" for="__drawer">
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3zm0 5h18v2H3zm0 5h18v2H3z"/></svg>
|
||||
</label>
|
||||
<div class="md-header__title" data-md-component="header-title">
|
||||
<div class="md-header__ellipsis">
|
||||
<div class="md-header__topic">
|
||||
<span class="md-ellipsis">
|
||||
HTTPX
|
||||
</span>
|
||||
</div>
|
||||
<div class="md-header__topic" data-md-component="header-topic">
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<form class="md-header__option" data-md-component="palette">
|
||||
|
||||
|
||||
|
||||
|
||||
<input class="md-option" data-md-color-media="(prefers-color-scheme: light)" data-md-color-scheme="default" data-md-color-primary="indigo" data-md-color-accent="indigo" aria-label="Switch to dark mode" type="radio" name="__palette" id="__palette_0">
|
||||
|
||||
<label class="md-header__button md-icon" title="Switch to dark mode" for="__palette_1" hidden>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 2a7 7 0 0 0-7 7c0 2.38 1.19 4.47 3 5.74V17a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1v-2.26c1.81-1.27 3-3.36 3-5.74a7 7 0 0 0-7-7M9 21a1 1 0 0 0 1 1h4a1 1 0 0 0 1-1v-1H9z"/></svg>
|
||||
</label>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<input class="md-option" data-md-color-media="(prefers-color-scheme: dark)" data-md-color-scheme="slate" data-md-color-primary="blue" data-md-color-accent="indigo" aria-label="Switch to light mode" type="radio" name="__palette" id="__palette_1">
|
||||
|
||||
<label class="md-header__button md-icon" title="Switch to light mode" for="__palette_0" hidden>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 2a7 7 0 0 1 7 7c0 2.38-1.19 4.47-3 5.74V17a1 1 0 0 1-1 1H9a1 1 0 0 1-1-1v-2.26C6.19 13.47 5 11.38 5 9a7 7 0 0 1 7-7M9 21v-1h6v1a1 1 0 0 1-1 1h-4a1 1 0 0 1-1-1m3-17a5 5 0 0 0-5 5c0 2.05 1.23 3.81 3 4.58V16h4v-2.42c1.77-.77 3-2.53 3-4.58a5 5 0 0 0-5-5"/></svg>
|
||||
</label>
|
||||
|
||||
|
||||
</form>
|
||||
|
||||
|
||||
|
||||
<script>var palette=__md_get("__palette");if(palette&&palette.color){if("(prefers-color-scheme)"===palette.color.media){var media=matchMedia("(prefers-color-scheme: light)"),input=document.querySelector(media.matches?"[data-md-color-media='(prefers-color-scheme: light)']":"[data-md-color-media='(prefers-color-scheme: dark)']");palette.color.media=input.getAttribute("data-md-color-media"),palette.color.scheme=input.getAttribute("data-md-color-scheme"),palette.color.primary=input.getAttribute("data-md-color-primary"),palette.color.accent=input.getAttribute("data-md-color-accent")}for(var[key,value]of Object.entries(palette.color))document.body.setAttribute("data-md-color-"+key,value)}</script>
|
||||
|
||||
|
||||
|
||||
<label class="md-header__button md-icon" for="__search">
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.52 6.52 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5"/></svg>
|
||||
</label>
|
||||
<div class="md-search" data-md-component="search" role="dialog">
|
||||
<label class="md-search__overlay" for="__search"></label>
|
||||
<div class="md-search__inner" role="search">
|
||||
<form class="md-search__form" name="search">
|
||||
<input type="text" class="md-search__input" name="query" aria-label="Search" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required>
|
||||
<label class="md-search__icon md-icon" for="__search">
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.52 6.52 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5"/></svg>
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11z"/></svg>
|
||||
</label>
|
||||
<nav class="md-search__options" aria-label="Search">
|
||||
|
||||
<button type="reset" class="md-search__icon md-icon" title="Clear" aria-label="Clear" tabindex="-1">
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/></svg>
|
||||
</button>
|
||||
</nav>
|
||||
|
||||
</form>
|
||||
<div class="md-search__output">
|
||||
<div class="md-search__scrollwrap" tabindex="0" data-md-scrollfix>
|
||||
<div class="md-search-result" data-md-component="search-result">
|
||||
<div class="md-search-result__meta">
|
||||
Initializing search
|
||||
</div>
|
||||
<ol class="md-search-result__list" role="presentation"></ol>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="md-header__source">
|
||||
<a href="https://github.com/encode/httpx/" title="Go to repository" class="md-source" data-md-component="source">
|
||||
<div class="md-source__icon md-icon">
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Free 6.7.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2024 Fonticons, Inc.--><path d="M439.55 236.05 244 40.45a28.87 28.87 0 0 0-40.81 0l-40.66 40.63 51.52 51.52c27.06-9.14 52.68 16.77 43.39 43.68l49.66 49.66c34.23-11.8 61.18 31 35.47 56.69-26.49 26.49-70.21-2.87-56-37.34L240.22 199v121.85c25.3 12.54 22.26 41.85 9.08 55a34.34 34.34 0 0 1-48.55 0c-17.57-17.6-11.07-46.91 11.25-56v-123c-20.8-8.51-24.6-30.74-18.64-45L142.57 101 8.45 235.14a28.86 28.86 0 0 0 0 40.81l195.61 195.6a28.86 28.86 0 0 0 40.8 0l194.69-194.69a28.86 28.86 0 0 0 0-40.81"/></svg>
|
||||
</div>
|
||||
<div class="md-source__repository">
|
||||
encode/httpx
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
</nav>
|
||||
|
||||
</header>
|
||||
|
||||
<div class="md-container" data-md-component="container">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<main class="md-main" data-md-component="main">
|
||||
<div class="md-main__inner md-grid">
|
||||
|
||||
|
||||
|
||||
<div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
|
||||
<div class="md-sidebar__scrollwrap">
|
||||
<div class="md-sidebar__inner">
|
||||
|
||||
|
||||
<!-- Determine class according to configuration -->
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- Main navigation -->
|
||||
<nav
|
||||
class="md-nav md-nav--primary"
|
||||
aria-label="nav.title"
|
||||
data-md-level="0"
|
||||
>
|
||||
|
||||
<!-- Site title -->
|
||||
<label class="md-nav__title" for="__drawer">
|
||||
<a
|
||||
href="/."
|
||||
title="HTTPX"
|
||||
class="md-nav__button md-logo"
|
||||
aria-label="HTTPX"
|
||||
data-md-component="logo"
|
||||
>
|
||||
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54"/></svg>
|
||||
|
||||
</a>
|
||||
HTTPX
|
||||
</label>
|
||||
|
||||
<!-- Repository information -->
|
||||
|
||||
<div class="md-nav__source">
|
||||
<a href="https://github.com/encode/httpx/" title="Go to repository" class="md-source" data-md-component="source">
|
||||
<div class="md-source__icon md-icon">
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Free 6.7.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2024 Fonticons, Inc.--><path d="M439.55 236.05 244 40.45a28.87 28.87 0 0 0-40.81 0l-40.66 40.63 51.52 51.52c27.06-9.14 52.68 16.77 43.39 43.68l49.66 49.66c34.23-11.8 61.18 31 35.47 56.69-26.49 26.49-70.21-2.87-56-37.34L240.22 199v121.85c25.3 12.54 22.26 41.85 9.08 55a34.34 34.34 0 0 1-48.55 0c-17.57-17.6-11.07-46.91 11.25-56v-123c-20.8-8.51-24.6-30.74-18.64-45L142.57 101 8.45 235.14a28.86 28.86 0 0 0 0 40.81l195.61 195.6a28.86 28.86 0 0 0 40.8 0l194.69-194.69a28.86 28.86 0 0 0 0-40.81"/></svg>
|
||||
</div>
|
||||
<div class="md-source__repository">
|
||||
encode/httpx
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Navigation list -->
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/." class="md-nav__link">
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
Introduction
|
||||
</span>
|
||||
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/quickstart/" class="md-nav__link">
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
QuickStart
|
||||
</span>
|
||||
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item md-nav__item--nested">
|
||||
|
||||
|
||||
|
||||
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3" >
|
||||
|
||||
|
||||
<label class="md-nav__link" for="__nav_3" id="__nav_3_label" tabindex="0">
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
Advanced
|
||||
</span>
|
||||
|
||||
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
</label>
|
||||
|
||||
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_3_label" aria-expanded="false">
|
||||
<label class="md-nav__title" for="__nav_3">
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
Advanced
|
||||
</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/advanced/clients/" class="md-nav__link">
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
Clients
|
||||
</span>
|
||||
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/advanced/authentication/" class="md-nav__link">
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
Authentication
|
||||
</span>
|
||||
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/advanced/ssl/" class="md-nav__link">
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
SSL
|
||||
</span>
|
||||
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/advanced/proxies/" class="md-nav__link">
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
Proxies
|
||||
</span>
|
||||
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/advanced/timeouts/" class="md-nav__link">
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
Timeouts
|
||||
</span>
|
||||
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/advanced/resource-limits/" class="md-nav__link">
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
Resource Limits
|
||||
</span>
|
||||
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/advanced/event-hooks/" class="md-nav__link">
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
Event Hooks
|
||||
</span>
|
||||
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/advanced/transports/" class="md-nav__link">
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
Transports
|
||||
</span>
|
||||
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/advanced/text-encodings/" class="md-nav__link">
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
Text Encodings
|
||||
</span>
|
||||
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/advanced/extensions/" class="md-nav__link">
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
Extensions
|
||||
</span>
|
||||
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item md-nav__item--nested">
|
||||
|
||||
|
||||
|
||||
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_4" >
|
||||
|
||||
|
||||
<label class="md-nav__link" for="__nav_4" id="__nav_4_label" tabindex="0">
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
Guides
|
||||
</span>
|
||||
|
||||
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
</label>
|
||||
|
||||
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_4_label" aria-expanded="false">
|
||||
<label class="md-nav__title" for="__nav_4">
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
Guides
|
||||
</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/async/" class="md-nav__link">
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
Async Support
|
||||
</span>
|
||||
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/http2/" class="md-nav__link">
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
HTTP/2 Support
|
||||
</span>
|
||||
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/logging/" class="md-nav__link">
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
Logging
|
||||
</span>
|
||||
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/compatibility/" class="md-nav__link">
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
Requests Compatibility
|
||||
</span>
|
||||
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/troubleshooting/" class="md-nav__link">
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
Troubleshooting
|
||||
</span>
|
||||
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item md-nav__item--nested">
|
||||
|
||||
|
||||
|
||||
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_5" >
|
||||
|
||||
|
||||
<label class="md-nav__link" for="__nav_5" id="__nav_5_label" tabindex="0">
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
API Reference
|
||||
</span>
|
||||
|
||||
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
</label>
|
||||
|
||||
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_5_label" aria-expanded="false">
|
||||
<label class="md-nav__title" for="__nav_5">
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
API Reference
|
||||
</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/api/" class="md-nav__link">
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
Developer Interface
|
||||
</span>
|
||||
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/exceptions/" class="md-nav__link">
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
Exceptions
|
||||
</span>
|
||||
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/environment_variables/" class="md-nav__link">
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
Environment Variables
|
||||
</span>
|
||||
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item md-nav__item--nested">
|
||||
|
||||
|
||||
|
||||
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_6" >
|
||||
|
||||
|
||||
<label class="md-nav__link" for="__nav_6" id="__nav_6_label" tabindex="0">
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
Community
|
||||
</span>
|
||||
|
||||
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
</label>
|
||||
|
||||
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_6_label" aria-expanded="false">
|
||||
<label class="md-nav__title" for="__nav_6">
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
Community
|
||||
</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/third_party_packages/" class="md-nav__link">
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
Third Party Packages
|
||||
</span>
|
||||
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/contributing/" class="md-nav__link">
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
Contributing
|
||||
</span>
|
||||
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/code_of_conduct/" class="md-nav__link">
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
Code of Conduct
|
||||
</span>
|
||||
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
<ul class="md-nav__list" data-md-scrollfix style="padding-top: 15px; padding-left: 10px">
|
||||
<div>
|
||||
<a href="https://speakeasy.com"><img src="/img/speakeasy.png" width=150px style=></img></a>
|
||||
</div>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" >
|
||||
<div class="md-sidebar__scrollwrap">
|
||||
<div class="md-sidebar__inner">
|
||||
|
||||
|
||||
<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
|
||||
|
||||
|
||||
|
||||
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="md-content" data-md-component="content">
|
||||
<article class="md-content__inner md-typeset">
|
||||
|
||||
<h1>404 - Not found</h1>
|
||||
|
||||
</article>
|
||||
</div>
|
||||
|
||||
|
||||
<script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script>
|
||||
</div>
|
||||
|
||||
</main>
|
||||
|
||||
<footer class="md-footer">
|
||||
|
||||
<div class="md-footer-meta md-typeset">
|
||||
<div class="md-footer-meta__inner md-grid">
|
||||
<div class="md-copyright">
|
||||
|
||||
|
||||
Made with
|
||||
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
|
||||
Material for MkDocs
|
||||
</a>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
</div>
|
||||
<div class="md-dialog" data-md-component="dialog">
|
||||
<div class="md-dialog__inner md-typeset"></div>
|
||||
</div>
|
||||
|
||||
|
||||
<script id="__config" type="application/json">{"base": "/", "features": [], "search": "/assets/javascripts/workers/search.6ce7567c.min.js", "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}}</script>
|
||||
|
||||
|
||||
<script src="/assets/javascripts/bundle.83f73b43.min.js"></script>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
1142
CHANGELOG.md
1142
CHANGELOG.md
File diff suppressed because it is too large
Load Diff
12
LICENSE.md
12
LICENSE.md
@ -1,12 +0,0 @@
|
||||
Copyright © 2019, [Encode OSS Ltd](https://www.encode.io/).
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
147
README.md
147
README.md
@ -1,147 +0,0 @@
|
||||
<p align="center">
|
||||
<a href="https://www.python-httpx.org/"><img width="350" height="208" src="https://raw.githubusercontent.com/encode/httpx/master/docs/img/butterfly.png" alt='HTTPX'></a>
|
||||
</p>
|
||||
|
||||
<p align="center"><strong>HTTPX</strong> <em>- A next-generation HTTP client for Python.</em></p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://github.com/encode/httpx/actions">
|
||||
<img src="https://github.com/encode/httpx/workflows/Test%20Suite/badge.svg" alt="Test Suite">
|
||||
</a>
|
||||
<a href="https://pypi.org/project/httpx/">
|
||||
<img src="https://badge.fury.io/py/httpx.svg" alt="Package version">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
HTTPX is a fully featured HTTP client library for Python 3. It includes **an integrated command line client**, has support for both **HTTP/1.1 and HTTP/2**, and provides both **sync and async APIs**.
|
||||
|
||||
---
|
||||
|
||||
Install HTTPX using pip:
|
||||
|
||||
```shell
|
||||
$ pip install httpx
|
||||
```
|
||||
|
||||
Now, let's get started:
|
||||
|
||||
```pycon
|
||||
>>> import httpx
|
||||
>>> r = httpx.get('https://www.example.org/')
|
||||
>>> r
|
||||
<Response [200 OK]>
|
||||
>>> r.status_code
|
||||
200
|
||||
>>> r.headers['content-type']
|
||||
'text/html; charset=UTF-8'
|
||||
>>> r.text
|
||||
'<!doctype html>\n<html>\n<head>\n<title>Example Domain</title>...'
|
||||
```
|
||||
|
||||
Or, using the command-line client.
|
||||
|
||||
```shell
|
||||
$ pip install 'httpx[cli]' # The command line client is an optional dependency.
|
||||
```
|
||||
|
||||
Which now allows us to use HTTPX directly from the command-line...
|
||||
|
||||
<p align="center">
|
||||
<img width="700" src="docs/img/httpx-help.png" alt='httpx --help'>
|
||||
</p>
|
||||
|
||||
Sending a request...
|
||||
|
||||
<p align="center">
|
||||
<img width="700" src="docs/img/httpx-request.png" alt='httpx http://httpbin.org/json'>
|
||||
</p>
|
||||
|
||||
## Features
|
||||
|
||||
HTTPX builds on the well-established usability of `requests`, and gives you:
|
||||
|
||||
* A broadly [requests-compatible API](https://www.python-httpx.org/compatibility/).
|
||||
* An integrated command-line client.
|
||||
* HTTP/1.1 [and HTTP/2 support](https://www.python-httpx.org/http2/).
|
||||
* Standard synchronous interface, but with [async support if you need it](https://www.python-httpx.org/async/).
|
||||
* Ability to make requests directly to [WSGI applications](https://www.python-httpx.org/advanced/transports/#wsgi-transport) or [ASGI applications](https://www.python-httpx.org/advanced/transports/#asgi-transport).
|
||||
* Strict timeouts everywhere.
|
||||
* Fully type annotated.
|
||||
* 100% test coverage.
|
||||
|
||||
Plus all the standard features of `requests`...
|
||||
|
||||
* International Domains and URLs
|
||||
* Keep-Alive & Connection Pooling
|
||||
* Sessions with Cookie Persistence
|
||||
* Browser-style SSL Verification
|
||||
* Basic/Digest Authentication
|
||||
* Elegant Key/Value Cookies
|
||||
* Automatic Decompression
|
||||
* Automatic Content Decoding
|
||||
* Unicode Response Bodies
|
||||
* Multipart File Uploads
|
||||
* HTTP(S) Proxy Support
|
||||
* Connection Timeouts
|
||||
* Streaming Downloads
|
||||
* .netrc Support
|
||||
* Chunked Requests
|
||||
|
||||
## Installation
|
||||
|
||||
Install with pip:
|
||||
|
||||
```shell
|
||||
$ pip install httpx
|
||||
```
|
||||
|
||||
Or, to include the optional HTTP/2 support, use:
|
||||
|
||||
```shell
|
||||
$ pip install httpx[http2]
|
||||
```
|
||||
|
||||
HTTPX requires Python 3.9+.
|
||||
|
||||
## Documentation
|
||||
|
||||
Project documentation is available at [https://www.python-httpx.org/](https://www.python-httpx.org/).
|
||||
|
||||
For a run-through of all the basics, head over to the [QuickStart](https://www.python-httpx.org/quickstart/).
|
||||
|
||||
For more advanced topics, see the [Advanced Usage](https://www.python-httpx.org/advanced/) section, the [async support](https://www.python-httpx.org/async/) section, or the [HTTP/2](https://www.python-httpx.org/http2/) section.
|
||||
|
||||
The [Developer Interface](https://www.python-httpx.org/api/) provides a comprehensive API reference.
|
||||
|
||||
To find out about tools that integrate with HTTPX, see [Third Party Packages](https://www.python-httpx.org/third_party_packages/).
|
||||
|
||||
## Contribute
|
||||
|
||||
If you want to contribute with HTTPX check out the [Contributing Guide](https://www.python-httpx.org/contributing/) to learn how to start.
|
||||
|
||||
## Dependencies
|
||||
|
||||
The HTTPX project relies on these excellent libraries:
|
||||
|
||||
* `httpcore` - The underlying transport implementation for `httpx`.
|
||||
* `h11` - HTTP/1.1 support.
|
||||
* `certifi` - SSL certificates.
|
||||
* `idna` - Internationalized domain name support.
|
||||
* `sniffio` - Async library autodetection.
|
||||
|
||||
As well as these optional installs:
|
||||
|
||||
* `h2` - HTTP/2 support. *(Optional, with `httpx[http2]`)*
|
||||
* `socksio` - SOCKS proxy support. *(Optional, with `httpx[socks]`)*
|
||||
* `rich` - Rich terminal support. *(Optional, with `httpx[cli]`)*
|
||||
* `click` - Command line client support. *(Optional, with `httpx[cli]`)*
|
||||
* `brotli` or `brotlicffi` - Decoding for "brotli" compressed responses. *(Optional, with `httpx[brotli]`)*
|
||||
* `zstandard` - Decoding for "zstd" compressed responses. *(Optional, with `httpx[zstd]`)*
|
||||
|
||||
A huge amount of credit is due to `requests` for the API layout that
|
||||
much of this work follows, as well as to `urllib3` for plenty of design
|
||||
inspiration around the lower-level networking details.
|
||||
|
||||
---
|
||||
|
||||
<p align="center"><i>HTTPX is <a href="https://github.com/encode/httpx/blob/master/LICENSE.md">BSD licensed</a> code.<br/>Designed & crafted with care.</i><br/>— 🦋 —</p>
|
||||
1328
advanced/authentication/index.html
Normal file
1328
advanced/authentication/index.html
Normal file
File diff suppressed because it is too large
Load Diff
1514
advanced/clients/index.html
Normal file
1514
advanced/clients/index.html
Normal file
File diff suppressed because it is too large
Load Diff
1077
advanced/event-hooks/index.html
Normal file
1077
advanced/event-hooks/index.html
Normal file
File diff suppressed because it is too large
Load Diff
1458
advanced/extensions/index.html
Normal file
1458
advanced/extensions/index.html
Normal file
File diff suppressed because it is too large
Load Diff
1244
advanced/proxies/index.html
Normal file
1244
advanced/proxies/index.html
Normal file
File diff suppressed because it is too large
Load Diff
1032
advanced/resource-limits/index.html
Normal file
1032
advanced/resource-limits/index.html
Normal file
File diff suppressed because it is too large
Load Diff
1216
advanced/ssl/index.html
Normal file
1216
advanced/ssl/index.html
Normal file
File diff suppressed because it is too large
Load Diff
1173
advanced/text-encodings/index.html
Normal file
1173
advanced/text-encodings/index.html
Normal file
File diff suppressed because it is too large
Load Diff
1172
advanced/timeouts/index.html
Normal file
1172
advanced/timeouts/index.html
Normal file
File diff suppressed because it is too large
Load Diff
1803
advanced/transports/index.html
Normal file
1803
advanced/transports/index.html
Normal file
File diff suppressed because it is too large
Load Diff
1657
api/index.html
Normal file
1657
api/index.html
Normal file
File diff suppressed because it is too large
Load Diff
BIN
assets/images/favicon.png
Normal file
BIN
assets/images/favicon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
16
assets/javascripts/bundle.83f73b43.min.js
vendored
Normal file
16
assets/javascripts/bundle.83f73b43.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
7
assets/javascripts/bundle.83f73b43.min.js.map
Normal file
7
assets/javascripts/bundle.83f73b43.min.js.map
Normal file
File diff suppressed because one or more lines are too long
1
assets/javascripts/lunr/min/lunr.ar.min.js
vendored
Normal file
1
assets/javascripts/lunr/min/lunr.ar.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
18
assets/javascripts/lunr/min/lunr.da.min.js
vendored
Normal file
18
assets/javascripts/lunr/min/lunr.da.min.js
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
/*!
|
||||
* Lunr languages, `Danish` language
|
||||
* https://github.com/MihaiValentin/lunr-languages
|
||||
*
|
||||
* Copyright 2014, Mihai Valentin
|
||||
* http://www.mozilla.org/MPL/
|
||||
*/
|
||||
/*!
|
||||
* based on
|
||||
* Snowball JavaScript Library v0.3
|
||||
* http://code.google.com/p/urim/
|
||||
* http://snowball.tartarus.org/
|
||||
*
|
||||
* Copyright 2010, Oleg Mazko
|
||||
* http://www.mozilla.org/MPL/
|
||||
*/
|
||||
|
||||
!function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r():r()(e.lunr)}(this,function(){return function(e){if(void 0===e)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===e.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");e.da=function(){this.pipeline.reset(),this.pipeline.add(e.da.trimmer,e.da.stopWordFilter,e.da.stemmer),this.searchPipeline&&(this.searchPipeline.reset(),this.searchPipeline.add(e.da.stemmer))},e.da.wordCharacters="A-Za-zªºÀ-ÖØ-öø-ʸˠ-ˤᴀ-ᴥᴬ-ᵜᵢ-ᵥᵫ-ᵷᵹ-ᶾḀ-ỿⁱⁿₐ-ₜKÅℲⅎⅠ-ↈⱠ-ⱿꜢ-ꞇꞋ-ꞭꞰ-ꞷꟷ-ꟿꬰ-ꭚꭜ-ꭤff-stA-Za-z",e.da.trimmer=e.trimmerSupport.generateTrimmer(e.da.wordCharacters),e.Pipeline.registerFunction(e.da.trimmer,"trimmer-da"),e.da.stemmer=function(){var r=e.stemmerSupport.Among,i=e.stemmerSupport.SnowballProgram,n=new function(){function e(){var e,r=f.cursor+3;if(d=f.limit,0<=r&&r<=f.limit){for(a=r;;){if(e=f.cursor,f.in_grouping(w,97,248)){f.cursor=e;break}if(f.cursor=e,e>=f.limit)return;f.cursor++}for(;!f.out_grouping(w,97,248);){if(f.cursor>=f.limit)return;f.cursor++}d=f.cursor,d<a&&(d=a)}}function n(){var e,r;if(f.cursor>=d&&(r=f.limit_backward,f.limit_backward=d,f.ket=f.cursor,e=f.find_among_b(c,32),f.limit_backward=r,e))switch(f.bra=f.cursor,e){case 1:f.slice_del();break;case 2:f.in_grouping_b(p,97,229)&&f.slice_del()}}function t(){var e,r=f.limit-f.cursor;f.cursor>=d&&(e=f.limit_backward,f.limit_backward=d,f.ket=f.cursor,f.find_among_b(l,4)?(f.bra=f.cursor,f.limit_backward=e,f.cursor=f.limit-r,f.cursor>f.limit_backward&&(f.cursor--,f.bra=f.cursor,f.slice_del())):f.limit_backward=e)}function s(){var e,r,i,n=f.limit-f.cursor;if(f.ket=f.cursor,f.eq_s_b(2,"st")&&(f.bra=f.cursor,f.eq_s_b(2,"ig")&&f.slice_del()),f.cursor=f.limit-n,f.cursor>=d&&(r=f.limit_backward,f.limit_backward=d,f.ket=f.cursor,e=f.find_among_b(m,5),f.limit_backward=r,e))switch(f.bra=f.cursor,e){case 1:f.slice_del(),i=f.limit-f.cursor,t(),f.cursor=f.limit-i;break;case 2:f.slice_from("løs")}}function o(){var e;f.cursor>=d&&(e=f.limit_backward,f.limit_backward=d,f.ket=f.cursor,f.out_grouping_b(w,97,248)?(f.bra=f.cursor,u=f.slice_to(u),f.limit_backward=e,f.eq_v_b(u)&&f.slice_del()):f.limit_backward=e)}var a,d,u,c=[new r("hed",-1,1),new r("ethed",0,1),new r("ered",-1,1),new r("e",-1,1),new r("erede",3,1),new r("ende",3,1),new r("erende",5,1),new r("ene",3,1),new r("erne",3,1),new r("ere",3,1),new r("en",-1,1),new r("heden",10,1),new r("eren",10,1),new r("er",-1,1),new r("heder",13,1),new r("erer",13,1),new r("s",-1,2),new r("heds",16,1),new r("es",16,1),new r("endes",18,1),new r("erendes",19,1),new r("enes",18,1),new r("ernes",18,1),new r("eres",18,1),new r("ens",16,1),new r("hedens",24,1),new r("erens",24,1),new r("ers",16,1),new r("ets",16,1),new r("erets",28,1),new r("et",-1,1),new r("eret",30,1)],l=[new r("gd",-1,-1),new r("dt",-1,-1),new r("gt",-1,-1),new r("kt",-1,-1)],m=[new r("ig",-1,1),new r("lig",0,1),new r("elig",1,1),new r("els",-1,1),new r("løst",-1,2)],w=[17,65,16,1,0,0,0,0,0,0,0,0,0,0,0,0,48,0,128],p=[239,254,42,3,0,0,0,0,0,0,0,0,0,0,0,0,16],f=new i;this.setCurrent=function(e){f.setCurrent(e)},this.getCurrent=function(){return f.getCurrent()},this.stem=function(){var r=f.cursor;return e(),f.limit_backward=r,f.cursor=f.limit,n(),f.cursor=f.limit,t(),f.cursor=f.limit,s(),f.cursor=f.limit,o(),!0}};return function(e){return"function"==typeof e.update?e.update(function(e){return n.setCurrent(e),n.stem(),n.getCurrent()}):(n.setCurrent(e),n.stem(),n.getCurrent())}}(),e.Pipeline.registerFunction(e.da.stemmer,"stemmer-da"),e.da.stopWordFilter=e.generateStopWordFilter("ad af alle alt anden at blev blive bliver da de dem den denne der deres det dette dig din disse dog du efter eller en end er et for fra ham han hans har havde have hende hendes her hos hun hvad hvis hvor i ikke ind jeg jer jo kunne man mange med meget men mig min mine mit mod ned noget nogle nu når og også om op os over på selv sig sin sine sit skal skulle som sådan thi til ud under var vi vil ville vor være været".split(" ")),e.Pipeline.registerFunction(e.da.stopWordFilter,"stopWordFilter-da")}});
|
||||
18
assets/javascripts/lunr/min/lunr.de.min.js
vendored
Normal file
18
assets/javascripts/lunr/min/lunr.de.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
18
assets/javascripts/lunr/min/lunr.du.min.js
vendored
Normal file
18
assets/javascripts/lunr/min/lunr.du.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
assets/javascripts/lunr/min/lunr.el.min.js
vendored
Normal file
1
assets/javascripts/lunr/min/lunr.el.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
18
assets/javascripts/lunr/min/lunr.es.min.js
vendored
Normal file
18
assets/javascripts/lunr/min/lunr.es.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
18
assets/javascripts/lunr/min/lunr.fi.min.js
vendored
Normal file
18
assets/javascripts/lunr/min/lunr.fi.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
18
assets/javascripts/lunr/min/lunr.fr.min.js
vendored
Normal file
18
assets/javascripts/lunr/min/lunr.fr.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
assets/javascripts/lunr/min/lunr.he.min.js
vendored
Normal file
1
assets/javascripts/lunr/min/lunr.he.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
assets/javascripts/lunr/min/lunr.hi.min.js
vendored
Normal file
1
assets/javascripts/lunr/min/lunr.hi.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
!function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r():r()(e.lunr)}(this,function(){return function(e){if(void 0===e)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===e.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");e.hi=function(){this.pipeline.reset(),this.pipeline.add(e.hi.trimmer,e.hi.stopWordFilter,e.hi.stemmer),this.searchPipeline&&(this.searchPipeline.reset(),this.searchPipeline.add(e.hi.stemmer))},e.hi.wordCharacters="ऀ-ःऄ-एऐ-टठ-यर-िी-ॏॐ-य़ॠ-९॰-ॿa-zA-Za-zA-Z0-90-9",e.hi.trimmer=e.trimmerSupport.generateTrimmer(e.hi.wordCharacters),e.Pipeline.registerFunction(e.hi.trimmer,"trimmer-hi"),e.hi.stopWordFilter=e.generateStopWordFilter("अत अपना अपनी अपने अभी अंदर आदि आप इत्यादि इन इनका इन्हीं इन्हें इन्हों इस इसका इसकी इसके इसमें इसी इसे उन उनका उनकी उनके उनको उन्हीं उन्हें उन्हों उस उसके उसी उसे एक एवं एस ऐसे और कई कर करता करते करना करने करें कहते कहा का काफ़ी कि कितना किन्हें किन्हों किया किर किस किसी किसे की कुछ कुल के को कोई कौन कौनसा गया घर जब जहाँ जा जितना जिन जिन्हें जिन्हों जिस जिसे जीधर जैसा जैसे जो तक तब तरह तिन तिन्हें तिन्हों तिस तिसे तो था थी थे दबारा दिया दुसरा दूसरे दो द्वारा न नके नहीं ना निहायत नीचे ने पर पहले पूरा पे फिर बनी बही बहुत बाद बाला बिलकुल भी भीतर मगर मानो मे में यदि यह यहाँ यही या यिह ये रखें रहा रहे ऱ्वासा लिए लिये लेकिन व वग़ैरह वर्ग वह वहाँ वहीं वाले वुह वे वो सकता सकते सबसे सभी साथ साबुत साभ सारा से सो संग ही हुआ हुई हुए है हैं हो होता होती होते होना होने".split(" ")),e.hi.stemmer=function(){return function(e){return"function"==typeof e.update?e.update(function(e){return e}):e}}();var r=e.wordcut;r.init(),e.hi.tokenizer=function(i){if(!arguments.length||null==i||void 0==i)return[];if(Array.isArray(i))return i.map(function(r){return isLunr2?new e.Token(r.toLowerCase()):r.toLowerCase()});var t=i.toString().toLowerCase().replace(/^\s+/,"");return r.cut(t).split("|")},e.Pipeline.registerFunction(e.hi.stemmer,"stemmer-hi"),e.Pipeline.registerFunction(e.hi.stopWordFilter,"stopWordFilter-hi")}});
|
||||
18
assets/javascripts/lunr/min/lunr.hu.min.js
vendored
Normal file
18
assets/javascripts/lunr/min/lunr.hu.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
assets/javascripts/lunr/min/lunr.hy.min.js
vendored
Normal file
1
assets/javascripts/lunr/min/lunr.hy.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
!function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r():r()(e.lunr)}(this,function(){return function(e){if(void 0===e)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===e.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");e.hy=function(){this.pipeline.reset(),this.pipeline.add(e.hy.trimmer,e.hy.stopWordFilter)},e.hy.wordCharacters="[A-Za-z-֏ff-ﭏ]",e.hy.trimmer=e.trimmerSupport.generateTrimmer(e.hy.wordCharacters),e.Pipeline.registerFunction(e.hy.trimmer,"trimmer-hy"),e.hy.stopWordFilter=e.generateStopWordFilter("դու և եք էիր էիք հետո նաև նրանք որը վրա է որ պիտի են այս մեջ ն իր ու ի այդ որոնք այն կամ էր մի ես համար այլ իսկ էին ենք հետ ին թ էինք մենք նրա նա դուք եմ էի ըստ որպես ում".split(" ")),e.Pipeline.registerFunction(e.hy.stopWordFilter,"stopWordFilter-hy"),e.hy.stemmer=function(){return function(e){return"function"==typeof e.update?e.update(function(e){return e}):e}}(),e.Pipeline.registerFunction(e.hy.stemmer,"stemmer-hy")}});
|
||||
18
assets/javascripts/lunr/min/lunr.it.min.js
vendored
Normal file
18
assets/javascripts/lunr/min/lunr.it.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
assets/javascripts/lunr/min/lunr.ja.min.js
vendored
Normal file
1
assets/javascripts/lunr/min/lunr.ja.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
!function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r():r()(e.lunr)}(this,function(){return function(e){if(void 0===e)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===e.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");var r="2"==e.version[0];e.ja=function(){this.pipeline.reset(),this.pipeline.add(e.ja.trimmer,e.ja.stopWordFilter,e.ja.stemmer),r?this.tokenizer=e.ja.tokenizer:(e.tokenizer&&(e.tokenizer=e.ja.tokenizer),this.tokenizerFn&&(this.tokenizerFn=e.ja.tokenizer))};var t=new e.TinySegmenter;e.ja.tokenizer=function(i){var n,o,s,p,a,u,m,l,c,f;if(!arguments.length||null==i||void 0==i)return[];if(Array.isArray(i))return i.map(function(t){return r?new e.Token(t.toLowerCase()):t.toLowerCase()});for(o=i.toString().toLowerCase().replace(/^\s+/,""),n=o.length-1;n>=0;n--)if(/\S/.test(o.charAt(n))){o=o.substring(0,n+1);break}for(a=[],s=o.length,c=0,l=0;c<=s;c++)if(u=o.charAt(c),m=c-l,u.match(/\s/)||c==s){if(m>0)for(p=t.segment(o.slice(l,c)).filter(function(e){return!!e}),f=l,n=0;n<p.length;n++)r?a.push(new e.Token(p[n],{position:[f,p[n].length],index:a.length})):a.push(p[n]),f+=p[n].length;l=c+1}return a},e.ja.stemmer=function(){return function(e){return e}}(),e.Pipeline.registerFunction(e.ja.stemmer,"stemmer-ja"),e.ja.wordCharacters="一二三四五六七八九十百千万億兆一-龠々〆ヵヶぁ-んァ-ヴーア-ン゙a-zA-Za-zA-Z0-90-9",e.ja.trimmer=e.trimmerSupport.generateTrimmer(e.ja.wordCharacters),e.Pipeline.registerFunction(e.ja.trimmer,"trimmer-ja"),e.ja.stopWordFilter=e.generateStopWordFilter("これ それ あれ この その あの ここ そこ あそこ こちら どこ だれ なに なん 何 私 貴方 貴方方 我々 私達 あの人 あのかた 彼女 彼 です あります おります います は が の に を で え から まで より も どの と し それで しかし".split(" ")),e.Pipeline.registerFunction(e.ja.stopWordFilter,"stopWordFilter-ja"),e.jp=e.ja,e.Pipeline.registerFunction(e.jp.stemmer,"stemmer-jp"),e.Pipeline.registerFunction(e.jp.trimmer,"trimmer-jp"),e.Pipeline.registerFunction(e.jp.stopWordFilter,"stopWordFilter-jp")}});
|
||||
1
assets/javascripts/lunr/min/lunr.jp.min.js
vendored
Normal file
1
assets/javascripts/lunr/min/lunr.jp.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
module.exports=require("./lunr.ja");
|
||||
1
assets/javascripts/lunr/min/lunr.kn.min.js
vendored
Normal file
1
assets/javascripts/lunr/min/lunr.kn.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
!function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r():r()(e.lunr)}(this,function(){return function(e){if(void 0===e)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===e.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");e.kn=function(){this.pipeline.reset(),this.pipeline.add(e.kn.trimmer,e.kn.stopWordFilter,e.kn.stemmer),this.searchPipeline&&(this.searchPipeline.reset(),this.searchPipeline.add(e.kn.stemmer))},e.kn.wordCharacters="ಀ-಄ಅ-ಔಕ-ಹಾ-ೌ಼-ಽೕ-ೖೝ-ೞೠ-ೡೢ-ೣ೦-೯ೱ-ೳ",e.kn.trimmer=e.trimmerSupport.generateTrimmer(e.kn.wordCharacters),e.Pipeline.registerFunction(e.kn.trimmer,"trimmer-kn"),e.kn.stopWordFilter=e.generateStopWordFilter("ಮತ್ತು ಈ ಒಂದು ರಲ್ಲಿ ಹಾಗೂ ಎಂದು ಅಥವಾ ಇದು ರ ಅವರು ಎಂಬ ಮೇಲೆ ಅವರ ತನ್ನ ಆದರೆ ತಮ್ಮ ನಂತರ ಮೂಲಕ ಹೆಚ್ಚು ನ ಆ ಕೆಲವು ಅನೇಕ ಎರಡು ಹಾಗು ಪ್ರಮುಖ ಇದನ್ನು ಇದರ ಸುಮಾರು ಅದರ ಅದು ಮೊದಲ ಬಗ್ಗೆ ನಲ್ಲಿ ರಂದು ಇತರ ಅತ್ಯಂತ ಹೆಚ್ಚಿನ ಸಹ ಸಾಮಾನ್ಯವಾಗಿ ನೇ ಹಲವಾರು ಹೊಸ ದಿ ಕಡಿಮೆ ಯಾವುದೇ ಹೊಂದಿದೆ ದೊಡ್ಡ ಅನ್ನು ಇವರು ಪ್ರಕಾರ ಇದೆ ಮಾತ್ರ ಕೂಡ ಇಲ್ಲಿ ಎಲ್ಲಾ ವಿವಿಧ ಅದನ್ನು ಹಲವು ರಿಂದ ಕೇವಲ ದ ದಕ್ಷಿಣ ಗೆ ಅವನ ಅತಿ ನೆಯ ಬಹಳ ಕೆಲಸ ಎಲ್ಲ ಪ್ರತಿ ಇತ್ಯಾದಿ ಇವು ಬೇರೆ ಹೀಗೆ ನಡುವೆ ಇದಕ್ಕೆ ಎಸ್ ಇವರ ಮೊದಲು ಶ್ರೀ ಮಾಡುವ ಇದರಲ್ಲಿ ರೀತಿಯ ಮಾಡಿದ ಕಾಲ ಅಲ್ಲಿ ಮಾಡಲು ಅದೇ ಈಗ ಅವು ಗಳು ಎ ಎಂಬುದು ಅವನು ಅಂದರೆ ಅವರಿಗೆ ಇರುವ ವಿಶೇಷ ಮುಂದೆ ಅವುಗಳ ಮುಂತಾದ ಮೂಲ ಬಿ ಮೀ ಒಂದೇ ಇನ್ನೂ ಹೆಚ್ಚಾಗಿ ಮಾಡಿ ಅವರನ್ನು ಇದೇ ಯ ರೀತಿಯಲ್ಲಿ ಜೊತೆ ಅದರಲ್ಲಿ ಮಾಡಿದರು ನಡೆದ ಆಗ ಮತ್ತೆ ಪೂರ್ವ ಆತ ಬಂದ ಯಾವ ಒಟ್ಟು ಇತರೆ ಹಿಂದೆ ಪ್ರಮಾಣದ ಗಳನ್ನು ಕುರಿತು ಯು ಆದ್ದರಿಂದ ಅಲ್ಲದೆ ನಗರದ ಮೇಲಿನ ಏಕೆಂದರೆ ರಷ್ಟು ಎಂಬುದನ್ನು ಬಾರಿ ಎಂದರೆ ಹಿಂದಿನ ಆದರೂ ಆದ ಸಂಬಂಧಿಸಿದ ಮತ್ತೊಂದು ಸಿ ಆತನ ".split(" ")),e.kn.stemmer=function(){return function(e){return"function"==typeof e.update?e.update(function(e){return e}):e}}();var r=e.wordcut;r.init(),e.kn.tokenizer=function(t){if(!arguments.length||null==t||void 0==t)return[];if(Array.isArray(t))return t.map(function(r){return isLunr2?new e.Token(r.toLowerCase()):r.toLowerCase()});var n=t.toString().toLowerCase().replace(/^\s+/,"");return r.cut(n).split("|")},e.Pipeline.registerFunction(e.kn.stemmer,"stemmer-kn"),e.Pipeline.registerFunction(e.kn.stopWordFilter,"stopWordFilter-kn")}});
|
||||
1
assets/javascripts/lunr/min/lunr.ko.min.js
vendored
Normal file
1
assets/javascripts/lunr/min/lunr.ko.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
assets/javascripts/lunr/min/lunr.multi.min.js
vendored
Normal file
1
assets/javascripts/lunr/min/lunr.multi.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
!function(e,t){"function"==typeof define&&define.amd?define(t):"object"==typeof exports?module.exports=t():t()(e.lunr)}(this,function(){return function(e){e.multiLanguage=function(){for(var t=Array.prototype.slice.call(arguments),i=t.join("-"),r="",n=[],s=[],p=0;p<t.length;++p)"en"==t[p]?(r+="\\w",n.unshift(e.stopWordFilter),n.push(e.stemmer),s.push(e.stemmer)):(r+=e[t[p]].wordCharacters,e[t[p]].stopWordFilter&&n.unshift(e[t[p]].stopWordFilter),e[t[p]].stemmer&&(n.push(e[t[p]].stemmer),s.push(e[t[p]].stemmer)));var o=e.trimmerSupport.generateTrimmer(r);return e.Pipeline.registerFunction(o,"lunr-multi-trimmer-"+i),n.unshift(o),function(){this.pipeline.reset(),this.pipeline.add.apply(this.pipeline,n),this.searchPipeline&&(this.searchPipeline.reset(),this.searchPipeline.add.apply(this.searchPipeline,s))}}}});
|
||||
18
assets/javascripts/lunr/min/lunr.nl.min.js
vendored
Normal file
18
assets/javascripts/lunr/min/lunr.nl.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
18
assets/javascripts/lunr/min/lunr.no.min.js
vendored
Normal file
18
assets/javascripts/lunr/min/lunr.no.min.js
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
/*!
|
||||
* Lunr languages, `Norwegian` language
|
||||
* https://github.com/MihaiValentin/lunr-languages
|
||||
*
|
||||
* Copyright 2014, Mihai Valentin
|
||||
* http://www.mozilla.org/MPL/
|
||||
*/
|
||||
/*!
|
||||
* based on
|
||||
* Snowball JavaScript Library v0.3
|
||||
* http://code.google.com/p/urim/
|
||||
* http://snowball.tartarus.org/
|
||||
*
|
||||
* Copyright 2010, Oleg Mazko
|
||||
* http://www.mozilla.org/MPL/
|
||||
*/
|
||||
|
||||
!function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r():r()(e.lunr)}(this,function(){return function(e){if(void 0===e)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===e.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");e.no=function(){this.pipeline.reset(),this.pipeline.add(e.no.trimmer,e.no.stopWordFilter,e.no.stemmer),this.searchPipeline&&(this.searchPipeline.reset(),this.searchPipeline.add(e.no.stemmer))},e.no.wordCharacters="A-Za-zªºÀ-ÖØ-öø-ʸˠ-ˤᴀ-ᴥᴬ-ᵜᵢ-ᵥᵫ-ᵷᵹ-ᶾḀ-ỿⁱⁿₐ-ₜKÅℲⅎⅠ-ↈⱠ-ⱿꜢ-ꞇꞋ-ꞭꞰ-ꞷꟷ-ꟿꬰ-ꭚꭜ-ꭤff-stA-Za-z",e.no.trimmer=e.trimmerSupport.generateTrimmer(e.no.wordCharacters),e.Pipeline.registerFunction(e.no.trimmer,"trimmer-no"),e.no.stemmer=function(){var r=e.stemmerSupport.Among,n=e.stemmerSupport.SnowballProgram,i=new function(){function e(){var e,r=w.cursor+3;if(a=w.limit,0<=r||r<=w.limit){for(s=r;;){if(e=w.cursor,w.in_grouping(d,97,248)){w.cursor=e;break}if(e>=w.limit)return;w.cursor=e+1}for(;!w.out_grouping(d,97,248);){if(w.cursor>=w.limit)return;w.cursor++}a=w.cursor,a<s&&(a=s)}}function i(){var e,r,n;if(w.cursor>=a&&(r=w.limit_backward,w.limit_backward=a,w.ket=w.cursor,e=w.find_among_b(m,29),w.limit_backward=r,e))switch(w.bra=w.cursor,e){case 1:w.slice_del();break;case 2:n=w.limit-w.cursor,w.in_grouping_b(c,98,122)?w.slice_del():(w.cursor=w.limit-n,w.eq_s_b(1,"k")&&w.out_grouping_b(d,97,248)&&w.slice_del());break;case 3:w.slice_from("er")}}function t(){var e,r=w.limit-w.cursor;w.cursor>=a&&(e=w.limit_backward,w.limit_backward=a,w.ket=w.cursor,w.find_among_b(u,2)?(w.bra=w.cursor,w.limit_backward=e,w.cursor=w.limit-r,w.cursor>w.limit_backward&&(w.cursor--,w.bra=w.cursor,w.slice_del())):w.limit_backward=e)}function o(){var e,r;w.cursor>=a&&(r=w.limit_backward,w.limit_backward=a,w.ket=w.cursor,e=w.find_among_b(l,11),e?(w.bra=w.cursor,w.limit_backward=r,1==e&&w.slice_del()):w.limit_backward=r)}var s,a,m=[new r("a",-1,1),new r("e",-1,1),new r("ede",1,1),new r("ande",1,1),new r("ende",1,1),new r("ane",1,1),new r("ene",1,1),new r("hetene",6,1),new r("erte",1,3),new r("en",-1,1),new r("heten",9,1),new r("ar",-1,1),new r("er",-1,1),new r("heter",12,1),new r("s",-1,2),new r("as",14,1),new r("es",14,1),new r("edes",16,1),new r("endes",16,1),new r("enes",16,1),new r("hetenes",19,1),new r("ens",14,1),new r("hetens",21,1),new r("ers",14,1),new r("ets",14,1),new r("et",-1,1),new r("het",25,1),new r("ert",-1,3),new r("ast",-1,1)],u=[new r("dt",-1,-1),new r("vt",-1,-1)],l=[new r("leg",-1,1),new r("eleg",0,1),new r("ig",-1,1),new r("eig",2,1),new r("lig",2,1),new r("elig",4,1),new r("els",-1,1),new r("lov",-1,1),new r("elov",7,1),new r("slov",7,1),new r("hetslov",9,1)],d=[17,65,16,1,0,0,0,0,0,0,0,0,0,0,0,0,48,0,128],c=[119,125,149,1],w=new n;this.setCurrent=function(e){w.setCurrent(e)},this.getCurrent=function(){return w.getCurrent()},this.stem=function(){var r=w.cursor;return e(),w.limit_backward=r,w.cursor=w.limit,i(),w.cursor=w.limit,t(),w.cursor=w.limit,o(),!0}};return function(e){return"function"==typeof e.update?e.update(function(e){return i.setCurrent(e),i.stem(),i.getCurrent()}):(i.setCurrent(e),i.stem(),i.getCurrent())}}(),e.Pipeline.registerFunction(e.no.stemmer,"stemmer-no"),e.no.stopWordFilter=e.generateStopWordFilter("alle at av bare begge ble blei bli blir blitt både båe da de deg dei deim deira deires dem den denne der dere deres det dette di din disse ditt du dykk dykkar då eg ein eit eitt eller elles en enn er et ett etter for fordi fra før ha hadde han hans har hennar henne hennes her hjå ho hoe honom hoss hossen hun hva hvem hver hvilke hvilken hvis hvor hvordan hvorfor i ikke ikkje ikkje ingen ingi inkje inn inni ja jeg kan kom korleis korso kun kunne kva kvar kvarhelst kven kvi kvifor man mange me med medan meg meget mellom men mi min mine mitt mot mykje ned no noe noen noka noko nokon nokor nokre nå når og også om opp oss over på samme seg selv si si sia sidan siden sin sine sitt sjøl skal skulle slik so som som somme somt så sånn til um upp ut uten var vart varte ved vere verte vi vil ville vore vors vort vår være være vært å".split(" ")),e.Pipeline.registerFunction(e.no.stopWordFilter,"stopWordFilter-no")}});
|
||||
18
assets/javascripts/lunr/min/lunr.pt.min.js
vendored
Normal file
18
assets/javascripts/lunr/min/lunr.pt.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
18
assets/javascripts/lunr/min/lunr.ro.min.js
vendored
Normal file
18
assets/javascripts/lunr/min/lunr.ro.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
18
assets/javascripts/lunr/min/lunr.ru.min.js
vendored
Normal file
18
assets/javascripts/lunr/min/lunr.ru.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
assets/javascripts/lunr/min/lunr.sa.min.js
vendored
Normal file
1
assets/javascripts/lunr/min/lunr.sa.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
!function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r():r()(e.lunr)}(this,function(){return function(e){if(void 0===e)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===e.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");e.sa=function(){this.pipeline.reset(),this.pipeline.add(e.sa.trimmer,e.sa.stopWordFilter,e.sa.stemmer),this.searchPipeline&&(this.searchPipeline.reset(),this.searchPipeline.add(e.sa.stemmer))},e.sa.wordCharacters="ऀ-ःऄ-एऐ-टठ-यर-िी-ॏॐ-य़ॠ-९॰-ॿ꣠-꣱ꣲ-ꣷ꣸-ꣻ꣼-ꣽꣾ-ꣿᆰ0-ᆰ9",e.sa.trimmer=e.trimmerSupport.generateTrimmer(e.sa.wordCharacters),e.Pipeline.registerFunction(e.sa.trimmer,"trimmer-sa"),e.sa.stopWordFilter=e.generateStopWordFilter('तथा अयम् एकम् इत्यस्मिन् तथा तत् वा अयम् इत्यस्य ते आहूत उपरि तेषाम् किन्तु तेषाम् तदा इत्यनेन अधिकः इत्यस्य तत् केचन बहवः द्वि तथा महत्वपूर्णः अयम् अस्य विषये अयं अस्ति तत् प्रथमः विषये इत्युपरि इत्युपरि इतर अधिकतमः अधिकः अपि सामान्यतया ठ इतरेतर नूतनम् द न्यूनम् कश्चित् वा विशालः द सः अस्ति तदनुसारम् तत्र अस्ति केवलम् अपि अत्र सर्वे विविधाः तत् बहवः यतः इदानीम् द दक्षिण इत्यस्मै तस्य उपरि नथ अतीव कार्यम् सर्वे एकैकम् इत्यादि। एते सन्ति उत इत्थम् मध्ये एतदर्थं . स कस्य प्रथमः श्री. करोति अस्मिन् प्रकारः निर्मिता कालः तत्र कर्तुं समान अधुना ते सन्ति स एकः अस्ति सः अर्थात् तेषां कृते . स्थितम् विशेषः अग्रिम तेषाम् समान स्रोतः ख म समान इदानीमपि अधिकतया करोतु ते समान इत्यस्य वीथी सह यस्मिन् कृतवान् धृतः तदा पुनः पूर्वं सः आगतः किम् कुल इतर पुरा मात्रा स विषये उ अतएव अपि नगरस्य उपरि यतः प्रतिशतं कतरः कालः साधनानि भूत तथापि जात सम्बन्धि अन्यत् ग अतः अस्माकं स्वकीयाः अस्माकं इदानीं अन्तः इत्यादयः भवन्तः इत्यादयः एते एताः तस्य अस्य इदम् एते तेषां तेषां तेषां तान् तेषां तेषां तेषां समानः सः एकः च तादृशाः बहवः अन्ये च वदन्ति यत् कियत् कस्मै कस्मै यस्मै यस्मै यस्मै यस्मै न अतिनीचः किन्तु प्रथमं सम्पूर्णतया ततः चिरकालानन्तरं पुस्तकं सम्पूर्णतया अन्तः किन्तु अत्र वा इह इव श्रद्धाय अवशिष्यते परन्तु अन्ये वर्गाः सन्ति ते सन्ति शक्नुवन्ति सर्वे मिलित्वा सर्वे एकत्र"'.split(" ")),e.sa.stemmer=function(){return function(e){return"function"==typeof e.update?e.update(function(e){return e}):e}}();var r=e.wordcut;r.init(),e.sa.tokenizer=function(t){if(!arguments.length||null==t||void 0==t)return[];if(Array.isArray(t))return t.map(function(r){return isLunr2?new e.Token(r.toLowerCase()):r.toLowerCase()});var i=t.toString().toLowerCase().replace(/^\s+/,"");return r.cut(i).split("|")},e.Pipeline.registerFunction(e.sa.stemmer,"stemmer-sa"),e.Pipeline.registerFunction(e.sa.stopWordFilter,"stopWordFilter-sa")}});
|
||||
1
assets/javascripts/lunr/min/lunr.stemmer.support.min.js
vendored
Normal file
1
assets/javascripts/lunr/min/lunr.stemmer.support.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
!function(r,t){"function"==typeof define&&define.amd?define(t):"object"==typeof exports?module.exports=t():t()(r.lunr)}(this,function(){return function(r){r.stemmerSupport={Among:function(r,t,i,s){if(this.toCharArray=function(r){for(var t=r.length,i=new Array(t),s=0;s<t;s++)i[s]=r.charCodeAt(s);return i},!r&&""!=r||!t&&0!=t||!i)throw"Bad Among initialisation: s:"+r+", substring_i: "+t+", result: "+i;this.s_size=r.length,this.s=this.toCharArray(r),this.substring_i=t,this.result=i,this.method=s},SnowballProgram:function(){var r;return{bra:0,ket:0,limit:0,cursor:0,limit_backward:0,setCurrent:function(t){r=t,this.cursor=0,this.limit=t.length,this.limit_backward=0,this.bra=this.cursor,this.ket=this.limit},getCurrent:function(){var t=r;return r=null,t},in_grouping:function(t,i,s){if(this.cursor<this.limit){var e=r.charCodeAt(this.cursor);if(e<=s&&e>=i&&(e-=i,t[e>>3]&1<<(7&e)))return this.cursor++,!0}return!1},in_grouping_b:function(t,i,s){if(this.cursor>this.limit_backward){var e=r.charCodeAt(this.cursor-1);if(e<=s&&e>=i&&(e-=i,t[e>>3]&1<<(7&e)))return this.cursor--,!0}return!1},out_grouping:function(t,i,s){if(this.cursor<this.limit){var e=r.charCodeAt(this.cursor);if(e>s||e<i)return this.cursor++,!0;if(e-=i,!(t[e>>3]&1<<(7&e)))return this.cursor++,!0}return!1},out_grouping_b:function(t,i,s){if(this.cursor>this.limit_backward){var e=r.charCodeAt(this.cursor-1);if(e>s||e<i)return this.cursor--,!0;if(e-=i,!(t[e>>3]&1<<(7&e)))return this.cursor--,!0}return!1},eq_s:function(t,i){if(this.limit-this.cursor<t)return!1;for(var s=0;s<t;s++)if(r.charCodeAt(this.cursor+s)!=i.charCodeAt(s))return!1;return this.cursor+=t,!0},eq_s_b:function(t,i){if(this.cursor-this.limit_backward<t)return!1;for(var s=0;s<t;s++)if(r.charCodeAt(this.cursor-t+s)!=i.charCodeAt(s))return!1;return this.cursor-=t,!0},find_among:function(t,i){for(var s=0,e=i,n=this.cursor,u=this.limit,o=0,h=0,c=!1;;){for(var a=s+(e-s>>1),f=0,l=o<h?o:h,_=t[a],m=l;m<_.s_size;m++){if(n+l==u){f=-1;break}if(f=r.charCodeAt(n+l)-_.s[m])break;l++}if(f<0?(e=a,h=l):(s=a,o=l),e-s<=1){if(s>0||e==s||c)break;c=!0}}for(;;){var _=t[s];if(o>=_.s_size){if(this.cursor=n+_.s_size,!_.method)return _.result;var b=_.method();if(this.cursor=n+_.s_size,b)return _.result}if((s=_.substring_i)<0)return 0}},find_among_b:function(t,i){for(var s=0,e=i,n=this.cursor,u=this.limit_backward,o=0,h=0,c=!1;;){for(var a=s+(e-s>>1),f=0,l=o<h?o:h,_=t[a],m=_.s_size-1-l;m>=0;m--){if(n-l==u){f=-1;break}if(f=r.charCodeAt(n-1-l)-_.s[m])break;l++}if(f<0?(e=a,h=l):(s=a,o=l),e-s<=1){if(s>0||e==s||c)break;c=!0}}for(;;){var _=t[s];if(o>=_.s_size){if(this.cursor=n-_.s_size,!_.method)return _.result;var b=_.method();if(this.cursor=n-_.s_size,b)return _.result}if((s=_.substring_i)<0)return 0}},replace_s:function(t,i,s){var e=s.length-(i-t),n=r.substring(0,t),u=r.substring(i);return r=n+s+u,this.limit+=e,this.cursor>=i?this.cursor+=e:this.cursor>t&&(this.cursor=t),e},slice_check:function(){if(this.bra<0||this.bra>this.ket||this.ket>this.limit||this.limit>r.length)throw"faulty slice operation"},slice_from:function(r){this.slice_check(),this.replace_s(this.bra,this.ket,r)},slice_del:function(){this.slice_from("")},insert:function(r,t,i){var s=this.replace_s(r,t,i);r<=this.bra&&(this.bra+=s),r<=this.ket&&(this.ket+=s)},slice_to:function(){return this.slice_check(),r.substring(this.bra,this.ket)},eq_v_b:function(r){return this.eq_s_b(r.length,r)}}}},r.trimmerSupport={generateTrimmer:function(r){var t=new RegExp("^[^"+r+"]+"),i=new RegExp("[^"+r+"]+$");return function(r){return"function"==typeof r.update?r.update(function(r){return r.replace(t,"").replace(i,"")}):r.replace(t,"").replace(i,"")}}}}});
|
||||
18
assets/javascripts/lunr/min/lunr.sv.min.js
vendored
Normal file
18
assets/javascripts/lunr/min/lunr.sv.min.js
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
/*!
|
||||
* Lunr languages, `Swedish` language
|
||||
* https://github.com/MihaiValentin/lunr-languages
|
||||
*
|
||||
* Copyright 2014, Mihai Valentin
|
||||
* http://www.mozilla.org/MPL/
|
||||
*/
|
||||
/*!
|
||||
* based on
|
||||
* Snowball JavaScript Library v0.3
|
||||
* http://code.google.com/p/urim/
|
||||
* http://snowball.tartarus.org/
|
||||
*
|
||||
* Copyright 2010, Oleg Mazko
|
||||
* http://www.mozilla.org/MPL/
|
||||
*/
|
||||
|
||||
!function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r():r()(e.lunr)}(this,function(){return function(e){if(void 0===e)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===e.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");e.sv=function(){this.pipeline.reset(),this.pipeline.add(e.sv.trimmer,e.sv.stopWordFilter,e.sv.stemmer),this.searchPipeline&&(this.searchPipeline.reset(),this.searchPipeline.add(e.sv.stemmer))},e.sv.wordCharacters="A-Za-zªºÀ-ÖØ-öø-ʸˠ-ˤᴀ-ᴥᴬ-ᵜᵢ-ᵥᵫ-ᵷᵹ-ᶾḀ-ỿⁱⁿₐ-ₜKÅℲⅎⅠ-ↈⱠ-ⱿꜢ-ꞇꞋ-ꞭꞰ-ꞷꟷ-ꟿꬰ-ꭚꭜ-ꭤff-stA-Za-z",e.sv.trimmer=e.trimmerSupport.generateTrimmer(e.sv.wordCharacters),e.Pipeline.registerFunction(e.sv.trimmer,"trimmer-sv"),e.sv.stemmer=function(){var r=e.stemmerSupport.Among,n=e.stemmerSupport.SnowballProgram,t=new function(){function e(){var e,r=w.cursor+3;if(o=w.limit,0<=r||r<=w.limit){for(a=r;;){if(e=w.cursor,w.in_grouping(l,97,246)){w.cursor=e;break}if(w.cursor=e,w.cursor>=w.limit)return;w.cursor++}for(;!w.out_grouping(l,97,246);){if(w.cursor>=w.limit)return;w.cursor++}o=w.cursor,o<a&&(o=a)}}function t(){var e,r=w.limit_backward;if(w.cursor>=o&&(w.limit_backward=o,w.cursor=w.limit,w.ket=w.cursor,e=w.find_among_b(u,37),w.limit_backward=r,e))switch(w.bra=w.cursor,e){case 1:w.slice_del();break;case 2:w.in_grouping_b(d,98,121)&&w.slice_del()}}function i(){var e=w.limit_backward;w.cursor>=o&&(w.limit_backward=o,w.cursor=w.limit,w.find_among_b(c,7)&&(w.cursor=w.limit,w.ket=w.cursor,w.cursor>w.limit_backward&&(w.bra=--w.cursor,w.slice_del())),w.limit_backward=e)}function s(){var e,r;if(w.cursor>=o){if(r=w.limit_backward,w.limit_backward=o,w.cursor=w.limit,w.ket=w.cursor,e=w.find_among_b(m,5))switch(w.bra=w.cursor,e){case 1:w.slice_del();break;case 2:w.slice_from("lös");break;case 3:w.slice_from("full")}w.limit_backward=r}}var a,o,u=[new r("a",-1,1),new r("arna",0,1),new r("erna",0,1),new r("heterna",2,1),new r("orna",0,1),new r("ad",-1,1),new r("e",-1,1),new r("ade",6,1),new r("ande",6,1),new r("arne",6,1),new r("are",6,1),new r("aste",6,1),new r("en",-1,1),new r("anden",12,1),new r("aren",12,1),new r("heten",12,1),new r("ern",-1,1),new r("ar",-1,1),new r("er",-1,1),new r("heter",18,1),new r("or",-1,1),new r("s",-1,2),new r("as",21,1),new r("arnas",22,1),new r("ernas",22,1),new r("ornas",22,1),new r("es",21,1),new r("ades",26,1),new r("andes",26,1),new r("ens",21,1),new r("arens",29,1),new r("hetens",29,1),new r("erns",21,1),new r("at",-1,1),new r("andet",-1,1),new r("het",-1,1),new r("ast",-1,1)],c=[new r("dd",-1,-1),new r("gd",-1,-1),new r("nn",-1,-1),new r("dt",-1,-1),new r("gt",-1,-1),new r("kt",-1,-1),new r("tt",-1,-1)],m=[new r("ig",-1,1),new r("lig",0,1),new r("els",-1,1),new r("fullt",-1,3),new r("löst",-1,2)],l=[17,65,16,1,0,0,0,0,0,0,0,0,0,0,0,0,24,0,32],d=[119,127,149],w=new n;this.setCurrent=function(e){w.setCurrent(e)},this.getCurrent=function(){return w.getCurrent()},this.stem=function(){var r=w.cursor;return e(),w.limit_backward=r,w.cursor=w.limit,t(),w.cursor=w.limit,i(),w.cursor=w.limit,s(),!0}};return function(e){return"function"==typeof e.update?e.update(function(e){return t.setCurrent(e),t.stem(),t.getCurrent()}):(t.setCurrent(e),t.stem(),t.getCurrent())}}(),e.Pipeline.registerFunction(e.sv.stemmer,"stemmer-sv"),e.sv.stopWordFilter=e.generateStopWordFilter("alla allt att av blev bli blir blivit de dem den denna deras dess dessa det detta dig din dina ditt du där då efter ej eller en er era ert ett från för ha hade han hans har henne hennes hon honom hur här i icke ingen inom inte jag ju kan kunde man med mellan men mig min mina mitt mot mycket ni nu när någon något några och om oss på samma sedan sig sin sina sitta själv skulle som så sådan sådana sådant till under upp ut utan vad var vara varför varit varje vars vart vem vi vid vilka vilkas vilken vilket vår våra vårt än är åt över".split(" ")),e.Pipeline.registerFunction(e.sv.stopWordFilter,"stopWordFilter-sv")}});
|
||||
1
assets/javascripts/lunr/min/lunr.ta.min.js
vendored
Normal file
1
assets/javascripts/lunr/min/lunr.ta.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
!function(e,t){"function"==typeof define&&define.amd?define(t):"object"==typeof exports?module.exports=t():t()(e.lunr)}(this,function(){return function(e){if(void 0===e)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===e.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");e.ta=function(){this.pipeline.reset(),this.pipeline.add(e.ta.trimmer,e.ta.stopWordFilter,e.ta.stemmer),this.searchPipeline&&(this.searchPipeline.reset(),this.searchPipeline.add(e.ta.stemmer))},e.ta.wordCharacters="-உஊ-ஏஐ-ஙச-ட-னப-யர-ஹ-ிீ-ொ-ௐ---௩௪-௯௰-௹௺-a-zA-Za-zA-Z0-90-9",e.ta.trimmer=e.trimmerSupport.generateTrimmer(e.ta.wordCharacters),e.Pipeline.registerFunction(e.ta.trimmer,"trimmer-ta"),e.ta.stopWordFilter=e.generateStopWordFilter("அங்கு அங்கே அது அதை அந்த அவர் அவர்கள் அவள் அவன் அவை ஆக ஆகவே ஆகையால் ஆதலால் ஆதலினால் ஆனாலும் ஆனால் இங்கு இங்கே இது இதை இந்த இப்படி இவர் இவர்கள் இவள் இவன் இவை இவ்வளவு உனக்கு உனது உன் உன்னால் எங்கு எங்கே எது எதை எந்த எப்படி எவர் எவர்கள் எவள் எவன் எவை எவ்வளவு எனக்கு எனது எனவே என் என்ன என்னால் ஏது ஏன் தனது தன்னால் தானே தான் நாங்கள் நாம் நான் நீ நீங்கள்".split(" ")),e.ta.stemmer=function(){return function(e){return"function"==typeof e.update?e.update(function(e){return e}):e}}();var t=e.wordcut;t.init(),e.ta.tokenizer=function(r){if(!arguments.length||null==r||void 0==r)return[];if(Array.isArray(r))return r.map(function(t){return isLunr2?new e.Token(t.toLowerCase()):t.toLowerCase()});var i=r.toString().toLowerCase().replace(/^\s+/,"");return t.cut(i).split("|")},e.Pipeline.registerFunction(e.ta.stemmer,"stemmer-ta"),e.Pipeline.registerFunction(e.ta.stopWordFilter,"stopWordFilter-ta")}});
|
||||
1
assets/javascripts/lunr/min/lunr.te.min.js
vendored
Normal file
1
assets/javascripts/lunr/min/lunr.te.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
!function(e,t){"function"==typeof define&&define.amd?define(t):"object"==typeof exports?module.exports=t():t()(e.lunr)}(this,function(){return function(e){if(void 0===e)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===e.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");e.te=function(){this.pipeline.reset(),this.pipeline.add(e.te.trimmer,e.te.stopWordFilter,e.te.stemmer),this.searchPipeline&&(this.searchPipeline.reset(),this.searchPipeline.add(e.te.stemmer))},e.te.wordCharacters="ఀ-ఄఅ-ఔక-హా-ౌౕ-ౖౘ-ౚౠ-ౡౢ-ౣ౦-౯౸-౿఼ఽ్ౝ౷",e.te.trimmer=e.trimmerSupport.generateTrimmer(e.te.wordCharacters),e.Pipeline.registerFunction(e.te.trimmer,"trimmer-te"),e.te.stopWordFilter=e.generateStopWordFilter("అందరూ అందుబాటులో అడగండి అడగడం అడ్డంగా అనుగుణంగా అనుమతించు అనుమతిస్తుంది అయితే ఇప్పటికే ఉన్నారు ఎక్కడైనా ఎప్పుడు ఎవరైనా ఎవరో ఏ ఏదైనా ఏమైనప్పటికి ఒక ఒకరు కనిపిస్తాయి కాదు కూడా గా గురించి చుట్టూ చేయగలిగింది తగిన తర్వాత దాదాపు దూరంగా నిజంగా పై ప్రకారం ప్రక్కన మధ్య మరియు మరొక మళ్ళీ మాత్రమే మెచ్చుకో వద్ద వెంట వేరుగా వ్యతిరేకంగా సంబంధం".split(" ")),e.te.stemmer=function(){return function(e){return"function"==typeof e.update?e.update(function(e){return e}):e}}();var t=e.wordcut;t.init(),e.te.tokenizer=function(r){if(!arguments.length||null==r||void 0==r)return[];if(Array.isArray(r))return r.map(function(t){return isLunr2?new e.Token(t.toLowerCase()):t.toLowerCase()});var i=r.toString().toLowerCase().replace(/^\s+/,"");return t.cut(i).split("|")},e.Pipeline.registerFunction(e.te.stemmer,"stemmer-te"),e.Pipeline.registerFunction(e.te.stopWordFilter,"stopWordFilter-te")}});
|
||||
1
assets/javascripts/lunr/min/lunr.th.min.js
vendored
Normal file
1
assets/javascripts/lunr/min/lunr.th.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
!function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r():r()(e.lunr)}(this,function(){return function(e){if(void 0===e)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===e.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");var r="2"==e.version[0];e.th=function(){this.pipeline.reset(),this.pipeline.add(e.th.trimmer),r?this.tokenizer=e.th.tokenizer:(e.tokenizer&&(e.tokenizer=e.th.tokenizer),this.tokenizerFn&&(this.tokenizerFn=e.th.tokenizer))},e.th.wordCharacters="[-]",e.th.trimmer=e.trimmerSupport.generateTrimmer(e.th.wordCharacters),e.Pipeline.registerFunction(e.th.trimmer,"trimmer-th");var t=e.wordcut;t.init(),e.th.tokenizer=function(i){if(!arguments.length||null==i||void 0==i)return[];if(Array.isArray(i))return i.map(function(t){return r?new e.Token(t):t});var n=i.toString().replace(/^\s+/,"");return t.cut(n).split("|")}}});
|
||||
18
assets/javascripts/lunr/min/lunr.tr.min.js
vendored
Normal file
18
assets/javascripts/lunr/min/lunr.tr.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
assets/javascripts/lunr/min/lunr.vi.min.js
vendored
Normal file
1
assets/javascripts/lunr/min/lunr.vi.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
!function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r():r()(e.lunr)}(this,function(){return function(e){if(void 0===e)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===e.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");e.vi=function(){this.pipeline.reset(),this.pipeline.add(e.vi.stopWordFilter,e.vi.trimmer)},e.vi.wordCharacters="[A-Za-ẓ̀͐́͑̉̃̓ÂâÊêÔôĂ-ăĐ-đƠ-ơƯ-ư]",e.vi.trimmer=e.trimmerSupport.generateTrimmer(e.vi.wordCharacters),e.Pipeline.registerFunction(e.vi.trimmer,"trimmer-vi"),e.vi.stopWordFilter=e.generateStopWordFilter("là cái nhưng mà".split(" "))}});
|
||||
1
assets/javascripts/lunr/min/lunr.zh.min.js
vendored
Normal file
1
assets/javascripts/lunr/min/lunr.zh.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
!function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r(require("@node-rs/jieba")):r()(e.lunr)}(this,function(e){return function(r,t){if(void 0===r)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===r.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");var i="2"==r.version[0];r.zh=function(){this.pipeline.reset(),this.pipeline.add(r.zh.trimmer,r.zh.stopWordFilter,r.zh.stemmer),i?this.tokenizer=r.zh.tokenizer:(r.tokenizer&&(r.tokenizer=r.zh.tokenizer),this.tokenizerFn&&(this.tokenizerFn=r.zh.tokenizer))},r.zh.tokenizer=function(n){if(!arguments.length||null==n||void 0==n)return[];if(Array.isArray(n))return n.map(function(e){return i?new r.Token(e.toLowerCase()):e.toLowerCase()});t&&e.load(t);var o=n.toString().trim().toLowerCase(),s=[];e.cut(o,!0).forEach(function(e){s=s.concat(e.split(" "))}),s=s.filter(function(e){return!!e});var u=0;return s.map(function(e,t){if(i){var n=o.indexOf(e,u),s={};return s.position=[n,e.length],s.index=t,u=n,new r.Token(e,s)}return e})},r.zh.wordCharacters="\\w一-龥",r.zh.trimmer=r.trimmerSupport.generateTrimmer(r.zh.wordCharacters),r.Pipeline.registerFunction(r.zh.trimmer,"trimmer-zh"),r.zh.stemmer=function(){return function(e){return e}}(),r.Pipeline.registerFunction(r.zh.stemmer,"stemmer-zh"),r.zh.stopWordFilter=r.generateStopWordFilter("的 一 不 在 人 有 是 为 為 以 于 於 上 他 而 后 後 之 来 來 及 了 因 下 可 到 由 这 這 与 與 也 此 但 并 並 个 個 其 已 无 無 小 我 们 們 起 最 再 今 去 好 只 又 或 很 亦 某 把 那 你 乃 它 吧 被 比 别 趁 当 當 从 從 得 打 凡 儿 兒 尔 爾 该 該 各 给 給 跟 和 何 还 還 即 几 幾 既 看 据 據 距 靠 啦 另 么 麽 每 嘛 拿 哪 您 凭 憑 且 却 卻 让 讓 仍 啥 如 若 使 谁 誰 虽 雖 随 隨 同 所 她 哇 嗡 往 些 向 沿 哟 喲 用 咱 则 則 怎 曾 至 致 着 著 诸 諸 自".split(" ")),r.Pipeline.registerFunction(r.zh.stopWordFilter,"stopWordFilter-zh")}});
|
||||
206
assets/javascripts/lunr/tinyseg.js
Normal file
206
assets/javascripts/lunr/tinyseg.js
Normal file
@ -0,0 +1,206 @@
|
||||
/**
|
||||
* export the module via AMD, CommonJS or as a browser global
|
||||
* Export code from https://github.com/umdjs/umd/blob/master/returnExports.js
|
||||
*/
|
||||
;(function (root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(factory)
|
||||
} else if (typeof exports === 'object') {
|
||||
/**
|
||||
* Node. Does not work with strict CommonJS, but
|
||||
* only CommonJS-like environments that support module.exports,
|
||||
* like Node.
|
||||
*/
|
||||
module.exports = factory()
|
||||
} else {
|
||||
// Browser globals (root is window)
|
||||
factory()(root.lunr);
|
||||
}
|
||||
}(this, function () {
|
||||
/**
|
||||
* Just return a value to define the module export.
|
||||
* This example returns an object, but the module
|
||||
* can return a function as the exported value.
|
||||
*/
|
||||
|
||||
return function(lunr) {
|
||||
// TinySegmenter 0.1 -- Super compact Japanese tokenizer in Javascript
|
||||
// (c) 2008 Taku Kudo <taku@chasen.org>
|
||||
// TinySegmenter is freely distributable under the terms of a new BSD licence.
|
||||
// For details, see http://chasen.org/~taku/software/TinySegmenter/LICENCE.txt
|
||||
|
||||
function TinySegmenter() {
|
||||
var patterns = {
|
||||
"[一二三四五六七八九十百千万億兆]":"M",
|
||||
"[一-龠々〆ヵヶ]":"H",
|
||||
"[ぁ-ん]":"I",
|
||||
"[ァ-ヴーア-ン゙ー]":"K",
|
||||
"[a-zA-Za-zA-Z]":"A",
|
||||
"[0-90-9]":"N"
|
||||
}
|
||||
this.chartype_ = [];
|
||||
for (var i in patterns) {
|
||||
var regexp = new RegExp(i);
|
||||
this.chartype_.push([regexp, patterns[i]]);
|
||||
}
|
||||
|
||||
this.BIAS__ = -332
|
||||
this.BC1__ = {"HH":6,"II":2461,"KH":406,"OH":-1378};
|
||||
this.BC2__ = {"AA":-3267,"AI":2744,"AN":-878,"HH":-4070,"HM":-1711,"HN":4012,"HO":3761,"IA":1327,"IH":-1184,"II":-1332,"IK":1721,"IO":5492,"KI":3831,"KK":-8741,"MH":-3132,"MK":3334,"OO":-2920};
|
||||
this.BC3__ = {"HH":996,"HI":626,"HK":-721,"HN":-1307,"HO":-836,"IH":-301,"KK":2762,"MK":1079,"MM":4034,"OA":-1652,"OH":266};
|
||||
this.BP1__ = {"BB":295,"OB":304,"OO":-125,"UB":352};
|
||||
this.BP2__ = {"BO":60,"OO":-1762};
|
||||
this.BQ1__ = {"BHH":1150,"BHM":1521,"BII":-1158,"BIM":886,"BMH":1208,"BNH":449,"BOH":-91,"BOO":-2597,"OHI":451,"OIH":-296,"OKA":1851,"OKH":-1020,"OKK":904,"OOO":2965};
|
||||
this.BQ2__ = {"BHH":118,"BHI":-1159,"BHM":466,"BIH":-919,"BKK":-1720,"BKO":864,"OHH":-1139,"OHM":-181,"OIH":153,"UHI":-1146};
|
||||
this.BQ3__ = {"BHH":-792,"BHI":2664,"BII":-299,"BKI":419,"BMH":937,"BMM":8335,"BNN":998,"BOH":775,"OHH":2174,"OHM":439,"OII":280,"OKH":1798,"OKI":-793,"OKO":-2242,"OMH":-2402,"OOO":11699};
|
||||
this.BQ4__ = {"BHH":-3895,"BIH":3761,"BII":-4654,"BIK":1348,"BKK":-1806,"BMI":-3385,"BOO":-12396,"OAH":926,"OHH":266,"OHK":-2036,"ONN":-973};
|
||||
this.BW1__ = {",と":660,",同":727,"B1あ":1404,"B1同":542,"、と":660,"、同":727,"」と":1682,"あっ":1505,"いう":1743,"いっ":-2055,"いる":672,"うし":-4817,"うん":665,"から":3472,"がら":600,"こう":-790,"こと":2083,"こん":-1262,"さら":-4143,"さん":4573,"した":2641,"して":1104,"すで":-3399,"そこ":1977,"それ":-871,"たち":1122,"ため":601,"った":3463,"つい":-802,"てい":805,"てき":1249,"でき":1127,"です":3445,"では":844,"とい":-4915,"とみ":1922,"どこ":3887,"ない":5713,"なっ":3015,"など":7379,"なん":-1113,"にし":2468,"には":1498,"にも":1671,"に対":-912,"の一":-501,"の中":741,"ませ":2448,"まで":1711,"まま":2600,"まる":-2155,"やむ":-1947,"よっ":-2565,"れた":2369,"れで":-913,"をし":1860,"を見":731,"亡く":-1886,"京都":2558,"取り":-2784,"大き":-2604,"大阪":1497,"平方":-2314,"引き":-1336,"日本":-195,"本当":-2423,"毎日":-2113,"目指":-724,"B1あ":1404,"B1同":542,"」と":1682};
|
||||
this.BW2__ = {"..":-11822,"11":-669,"――":-5730,"−−":-13175,"いう":-1609,"うか":2490,"かし":-1350,"かも":-602,"から":-7194,"かれ":4612,"がい":853,"がら":-3198,"きた":1941,"くな":-1597,"こと":-8392,"この":-4193,"させ":4533,"され":13168,"さん":-3977,"しい":-1819,"しか":-545,"した":5078,"して":972,"しな":939,"その":-3744,"たい":-1253,"たた":-662,"ただ":-3857,"たち":-786,"たと":1224,"たは":-939,"った":4589,"って":1647,"っと":-2094,"てい":6144,"てき":3640,"てく":2551,"ては":-3110,"ても":-3065,"でい":2666,"でき":-1528,"でし":-3828,"です":-4761,"でも":-4203,"とい":1890,"とこ":-1746,"とと":-2279,"との":720,"とみ":5168,"とも":-3941,"ない":-2488,"なが":-1313,"など":-6509,"なの":2614,"なん":3099,"にお":-1615,"にし":2748,"にな":2454,"によ":-7236,"に対":-14943,"に従":-4688,"に関":-11388,"のか":2093,"ので":-7059,"のに":-6041,"のの":-6125,"はい":1073,"はが":-1033,"はず":-2532,"ばれ":1813,"まし":-1316,"まで":-6621,"まれ":5409,"めて":-3153,"もい":2230,"もの":-10713,"らか":-944,"らし":-1611,"らに":-1897,"りし":651,"りま":1620,"れた":4270,"れて":849,"れば":4114,"ろう":6067,"われ":7901,"を通":-11877,"んだ":728,"んな":-4115,"一人":602,"一方":-1375,"一日":970,"一部":-1051,"上が":-4479,"会社":-1116,"出て":2163,"分の":-7758,"同党":970,"同日":-913,"大阪":-2471,"委員":-1250,"少な":-1050,"年度":-8669,"年間":-1626,"府県":-2363,"手権":-1982,"新聞":-4066,"日新":-722,"日本":-7068,"日米":3372,"曜日":-601,"朝鮮":-2355,"本人":-2697,"東京":-1543,"然と":-1384,"社会":-1276,"立て":-990,"第に":-1612,"米国":-4268,"11":-669};
|
||||
this.BW3__ = {"あた":-2194,"あり":719,"ある":3846,"い.":-1185,"い。":-1185,"いい":5308,"いえ":2079,"いく":3029,"いた":2056,"いっ":1883,"いる":5600,"いわ":1527,"うち":1117,"うと":4798,"えと":1454,"か.":2857,"か。":2857,"かけ":-743,"かっ":-4098,"かに":-669,"から":6520,"かり":-2670,"が,":1816,"が、":1816,"がき":-4855,"がけ":-1127,"がっ":-913,"がら":-4977,"がり":-2064,"きた":1645,"けど":1374,"こと":7397,"この":1542,"ころ":-2757,"さい":-714,"さを":976,"し,":1557,"し、":1557,"しい":-3714,"した":3562,"して":1449,"しな":2608,"しま":1200,"す.":-1310,"す。":-1310,"する":6521,"ず,":3426,"ず、":3426,"ずに":841,"そう":428,"た.":8875,"た。":8875,"たい":-594,"たの":812,"たり":-1183,"たる":-853,"だ.":4098,"だ。":4098,"だっ":1004,"った":-4748,"って":300,"てい":6240,"てお":855,"ても":302,"です":1437,"でに":-1482,"では":2295,"とう":-1387,"とし":2266,"との":541,"とも":-3543,"どう":4664,"ない":1796,"なく":-903,"など":2135,"に,":-1021,"に、":-1021,"にし":1771,"にな":1906,"には":2644,"の,":-724,"の、":-724,"の子":-1000,"は,":1337,"は、":1337,"べき":2181,"まし":1113,"ます":6943,"まっ":-1549,"まで":6154,"まれ":-793,"らし":1479,"られ":6820,"るる":3818,"れ,":854,"れ、":854,"れた":1850,"れて":1375,"れば":-3246,"れる":1091,"われ":-605,"んだ":606,"んで":798,"カ月":990,"会議":860,"入り":1232,"大会":2217,"始め":1681,"市":965,"新聞":-5055,"日,":974,"日、":974,"社会":2024,"カ月":990};
|
||||
this.TC1__ = {"AAA":1093,"HHH":1029,"HHM":580,"HII":998,"HOH":-390,"HOM":-331,"IHI":1169,"IOH":-142,"IOI":-1015,"IOM":467,"MMH":187,"OOI":-1832};
|
||||
this.TC2__ = {"HHO":2088,"HII":-1023,"HMM":-1154,"IHI":-1965,"KKH":703,"OII":-2649};
|
||||
this.TC3__ = {"AAA":-294,"HHH":346,"HHI":-341,"HII":-1088,"HIK":731,"HOH":-1486,"IHH":128,"IHI":-3041,"IHO":-1935,"IIH":-825,"IIM":-1035,"IOI":-542,"KHH":-1216,"KKA":491,"KKH":-1217,"KOK":-1009,"MHH":-2694,"MHM":-457,"MHO":123,"MMH":-471,"NNH":-1689,"NNO":662,"OHO":-3393};
|
||||
this.TC4__ = {"HHH":-203,"HHI":1344,"HHK":365,"HHM":-122,"HHN":182,"HHO":669,"HIH":804,"HII":679,"HOH":446,"IHH":695,"IHO":-2324,"IIH":321,"III":1497,"IIO":656,"IOO":54,"KAK":4845,"KKA":3386,"KKK":3065,"MHH":-405,"MHI":201,"MMH":-241,"MMM":661,"MOM":841};
|
||||
this.TQ1__ = {"BHHH":-227,"BHHI":316,"BHIH":-132,"BIHH":60,"BIII":1595,"BNHH":-744,"BOHH":225,"BOOO":-908,"OAKK":482,"OHHH":281,"OHIH":249,"OIHI":200,"OIIH":-68};
|
||||
this.TQ2__ = {"BIHH":-1401,"BIII":-1033,"BKAK":-543,"BOOO":-5591};
|
||||
this.TQ3__ = {"BHHH":478,"BHHM":-1073,"BHIH":222,"BHII":-504,"BIIH":-116,"BIII":-105,"BMHI":-863,"BMHM":-464,"BOMH":620,"OHHH":346,"OHHI":1729,"OHII":997,"OHMH":481,"OIHH":623,"OIIH":1344,"OKAK":2792,"OKHH":587,"OKKA":679,"OOHH":110,"OOII":-685};
|
||||
this.TQ4__ = {"BHHH":-721,"BHHM":-3604,"BHII":-966,"BIIH":-607,"BIII":-2181,"OAAA":-2763,"OAKK":180,"OHHH":-294,"OHHI":2446,"OHHO":480,"OHIH":-1573,"OIHH":1935,"OIHI":-493,"OIIH":626,"OIII":-4007,"OKAK":-8156};
|
||||
this.TW1__ = {"につい":-4681,"東京都":2026};
|
||||
this.TW2__ = {"ある程":-2049,"いった":-1256,"ころが":-2434,"しょう":3873,"その後":-4430,"だって":-1049,"ていた":1833,"として":-4657,"ともに":-4517,"もので":1882,"一気に":-792,"初めて":-1512,"同時に":-8097,"大きな":-1255,"対して":-2721,"社会党":-3216};
|
||||
this.TW3__ = {"いただ":-1734,"してい":1314,"として":-4314,"につい":-5483,"にとっ":-5989,"に当た":-6247,"ので,":-727,"ので、":-727,"のもの":-600,"れから":-3752,"十二月":-2287};
|
||||
this.TW4__ = {"いう.":8576,"いう。":8576,"からな":-2348,"してい":2958,"たが,":1516,"たが、":1516,"ている":1538,"という":1349,"ました":5543,"ません":1097,"ようと":-4258,"よると":5865};
|
||||
this.UC1__ = {"A":484,"K":93,"M":645,"O":-505};
|
||||
this.UC2__ = {"A":819,"H":1059,"I":409,"M":3987,"N":5775,"O":646};
|
||||
this.UC3__ = {"A":-1370,"I":2311};
|
||||
this.UC4__ = {"A":-2643,"H":1809,"I":-1032,"K":-3450,"M":3565,"N":3876,"O":6646};
|
||||
this.UC5__ = {"H":313,"I":-1238,"K":-799,"M":539,"O":-831};
|
||||
this.UC6__ = {"H":-506,"I":-253,"K":87,"M":247,"O":-387};
|
||||
this.UP1__ = {"O":-214};
|
||||
this.UP2__ = {"B":69,"O":935};
|
||||
this.UP3__ = {"B":189};
|
||||
this.UQ1__ = {"BH":21,"BI":-12,"BK":-99,"BN":142,"BO":-56,"OH":-95,"OI":477,"OK":410,"OO":-2422};
|
||||
this.UQ2__ = {"BH":216,"BI":113,"OK":1759};
|
||||
this.UQ3__ = {"BA":-479,"BH":42,"BI":1913,"BK":-7198,"BM":3160,"BN":6427,"BO":14761,"OI":-827,"ON":-3212};
|
||||
this.UW1__ = {",":156,"、":156,"「":-463,"あ":-941,"う":-127,"が":-553,"き":121,"こ":505,"で":-201,"と":-547,"ど":-123,"に":-789,"の":-185,"は":-847,"も":-466,"や":-470,"よ":182,"ら":-292,"り":208,"れ":169,"を":-446,"ん":-137,"・":-135,"主":-402,"京":-268,"区":-912,"午":871,"国":-460,"大":561,"委":729,"市":-411,"日":-141,"理":361,"生":-408,"県":-386,"都":-718,"「":-463,"・":-135};
|
||||
this.UW2__ = {",":-829,"、":-829,"〇":892,"「":-645,"」":3145,"あ":-538,"い":505,"う":134,"お":-502,"か":1454,"が":-856,"く":-412,"こ":1141,"さ":878,"ざ":540,"し":1529,"す":-675,"せ":300,"そ":-1011,"た":188,"だ":1837,"つ":-949,"て":-291,"で":-268,"と":-981,"ど":1273,"な":1063,"に":-1764,"の":130,"は":-409,"ひ":-1273,"べ":1261,"ま":600,"も":-1263,"や":-402,"よ":1639,"り":-579,"る":-694,"れ":571,"を":-2516,"ん":2095,"ア":-587,"カ":306,"キ":568,"ッ":831,"三":-758,"不":-2150,"世":-302,"中":-968,"主":-861,"事":492,"人":-123,"会":978,"保":362,"入":548,"初":-3025,"副":-1566,"北":-3414,"区":-422,"大":-1769,"天":-865,"太":-483,"子":-1519,"学":760,"実":1023,"小":-2009,"市":-813,"年":-1060,"強":1067,"手":-1519,"揺":-1033,"政":1522,"文":-1355,"新":-1682,"日":-1815,"明":-1462,"最":-630,"朝":-1843,"本":-1650,"東":-931,"果":-665,"次":-2378,"民":-180,"気":-1740,"理":752,"発":529,"目":-1584,"相":-242,"県":-1165,"立":-763,"第":810,"米":509,"自":-1353,"行":838,"西":-744,"見":-3874,"調":1010,"議":1198,"込":3041,"開":1758,"間":-1257,"「":-645,"」":3145,"ッ":831,"ア":-587,"カ":306,"キ":568};
|
||||
this.UW3__ = {",":4889,"1":-800,"−":-1723,"、":4889,"々":-2311,"〇":5827,"」":2670,"〓":-3573,"あ":-2696,"い":1006,"う":2342,"え":1983,"お":-4864,"か":-1163,"が":3271,"く":1004,"け":388,"げ":401,"こ":-3552,"ご":-3116,"さ":-1058,"し":-395,"す":584,"せ":3685,"そ":-5228,"た":842,"ち":-521,"っ":-1444,"つ":-1081,"て":6167,"で":2318,"と":1691,"ど":-899,"な":-2788,"に":2745,"の":4056,"は":4555,"ひ":-2171,"ふ":-1798,"へ":1199,"ほ":-5516,"ま":-4384,"み":-120,"め":1205,"も":2323,"や":-788,"よ":-202,"ら":727,"り":649,"る":5905,"れ":2773,"わ":-1207,"を":6620,"ん":-518,"ア":551,"グ":1319,"ス":874,"ッ":-1350,"ト":521,"ム":1109,"ル":1591,"ロ":2201,"ン":278,"・":-3794,"一":-1619,"下":-1759,"世":-2087,"両":3815,"中":653,"主":-758,"予":-1193,"二":974,"人":2742,"今":792,"他":1889,"以":-1368,"低":811,"何":4265,"作":-361,"保":-2439,"元":4858,"党":3593,"全":1574,"公":-3030,"六":755,"共":-1880,"円":5807,"再":3095,"分":457,"初":2475,"別":1129,"前":2286,"副":4437,"力":365,"動":-949,"務":-1872,"化":1327,"北":-1038,"区":4646,"千":-2309,"午":-783,"協":-1006,"口":483,"右":1233,"各":3588,"合":-241,"同":3906,"和":-837,"員":4513,"国":642,"型":1389,"場":1219,"外":-241,"妻":2016,"学":-1356,"安":-423,"実":-1008,"家":1078,"小":-513,"少":-3102,"州":1155,"市":3197,"平":-1804,"年":2416,"広":-1030,"府":1605,"度":1452,"建":-2352,"当":-3885,"得":1905,"思":-1291,"性":1822,"戸":-488,"指":-3973,"政":-2013,"教":-1479,"数":3222,"文":-1489,"新":1764,"日":2099,"旧":5792,"昨":-661,"時":-1248,"曜":-951,"最":-937,"月":4125,"期":360,"李":3094,"村":364,"東":-805,"核":5156,"森":2438,"業":484,"氏":2613,"民":-1694,"決":-1073,"法":1868,"海":-495,"無":979,"物":461,"特":-3850,"生":-273,"用":914,"町":1215,"的":7313,"直":-1835,"省":792,"県":6293,"知":-1528,"私":4231,"税":401,"立":-960,"第":1201,"米":7767,"系":3066,"約":3663,"級":1384,"統":-4229,"総":1163,"線":1255,"者":6457,"能":725,"自":-2869,"英":785,"見":1044,"調":-562,"財":-733,"費":1777,"車":1835,"軍":1375,"込":-1504,"通":-1136,"選":-681,"郎":1026,"郡":4404,"部":1200,"金":2163,"長":421,"開":-1432,"間":1302,"関":-1282,"雨":2009,"電":-1045,"非":2066,"駅":1620,"1":-800,"」":2670,"・":-3794,"ッ":-1350,"ア":551,"グ":1319,"ス":874,"ト":521,"ム":1109,"ル":1591,"ロ":2201,"ン":278};
|
||||
this.UW4__ = {",":3930,".":3508,"―":-4841,"、":3930,"。":3508,"〇":4999,"「":1895,"」":3798,"〓":-5156,"あ":4752,"い":-3435,"う":-640,"え":-2514,"お":2405,"か":530,"が":6006,"き":-4482,"ぎ":-3821,"く":-3788,"け":-4376,"げ":-4734,"こ":2255,"ご":1979,"さ":2864,"し":-843,"じ":-2506,"す":-731,"ず":1251,"せ":181,"そ":4091,"た":5034,"だ":5408,"ち":-3654,"っ":-5882,"つ":-1659,"て":3994,"で":7410,"と":4547,"な":5433,"に":6499,"ぬ":1853,"ね":1413,"の":7396,"は":8578,"ば":1940,"ひ":4249,"び":-4134,"ふ":1345,"へ":6665,"べ":-744,"ほ":1464,"ま":1051,"み":-2082,"む":-882,"め":-5046,"も":4169,"ゃ":-2666,"や":2795,"ょ":-1544,"よ":3351,"ら":-2922,"り":-9726,"る":-14896,"れ":-2613,"ろ":-4570,"わ":-1783,"を":13150,"ん":-2352,"カ":2145,"コ":1789,"セ":1287,"ッ":-724,"ト":-403,"メ":-1635,"ラ":-881,"リ":-541,"ル":-856,"ン":-3637,"・":-4371,"ー":-11870,"一":-2069,"中":2210,"予":782,"事":-190,"井":-1768,"人":1036,"以":544,"会":950,"体":-1286,"作":530,"側":4292,"先":601,"党":-2006,"共":-1212,"内":584,"円":788,"初":1347,"前":1623,"副":3879,"力":-302,"動":-740,"務":-2715,"化":776,"区":4517,"協":1013,"参":1555,"合":-1834,"和":-681,"員":-910,"器":-851,"回":1500,"国":-619,"園":-1200,"地":866,"場":-1410,"塁":-2094,"士":-1413,"多":1067,"大":571,"子":-4802,"学":-1397,"定":-1057,"寺":-809,"小":1910,"屋":-1328,"山":-1500,"島":-2056,"川":-2667,"市":2771,"年":374,"庁":-4556,"後":456,"性":553,"感":916,"所":-1566,"支":856,"改":787,"政":2182,"教":704,"文":522,"方":-856,"日":1798,"時":1829,"最":845,"月":-9066,"木":-485,"来":-442,"校":-360,"業":-1043,"氏":5388,"民":-2716,"気":-910,"沢":-939,"済":-543,"物":-735,"率":672,"球":-1267,"生":-1286,"産":-1101,"田":-2900,"町":1826,"的":2586,"目":922,"省":-3485,"県":2997,"空":-867,"立":-2112,"第":788,"米":2937,"系":786,"約":2171,"経":1146,"統":-1169,"総":940,"線":-994,"署":749,"者":2145,"能":-730,"般":-852,"行":-792,"規":792,"警":-1184,"議":-244,"谷":-1000,"賞":730,"車":-1481,"軍":1158,"輪":-1433,"込":-3370,"近":929,"道":-1291,"選":2596,"郎":-4866,"都":1192,"野":-1100,"銀":-2213,"長":357,"間":-2344,"院":-2297,"際":-2604,"電":-878,"領":-1659,"題":-792,"館":-1984,"首":1749,"高":2120,"「":1895,"」":3798,"・":-4371,"ッ":-724,"ー":-11870,"カ":2145,"コ":1789,"セ":1287,"ト":-403,"メ":-1635,"ラ":-881,"リ":-541,"ル":-856,"ン":-3637};
|
||||
this.UW5__ = {",":465,".":-299,"1":-514,"E2":-32768,"]":-2762,"、":465,"。":-299,"「":363,"あ":1655,"い":331,"う":-503,"え":1199,"お":527,"か":647,"が":-421,"き":1624,"ぎ":1971,"く":312,"げ":-983,"さ":-1537,"し":-1371,"す":-852,"だ":-1186,"ち":1093,"っ":52,"つ":921,"て":-18,"で":-850,"と":-127,"ど":1682,"な":-787,"に":-1224,"の":-635,"は":-578,"べ":1001,"み":502,"め":865,"ゃ":3350,"ょ":854,"り":-208,"る":429,"れ":504,"わ":419,"を":-1264,"ん":327,"イ":241,"ル":451,"ン":-343,"中":-871,"京":722,"会":-1153,"党":-654,"務":3519,"区":-901,"告":848,"員":2104,"大":-1296,"学":-548,"定":1785,"嵐":-1304,"市":-2991,"席":921,"年":1763,"思":872,"所":-814,"挙":1618,"新":-1682,"日":218,"月":-4353,"査":932,"格":1356,"機":-1508,"氏":-1347,"田":240,"町":-3912,"的":-3149,"相":1319,"省":-1052,"県":-4003,"研":-997,"社":-278,"空":-813,"統":1955,"者":-2233,"表":663,"語":-1073,"議":1219,"選":-1018,"郎":-368,"長":786,"間":1191,"題":2368,"館":-689,"1":-514,"E2":-32768,"「":363,"イ":241,"ル":451,"ン":-343};
|
||||
this.UW6__ = {",":227,".":808,"1":-270,"E1":306,"、":227,"。":808,"あ":-307,"う":189,"か":241,"が":-73,"く":-121,"こ":-200,"じ":1782,"す":383,"た":-428,"っ":573,"て":-1014,"で":101,"と":-105,"な":-253,"に":-149,"の":-417,"は":-236,"も":-206,"り":187,"る":-135,"を":195,"ル":-673,"ン":-496,"一":-277,"中":201,"件":-800,"会":624,"前":302,"区":1792,"員":-1212,"委":798,"学":-960,"市":887,"広":-695,"後":535,"業":-697,"相":753,"社":-507,"福":974,"空":-822,"者":1811,"連":463,"郎":1082,"1":-270,"E1":306,"ル":-673,"ン":-496};
|
||||
|
||||
return this;
|
||||
}
|
||||
TinySegmenter.prototype.ctype_ = function(str) {
|
||||
for (var i in this.chartype_) {
|
||||
if (str.match(this.chartype_[i][0])) {
|
||||
return this.chartype_[i][1];
|
||||
}
|
||||
}
|
||||
return "O";
|
||||
}
|
||||
|
||||
TinySegmenter.prototype.ts_ = function(v) {
|
||||
if (v) { return v; }
|
||||
return 0;
|
||||
}
|
||||
|
||||
TinySegmenter.prototype.segment = function(input) {
|
||||
if (input == null || input == undefined || input == "") {
|
||||
return [];
|
||||
}
|
||||
var result = [];
|
||||
var seg = ["B3","B2","B1"];
|
||||
var ctype = ["O","O","O"];
|
||||
var o = input.split("");
|
||||
for (i = 0; i < o.length; ++i) {
|
||||
seg.push(o[i]);
|
||||
ctype.push(this.ctype_(o[i]))
|
||||
}
|
||||
seg.push("E1");
|
||||
seg.push("E2");
|
||||
seg.push("E3");
|
||||
ctype.push("O");
|
||||
ctype.push("O");
|
||||
ctype.push("O");
|
||||
var word = seg[3];
|
||||
var p1 = "U";
|
||||
var p2 = "U";
|
||||
var p3 = "U";
|
||||
for (var i = 4; i < seg.length - 3; ++i) {
|
||||
var score = this.BIAS__;
|
||||
var w1 = seg[i-3];
|
||||
var w2 = seg[i-2];
|
||||
var w3 = seg[i-1];
|
||||
var w4 = seg[i];
|
||||
var w5 = seg[i+1];
|
||||
var w6 = seg[i+2];
|
||||
var c1 = ctype[i-3];
|
||||
var c2 = ctype[i-2];
|
||||
var c3 = ctype[i-1];
|
||||
var c4 = ctype[i];
|
||||
var c5 = ctype[i+1];
|
||||
var c6 = ctype[i+2];
|
||||
score += this.ts_(this.UP1__[p1]);
|
||||
score += this.ts_(this.UP2__[p2]);
|
||||
score += this.ts_(this.UP3__[p3]);
|
||||
score += this.ts_(this.BP1__[p1 + p2]);
|
||||
score += this.ts_(this.BP2__[p2 + p3]);
|
||||
score += this.ts_(this.UW1__[w1]);
|
||||
score += this.ts_(this.UW2__[w2]);
|
||||
score += this.ts_(this.UW3__[w3]);
|
||||
score += this.ts_(this.UW4__[w4]);
|
||||
score += this.ts_(this.UW5__[w5]);
|
||||
score += this.ts_(this.UW6__[w6]);
|
||||
score += this.ts_(this.BW1__[w2 + w3]);
|
||||
score += this.ts_(this.BW2__[w3 + w4]);
|
||||
score += this.ts_(this.BW3__[w4 + w5]);
|
||||
score += this.ts_(this.TW1__[w1 + w2 + w3]);
|
||||
score += this.ts_(this.TW2__[w2 + w3 + w4]);
|
||||
score += this.ts_(this.TW3__[w3 + w4 + w5]);
|
||||
score += this.ts_(this.TW4__[w4 + w5 + w6]);
|
||||
score += this.ts_(this.UC1__[c1]);
|
||||
score += this.ts_(this.UC2__[c2]);
|
||||
score += this.ts_(this.UC3__[c3]);
|
||||
score += this.ts_(this.UC4__[c4]);
|
||||
score += this.ts_(this.UC5__[c5]);
|
||||
score += this.ts_(this.UC6__[c6]);
|
||||
score += this.ts_(this.BC1__[c2 + c3]);
|
||||
score += this.ts_(this.BC2__[c3 + c4]);
|
||||
score += this.ts_(this.BC3__[c4 + c5]);
|
||||
score += this.ts_(this.TC1__[c1 + c2 + c3]);
|
||||
score += this.ts_(this.TC2__[c2 + c3 + c4]);
|
||||
score += this.ts_(this.TC3__[c3 + c4 + c5]);
|
||||
score += this.ts_(this.TC4__[c4 + c5 + c6]);
|
||||
// score += this.ts_(this.TC5__[c4 + c5 + c6]);
|
||||
score += this.ts_(this.UQ1__[p1 + c1]);
|
||||
score += this.ts_(this.UQ2__[p2 + c2]);
|
||||
score += this.ts_(this.UQ3__[p3 + c3]);
|
||||
score += this.ts_(this.BQ1__[p2 + c2 + c3]);
|
||||
score += this.ts_(this.BQ2__[p2 + c3 + c4]);
|
||||
score += this.ts_(this.BQ3__[p3 + c2 + c3]);
|
||||
score += this.ts_(this.BQ4__[p3 + c3 + c4]);
|
||||
score += this.ts_(this.TQ1__[p2 + c1 + c2 + c3]);
|
||||
score += this.ts_(this.TQ2__[p2 + c2 + c3 + c4]);
|
||||
score += this.ts_(this.TQ3__[p3 + c1 + c2 + c3]);
|
||||
score += this.ts_(this.TQ4__[p3 + c2 + c3 + c4]);
|
||||
var p = "O";
|
||||
if (score > 0) {
|
||||
result.push(word);
|
||||
word = "";
|
||||
p = "B";
|
||||
}
|
||||
p1 = p2;
|
||||
p2 = p3;
|
||||
p3 = p;
|
||||
word += seg[i];
|
||||
}
|
||||
result.push(word);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
lunr.TinySegmenter = TinySegmenter;
|
||||
};
|
||||
|
||||
}));
|
||||
6708
assets/javascripts/lunr/wordcut.js
Normal file
6708
assets/javascripts/lunr/wordcut.js
Normal file
File diff suppressed because one or more lines are too long
42
assets/javascripts/workers/search.6ce7567c.min.js
vendored
Normal file
42
assets/javascripts/workers/search.6ce7567c.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
7
assets/javascripts/workers/search.6ce7567c.min.js.map
Normal file
7
assets/javascripts/workers/search.6ce7567c.min.js.map
Normal file
File diff suppressed because one or more lines are too long
1
assets/stylesheets/main.6f8fc17f.min.css
vendored
Normal file
1
assets/stylesheets/main.6f8fc17f.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
1
assets/stylesheets/main.6f8fc17f.min.css.map
Normal file
1
assets/stylesheets/main.6f8fc17f.min.css.map
Normal file
File diff suppressed because one or more lines are too long
1
assets/stylesheets/palette.06af60db.min.css
vendored
Normal file
1
assets/stylesheets/palette.06af60db.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
1
assets/stylesheets/palette.06af60db.min.css.map
Normal file
1
assets/stylesheets/palette.06af60db.min.css.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["src/templates/assets/stylesheets/palette/_scheme.scss","../../../../src/templates/assets/stylesheets/palette.scss","src/templates/assets/stylesheets/palette/_accent.scss","src/templates/assets/stylesheets/palette/_primary.scss","src/templates/assets/stylesheets/utilities/_break.scss"],"names":[],"mappings":"AA2BA,cAGE,6BAME,sDAAA,CACA,6DAAA,CACA,+DAAA,CACA,gEAAA,CACA,mDAAA,CACA,6DAAA,CACA,+DAAA,CACA,gEAAA,CAGA,mDAAA,CACA,gDAAA,CAGA,0BAAA,CACA,mCAAA,CAGA,iCAAA,CACA,kCAAA,CACA,mCAAA,CACA,mCAAA,CACA,kCAAA,CACA,iCAAA,CACA,+CAAA,CACA,6DAAA,CACA,gEAAA,CACA,4DAAA,CACA,4DAAA,CACA,6DAAA,CAGA,6CAAA,CAGA,+CAAA,CAGA,uDAAA,CACA,6DAAA,CACA,2DAAA,CAGA,iCAAA,CAGA,yDAAA,CACA,iEAAA,CAGA,mDAAA,CACA,mDAAA,CAGA,qDAAA,CACA,uDAAA,CAGA,8DAAA,CAKA,8DAAA,CAKA,0DAAA,CAvEA,iBCeF,CD6DE,kHAEE,YC3DJ,CDkFE,yDACE,4BChFJ,CD+EE,2DACE,4BC7EJ,CD4EE,gEACE,4BC1EJ,CDyEE,2DACE,4BCvEJ,CDsEE,yDACE,4BCpEJ,CDmEE,0DACE,4BCjEJ,CDgEE,gEACE,4BC9DJ,CD6DE,0DACE,4BC3DJ,CD0DE,2OACE,4BC/CJ,CDsDA,+FAGE,iCCpDF,CACF,CC/CE,2BACE,4BAAA,CACA,2CAAA,CAOE,yBAAA,CACA,qCD2CN,CCrDE,4BACE,4BAAA,CACA,2CAAA,CAOE,yBAAA,CACA,qCDkDN,CC5DE,8BACE,4BAAA,CACA,2CAAA,CAOE,yBAAA,CACA,qCDyDN,CCnEE,mCACE,4BAAA,CACA,2CAAA,CAOE,yBAAA,CACA,qCDgEN,CC1EE,8BACE,4BAAA,CACA,2CAAA,CAOE,yBAAA,CACA,qCDuEN,CCjFE,4BACE,4BAAA,CACA,2CAAA,CAOE,yBAAA,CACA,qCD8EN,CCxFE,kCACE,4BAAA,CACA,2CAAA,CAOE,yBAAA,CACA,qCDqFN,CC/FE,4BACE,4BAAA,CACA,2CAAA,CAOE,yBAAA,CACA,qCD4FN,CCtGE,4BACE,4BAAA,CACA,2CAAA,CAOE,yBAAA,CACA,qCDmGN,CC7GE,6BACE,4BAAA,CACA,2CAAA,CAOE,yBAAA,CACA,qCD0GN,CCpHE,mCACE,4BAAA,CACA,2CAAA,CAOE,yBAAA,CACA,qCDiHN,CC3HE,4BACE,4BAAA,CACA,2CAAA,CAIE,8BAAA,CACA,qCD2HN,CClIE,8BACE,4BAAA,CACA,2CAAA,CAIE,8BAAA,CACA,qCDkIN,CCzIE,6BACE,yBAAA,CACA,2CAAA,CAIE,8BAAA,CACA,qCDyIN,CChJE,8BACE,4BAAA,CACA,2CAAA,CAIE,8BAAA,CACA,qCDgJN,CCvJE,mCACE,4BAAA,CACA,2CAAA,CAOE,yBAAA,CACA,qCDoJN,CEzJE,4BACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAOE,0BAAA,CACA,sCFsJN,CEjKE,6BACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAOE,0BAAA,CACA,sCF8JN,CEzKE,+BACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAOE,0BAAA,CACA,sCFsKN,CEjLE,oCACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAOE,0BAAA,CACA,sCF8KN,CEzLE,+BACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAOE,0BAAA,CACA,sCFsLN,CEjME,6BACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAOE,0BAAA,CACA,sCF8LN,CEzME,mCACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAOE,0BAAA,CACA,sCFsMN,CEjNE,6BACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAOE,0BAAA,CACA,sCF8MN,CEzNE,6BACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAOE,0BAAA,CACA,sCFsNN,CEjOE,8BACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAOE,0BAAA,CACA,sCF8NN,CEzOE,oCACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAOE,0BAAA,CACA,sCFsON,CEjPE,6BACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAIE,+BAAA,CACA,sCFiPN,CEzPE,+BACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAIE,+BAAA,CACA,sCFyPN,CEjQE,8BACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAIE,+BAAA,CACA,sCFiQN,CEzQE,+BACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAIE,+BAAA,CACA,sCFyQN,CEjRE,oCACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAOE,0BAAA,CACA,sCF8QN,CEzRE,8BACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAOE,0BAAA,CACA,sCFsRN,CEjSE,6BACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAOE,0BAAA,CACA,sCAAA,CAKA,4BF0RN,CE1SE,kCACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAOE,0BAAA,CACA,sCAAA,CAKA,4BFmSN,CEpRE,sEACE,4BFuRJ,CExRE,+DACE,4BF2RJ,CE5RE,iEACE,4BF+RJ,CEhSE,gEACE,4BFmSJ,CEpSE,iEACE,4BFuSJ,CE9RA,8BACE,mDAAA,CACA,4DAAA,CACA,0DAAA,CACA,oDAAA,CACA,2DAAA,CAGA,4BF+RF,CE5RE,yCACE,+BF8RJ,CE3RI,kDAEE,0CAAA,CACA,sCAAA,CAFA,mCF+RN,CG3MI,mCD1EA,+CACE,8CFwRJ,CErRI,qDACE,8CFuRN,CElRE,iEACE,mCFoRJ,CACF,CGtNI,sCDvDA,uCACE,oCFgRJ,CACF,CEvQA,8BACE,kDAAA,CACA,4DAAA,CACA,wDAAA,CACA,oDAAA,CACA,6DAAA,CAGA,4BFwQF,CErQE,yCACE,+BFuQJ,CEpQI,kDAEE,0CAAA,CACA,sCAAA,CAFA,mCFwQN,CEjQE,yCACE,6CFmQJ,CG5NI,0CDhCA,8CACE,gDF+PJ,CACF,CGjOI,0CDvBA,iFACE,6CF2PJ,CACF,CGzPI,sCDKA,uCACE,6CFuPJ,CACF","file":"palette.css"}
|
||||
1461
async/index.html
Normal file
1461
async/index.html
Normal file
File diff suppressed because it is too large
Load Diff
1179
code_of_conduct/index.html
Normal file
1179
code_of_conduct/index.html
Normal file
File diff suppressed because it is too large
Load Diff
1608
compatibility/index.html
Normal file
1608
compatibility/index.html
Normal file
File diff suppressed because it is too large
Load Diff
1440
contributing/index.html
Normal file
1440
contributing/index.html
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,232 +0,0 @@
|
||||
Authentication can either be included on a per-request basis...
|
||||
|
||||
```pycon
|
||||
>>> auth = httpx.BasicAuth(username="username", password="secret")
|
||||
>>> client = httpx.Client()
|
||||
>>> response = client.get("https://www.example.com/", auth=auth)
|
||||
```
|
||||
|
||||
Or configured on the client instance, ensuring that all outgoing requests will include authentication credentials...
|
||||
|
||||
```pycon
|
||||
>>> auth = httpx.BasicAuth(username="username", password="secret")
|
||||
>>> client = httpx.Client(auth=auth)
|
||||
>>> response = client.get("https://www.example.com/")
|
||||
```
|
||||
|
||||
## Basic authentication
|
||||
|
||||
HTTP basic authentication is an unencrypted authentication scheme that uses a simple encoding of the username and password in the request `Authorization` header. Since it is unencrypted it should typically only be used over `https`, although this is not strictly enforced.
|
||||
|
||||
```pycon
|
||||
>>> auth = httpx.BasicAuth(username="finley", password="secret")
|
||||
>>> client = httpx.Client(auth=auth)
|
||||
>>> response = client.get("https://httpbin.org/basic-auth/finley/secret")
|
||||
>>> response
|
||||
<Response [200 OK]>
|
||||
```
|
||||
|
||||
## Digest authentication
|
||||
|
||||
HTTP digest authentication is a challenge-response authentication scheme. Unlike basic authentication it provides encryption, and can be used over unencrypted `http` connections. It requires an additional round-trip in order to negotiate the authentication.
|
||||
|
||||
```pycon
|
||||
>>> auth = httpx.DigestAuth(username="olivia", password="secret")
|
||||
>>> client = httpx.Client(auth=auth)
|
||||
>>> response = client.get("https://httpbin.org/digest-auth/auth/olivia/secret")
|
||||
>>> response
|
||||
<Response [200 OK]>
|
||||
>>> response.history
|
||||
[<Response [401 UNAUTHORIZED]>]
|
||||
```
|
||||
|
||||
## NetRC authentication
|
||||
|
||||
HTTPX can be configured to use [a `.netrc` config file](https://everything.curl.dev/usingcurl/netrc) for authentication.
|
||||
|
||||
The `.netrc` config file allows authentication credentials to be associated with specified hosts. When a request is made to a host that is found in the netrc file, the username and password will be included using HTTP basic authentication.
|
||||
|
||||
Example `.netrc` file:
|
||||
|
||||
```
|
||||
machine example.org
|
||||
login example-username
|
||||
password example-password
|
||||
|
||||
machine python-httpx.org
|
||||
login other-username
|
||||
password other-password
|
||||
```
|
||||
|
||||
Some examples of configuring `.netrc` authentication with `httpx`.
|
||||
|
||||
Use the default `.netrc` file in the users home directory:
|
||||
|
||||
```pycon
|
||||
>>> auth = httpx.NetRCAuth()
|
||||
>>> client = httpx.Client(auth=auth)
|
||||
```
|
||||
|
||||
Use an explicit path to a `.netrc` file:
|
||||
|
||||
```pycon
|
||||
>>> auth = httpx.NetRCAuth(file="/path/to/.netrc")
|
||||
>>> client = httpx.Client(auth=auth)
|
||||
```
|
||||
|
||||
Use the `NETRC` environment variable to configure a path to the `.netrc` file,
|
||||
or fallback to the default.
|
||||
|
||||
```pycon
|
||||
>>> auth = httpx.NetRCAuth(file=os.environ.get("NETRC"))
|
||||
>>> client = httpx.Client(auth=auth)
|
||||
```
|
||||
|
||||
The `NetRCAuth()` class uses [the `netrc.netrc()` function from the Python standard library](https://docs.python.org/3/library/netrc.html). See the documentation there for more details on exceptions that may be raised if the `.netrc` file is not found, or cannot be parsed.
|
||||
|
||||
## Custom authentication schemes
|
||||
|
||||
When issuing requests or instantiating a client, the `auth` argument can be used to pass an authentication scheme to use. The `auth` argument may be one of the following...
|
||||
|
||||
* A two-tuple of `username`/`password`, to be used with basic authentication.
|
||||
* An instance of `httpx.BasicAuth()`, `httpx.DigestAuth()`, or `httpx.NetRCAuth()`.
|
||||
* A callable, accepting a request and returning an authenticated request instance.
|
||||
* An instance of subclasses of `httpx.Auth`.
|
||||
|
||||
The most involved of these is the last, which allows you to create authentication flows involving one or more requests. A subclass of `httpx.Auth` should implement `def auth_flow(request)`, and yield any requests that need to be made...
|
||||
|
||||
```python
|
||||
class MyCustomAuth(httpx.Auth):
|
||||
def __init__(self, token):
|
||||
self.token = token
|
||||
|
||||
def auth_flow(self, request):
|
||||
# Send the request, with a custom `X-Authentication` header.
|
||||
request.headers['X-Authentication'] = self.token
|
||||
yield request
|
||||
```
|
||||
|
||||
If the auth flow requires more than one request, you can issue multiple yields, and obtain the response in each case...
|
||||
|
||||
```python
|
||||
class MyCustomAuth(httpx.Auth):
|
||||
def __init__(self, token):
|
||||
self.token = token
|
||||
|
||||
def auth_flow(self, request):
|
||||
response = yield request
|
||||
if response.status_code == 401:
|
||||
# If the server issues a 401 response then resend the request,
|
||||
# with a custom `X-Authentication` header.
|
||||
request.headers['X-Authentication'] = self.token
|
||||
yield request
|
||||
```
|
||||
|
||||
Custom authentication classes are designed to not perform any I/O, so that they may be used with both sync and async client instances. If you are implementing an authentication scheme that requires the request body, then you need to indicate this on the class using a `requires_request_body` property.
|
||||
|
||||
You will then be able to access `request.content` inside the `.auth_flow()` method.
|
||||
|
||||
```python
|
||||
class MyCustomAuth(httpx.Auth):
|
||||
requires_request_body = True
|
||||
|
||||
def __init__(self, token):
|
||||
self.token = token
|
||||
|
||||
def auth_flow(self, request):
|
||||
response = yield request
|
||||
if response.status_code == 401:
|
||||
# If the server issues a 401 response then resend the request,
|
||||
# with a custom `X-Authentication` header.
|
||||
request.headers['X-Authentication'] = self.sign_request(...)
|
||||
yield request
|
||||
|
||||
def sign_request(self, request):
|
||||
# Create a request signature, based on `request.method`, `request.url`,
|
||||
# `request.headers`, and `request.content`.
|
||||
...
|
||||
```
|
||||
|
||||
Similarly, if you are implementing a scheme that requires access to the response body, then use the `requires_response_body` property. You will then be able to access response body properties and methods such as `response.content`, `response.text`, `response.json()`, etc.
|
||||
|
||||
```python
|
||||
class MyCustomAuth(httpx.Auth):
|
||||
requires_response_body = True
|
||||
|
||||
def __init__(self, access_token, refresh_token, refresh_url):
|
||||
self.access_token = access_token
|
||||
self.refresh_token = refresh_token
|
||||
self.refresh_url = refresh_url
|
||||
|
||||
def auth_flow(self, request):
|
||||
request.headers["X-Authentication"] = self.access_token
|
||||
response = yield request
|
||||
|
||||
if response.status_code == 401:
|
||||
# If the server issues a 401 response, then issue a request to
|
||||
# refresh tokens, and resend the request.
|
||||
refresh_response = yield self.build_refresh_request()
|
||||
self.update_tokens(refresh_response)
|
||||
|
||||
request.headers["X-Authentication"] = self.access_token
|
||||
yield request
|
||||
|
||||
def build_refresh_request(self):
|
||||
# Return an `httpx.Request` for refreshing tokens.
|
||||
...
|
||||
|
||||
def update_tokens(self, response):
|
||||
# Update the `.access_token` and `.refresh_token` tokens
|
||||
# based on a refresh response.
|
||||
data = response.json()
|
||||
...
|
||||
```
|
||||
|
||||
If you _do_ need to perform I/O other than HTTP requests, such as accessing a disk-based cache, or you need to use concurrency primitives, such as locks, then you should override `.sync_auth_flow()` and `.async_auth_flow()` (instead of `.auth_flow()`). The former will be used by `httpx.Client`, while the latter will be used by `httpx.AsyncClient`.
|
||||
|
||||
```python
|
||||
import asyncio
|
||||
import threading
|
||||
import httpx
|
||||
|
||||
|
||||
class MyCustomAuth(httpx.Auth):
|
||||
def __init__(self):
|
||||
self._sync_lock = threading.RLock()
|
||||
self._async_lock = asyncio.Lock()
|
||||
|
||||
def sync_get_token(self):
|
||||
with self._sync_lock:
|
||||
...
|
||||
|
||||
def sync_auth_flow(self, request):
|
||||
token = self.sync_get_token()
|
||||
request.headers["Authorization"] = f"Token {token}"
|
||||
yield request
|
||||
|
||||
async def async_get_token(self):
|
||||
async with self._async_lock:
|
||||
...
|
||||
|
||||
async def async_auth_flow(self, request):
|
||||
token = await self.async_get_token()
|
||||
request.headers["Authorization"] = f"Token {token}"
|
||||
yield request
|
||||
```
|
||||
|
||||
If you only want to support one of the two methods, then you should still override it, but raise an explicit `RuntimeError`.
|
||||
|
||||
```python
|
||||
import httpx
|
||||
import sync_only_library
|
||||
|
||||
|
||||
class MyCustomAuth(httpx.Auth):
|
||||
def sync_auth_flow(self, request):
|
||||
token = sync_only_library.get_token(...)
|
||||
request.headers["Authorization"] = f"Token {token}"
|
||||
yield request
|
||||
|
||||
async def async_auth_flow(self, request):
|
||||
raise RuntimeError("Cannot use a sync authentication class with httpx.AsyncClient")
|
||||
```
|
||||
@ -1,328 +0,0 @@
|
||||
!!! hint
|
||||
If you are coming from Requests, `httpx.Client()` is what you can use instead of `requests.Session()`.
|
||||
|
||||
## Why use a Client?
|
||||
|
||||
!!! note "TL;DR"
|
||||
If you do anything more than experimentation, one-off scripts, or prototypes, then you should use a `Client` instance.
|
||||
|
||||
**More efficient usage of network resources**
|
||||
|
||||
When you make requests using the top-level API as documented in the [Quickstart](../quickstart.md) guide, HTTPX has to establish a new connection _for every single request_ (connections are not reused). As the number of requests to a host increases, this quickly becomes inefficient.
|
||||
|
||||
On the other hand, a `Client` instance uses [HTTP connection pooling](https://en.wikipedia.org/wiki/HTTP_persistent_connection). This means that when you make several requests to the same host, the `Client` will reuse the underlying TCP connection, instead of recreating one for every single request.
|
||||
|
||||
This can bring **significant performance improvements** compared to using the top-level API, including:
|
||||
|
||||
- Reduced latency across requests (no handshaking).
|
||||
- Reduced CPU usage and round-trips.
|
||||
- Reduced network congestion.
|
||||
|
||||
**Extra features**
|
||||
|
||||
`Client` instances also support features that aren't available at the top-level API, such as:
|
||||
|
||||
- Cookie persistence across requests.
|
||||
- Applying configuration across all outgoing requests.
|
||||
- Sending requests through HTTP proxies.
|
||||
- Using [HTTP/2](../http2.md).
|
||||
|
||||
The other sections on this page go into further detail about what you can do with a `Client` instance.
|
||||
|
||||
## Usage
|
||||
|
||||
The recommended way to use a `Client` is as a context manager. This will ensure that connections are properly cleaned up when leaving the `with` block:
|
||||
|
||||
```python
|
||||
with httpx.Client() as client:
|
||||
...
|
||||
```
|
||||
|
||||
Alternatively, you can explicitly close the connection pool without block-usage using `.close()`:
|
||||
|
||||
```python
|
||||
client = httpx.Client()
|
||||
try:
|
||||
...
|
||||
finally:
|
||||
client.close()
|
||||
```
|
||||
|
||||
## Making requests
|
||||
|
||||
Once you have a `Client`, you can send requests using `.get()`, `.post()`, etc. For example:
|
||||
|
||||
```pycon
|
||||
>>> with httpx.Client() as client:
|
||||
... r = client.get('https://example.com')
|
||||
...
|
||||
>>> r
|
||||
<Response [200 OK]>
|
||||
```
|
||||
|
||||
These methods accept the same arguments as `httpx.get()`, `httpx.post()`, etc. This means that all features documented in the [Quickstart](../quickstart.md) guide are also available at the client level.
|
||||
|
||||
For example, to send a request with custom headers:
|
||||
|
||||
```pycon
|
||||
>>> with httpx.Client() as client:
|
||||
... headers = {'X-Custom': 'value'}
|
||||
... r = client.get('https://example.com', headers=headers)
|
||||
...
|
||||
>>> r.request.headers['X-Custom']
|
||||
'value'
|
||||
```
|
||||
|
||||
## Sharing configuration across requests
|
||||
|
||||
Clients allow you to apply configuration to all outgoing requests by passing parameters to the `Client` constructor.
|
||||
|
||||
For example, to apply a set of custom headers _on every request_:
|
||||
|
||||
```pycon
|
||||
>>> url = 'http://httpbin.org/headers'
|
||||
>>> headers = {'user-agent': 'my-app/0.0.1'}
|
||||
>>> with httpx.Client(headers=headers) as client:
|
||||
... r = client.get(url)
|
||||
...
|
||||
>>> r.json()['headers']['User-Agent']
|
||||
'my-app/0.0.1'
|
||||
```
|
||||
|
||||
## Merging of configuration
|
||||
|
||||
When a configuration option is provided at both the client-level and request-level, one of two things can happen:
|
||||
|
||||
- For headers, query parameters and cookies, the values are combined together. For example:
|
||||
|
||||
```pycon
|
||||
>>> headers = {'X-Auth': 'from-client'}
|
||||
>>> params = {'client_id': 'client1'}
|
||||
>>> with httpx.Client(headers=headers, params=params) as client:
|
||||
... headers = {'X-Custom': 'from-request'}
|
||||
... params = {'request_id': 'request1'}
|
||||
... r = client.get('https://example.com', headers=headers, params=params)
|
||||
...
|
||||
>>> r.request.url
|
||||
URL('https://example.com?client_id=client1&request_id=request1')
|
||||
>>> r.request.headers['X-Auth']
|
||||
'from-client'
|
||||
>>> r.request.headers['X-Custom']
|
||||
'from-request'
|
||||
```
|
||||
|
||||
- For all other parameters, the request-level value takes priority. For example:
|
||||
|
||||
```pycon
|
||||
>>> with httpx.Client(auth=('tom', 'mot123')) as client:
|
||||
... r = client.get('https://example.com', auth=('alice', 'ecila123'))
|
||||
...
|
||||
>>> _, _, auth = r.request.headers['Authorization'].partition(' ')
|
||||
>>> import base64
|
||||
>>> base64.b64decode(auth)
|
||||
b'alice:ecila123'
|
||||
```
|
||||
|
||||
If you need finer-grained control on the merging of client-level and request-level parameters, see [Request instances](#request-instances).
|
||||
|
||||
## Other Client-only configuration options
|
||||
|
||||
Additionally, `Client` accepts some configuration options that aren't available at the request level.
|
||||
|
||||
For example, `base_url` allows you to prepend an URL to all outgoing requests:
|
||||
|
||||
```pycon
|
||||
>>> with httpx.Client(base_url='http://httpbin.org') as client:
|
||||
... r = client.get('/headers')
|
||||
...
|
||||
>>> r.request.url
|
||||
URL('http://httpbin.org/headers')
|
||||
```
|
||||
|
||||
For a list of all available client parameters, see the [`Client`](../api.md#client) API reference.
|
||||
|
||||
---
|
||||
|
||||
## Request instances
|
||||
|
||||
For maximum control on what gets sent over the wire, HTTPX supports building explicit [`Request`](../api.md#request) instances:
|
||||
|
||||
```python
|
||||
request = httpx.Request("GET", "https://example.com")
|
||||
```
|
||||
|
||||
To dispatch a `Request` instance across to the network, create a [`Client` instance](#client-instances) and use `.send()`:
|
||||
|
||||
```python
|
||||
with httpx.Client() as client:
|
||||
response = client.send(request)
|
||||
...
|
||||
```
|
||||
|
||||
If you need to mix client-level and request-level options in a way that is not supported by the default [Merging of parameters](#merging-of-parameters), you can use `.build_request()` and then make arbitrary modifications to the `Request` instance. For example:
|
||||
|
||||
```python
|
||||
headers = {"X-Api-Key": "...", "X-Client-ID": "ABC123"}
|
||||
|
||||
with httpx.Client(headers=headers) as client:
|
||||
request = client.build_request("GET", "https://api.example.com")
|
||||
|
||||
print(request.headers["X-Client-ID"]) # "ABC123"
|
||||
|
||||
# Don't send the API key for this particular request.
|
||||
del request.headers["X-Api-Key"]
|
||||
|
||||
response = client.send(request)
|
||||
...
|
||||
```
|
||||
|
||||
## Monitoring download progress
|
||||
|
||||
If you need to monitor download progress of large responses, you can use response streaming and inspect the `response.num_bytes_downloaded` property.
|
||||
|
||||
This interface is required for properly determining download progress, because the total number of bytes returned by `response.content` or `response.iter_content()` will not always correspond with the raw content length of the response if HTTP response compression is being used.
|
||||
|
||||
For example, showing a progress bar using the [`tqdm`](https://github.com/tqdm/tqdm) library while a response is being downloaded could be done like this…
|
||||
|
||||
```python
|
||||
import tempfile
|
||||
|
||||
import httpx
|
||||
from tqdm import tqdm
|
||||
|
||||
with tempfile.NamedTemporaryFile() as download_file:
|
||||
url = "https://speed.hetzner.de/100MB.bin"
|
||||
with httpx.stream("GET", url) as response:
|
||||
total = int(response.headers["Content-Length"])
|
||||
|
||||
with tqdm(total=total, unit_scale=True, unit_divisor=1024, unit="B") as progress:
|
||||
num_bytes_downloaded = response.num_bytes_downloaded
|
||||
for chunk in response.iter_bytes():
|
||||
download_file.write(chunk)
|
||||
progress.update(response.num_bytes_downloaded - num_bytes_downloaded)
|
||||
num_bytes_downloaded = response.num_bytes_downloaded
|
||||
```
|
||||
|
||||

|
||||
|
||||
Or an alternate example, this time using the [`rich`](https://github.com/willmcgugan/rich) library…
|
||||
|
||||
```python
|
||||
import tempfile
|
||||
import httpx
|
||||
import rich.progress
|
||||
|
||||
with tempfile.NamedTemporaryFile() as download_file:
|
||||
url = "https://speed.hetzner.de/100MB.bin"
|
||||
with httpx.stream("GET", url) as response:
|
||||
total = int(response.headers["Content-Length"])
|
||||
|
||||
with rich.progress.Progress(
|
||||
"[progress.percentage]{task.percentage:>3.0f}%",
|
||||
rich.progress.BarColumn(bar_width=None),
|
||||
rich.progress.DownloadColumn(),
|
||||
rich.progress.TransferSpeedColumn(),
|
||||
) as progress:
|
||||
download_task = progress.add_task("Download", total=total)
|
||||
for chunk in response.iter_bytes():
|
||||
download_file.write(chunk)
|
||||
progress.update(download_task, completed=response.num_bytes_downloaded)
|
||||
```
|
||||
|
||||

|
||||
|
||||
## Monitoring upload progress
|
||||
|
||||
If you need to monitor upload progress of large responses, you can use request content generator streaming.
|
||||
|
||||
For example, showing a progress bar using the [`tqdm`](https://github.com/tqdm/tqdm) library.
|
||||
|
||||
```python
|
||||
import io
|
||||
import random
|
||||
|
||||
import httpx
|
||||
from tqdm import tqdm
|
||||
|
||||
|
||||
def gen():
|
||||
"""
|
||||
this is a complete example with generated random bytes.
|
||||
you can replace `io.BytesIO` with real file object.
|
||||
"""
|
||||
total = 32 * 1024 * 1024 # 32m
|
||||
with tqdm(ascii=True, unit_scale=True, unit='B', unit_divisor=1024, total=total) as bar:
|
||||
with io.BytesIO(random.randbytes(total)) as f:
|
||||
while data := f.read(1024):
|
||||
yield data
|
||||
bar.update(len(data))
|
||||
|
||||
|
||||
httpx.post("https://httpbin.org/post", content=gen())
|
||||
```
|
||||
|
||||

|
||||
|
||||
## Multipart file encoding
|
||||
|
||||
As mentioned in the [quickstart](../quickstart.md#sending-multipart-file-uploads)
|
||||
multipart file encoding is available by passing a dictionary with the
|
||||
name of the payloads as keys and either tuple of elements or a file-like object or a string as values.
|
||||
|
||||
```pycon
|
||||
>>> with open('report.xls', 'rb') as report_file:
|
||||
... files = {'upload-file': ('report.xls', report_file, 'application/vnd.ms-excel')}
|
||||
... r = httpx.post("https://httpbin.org/post", files=files)
|
||||
>>> print(r.text)
|
||||
{
|
||||
...
|
||||
"files": {
|
||||
"upload-file": "<... binary content ...>"
|
||||
},
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
More specifically, if a tuple is used as a value, it must have between 2 and 3 elements:
|
||||
|
||||
- The first element is an optional file name which can be set to `None`.
|
||||
- The second element may be a file-like object or a string which will be automatically
|
||||
encoded in UTF-8.
|
||||
- An optional third element can be used to specify the
|
||||
[MIME type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_Types)
|
||||
of the file being uploaded. If not specified HTTPX will attempt to guess the MIME type based
|
||||
on the file name, with unknown file extensions defaulting to "application/octet-stream".
|
||||
If the file name is explicitly set to `None` then HTTPX will not include a content-type
|
||||
MIME header field.
|
||||
|
||||
```pycon
|
||||
>>> files = {'upload-file': (None, 'text content', 'text/plain')}
|
||||
>>> r = httpx.post("https://httpbin.org/post", files=files)
|
||||
>>> print(r.text)
|
||||
{
|
||||
...
|
||||
"files": {},
|
||||
"form": {
|
||||
"upload-file": "text-content"
|
||||
},
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
!!! tip
|
||||
It is safe to upload large files this way. File uploads are streaming by default, meaning that only one chunk will be loaded into memory at a time.
|
||||
|
||||
Non-file data fields can be included in the multipart form using by passing them to `data=...`.
|
||||
|
||||
You can also send multiple files in one go with a multiple file field form.
|
||||
To do that, pass a list of `(field, <file>)` items instead of a dictionary, allowing you to pass multiple items with the same `field`.
|
||||
For instance this request sends 2 files, `foo.png` and `bar.png` in one request on the `images` form field:
|
||||
|
||||
```pycon
|
||||
>>> with open('foo.png', 'rb') as foo_file, open('bar.png', 'rb') as bar_file:
|
||||
... files = [
|
||||
... ('images', ('foo.png', foo_file, 'image/png')),
|
||||
... ('images', ('bar.png', bar_file, 'image/png')),
|
||||
... ]
|
||||
... r = httpx.post("https://httpbin.org/post", files=files)
|
||||
```
|
||||
@ -1,65 +0,0 @@
|
||||
HTTPX allows you to register "event hooks" with the client, that are called
|
||||
every time a particular type of event takes place.
|
||||
|
||||
There are currently two event hooks:
|
||||
|
||||
* `request` - Called after a request is fully prepared, but before it is sent to the network. Passed the `request` instance.
|
||||
* `response` - Called after the response has been fetched from the network, but before it is returned to the caller. Passed the `response` instance.
|
||||
|
||||
These allow you to install client-wide functionality such as logging, monitoring or tracing.
|
||||
|
||||
```python
|
||||
def log_request(request):
|
||||
print(f"Request event hook: {request.method} {request.url} - Waiting for response")
|
||||
|
||||
def log_response(response):
|
||||
request = response.request
|
||||
print(f"Response event hook: {request.method} {request.url} - Status {response.status_code}")
|
||||
|
||||
client = httpx.Client(event_hooks={'request': [log_request], 'response': [log_response]})
|
||||
```
|
||||
|
||||
You can also use these hooks to install response processing code, such as this
|
||||
example, which creates a client instance that always raises `httpx.HTTPStatusError`
|
||||
on 4xx and 5xx responses.
|
||||
|
||||
```python
|
||||
def raise_on_4xx_5xx(response):
|
||||
response.raise_for_status()
|
||||
|
||||
client = httpx.Client(event_hooks={'response': [raise_on_4xx_5xx]})
|
||||
```
|
||||
|
||||
!!! note
|
||||
Response event hooks are called before determining if the response body
|
||||
should be read or not.
|
||||
|
||||
If you need access to the response body inside an event hook, you'll
|
||||
need to call `response.read()`, or for AsyncClients, `response.aread()`.
|
||||
|
||||
The hooks are also allowed to modify `request` and `response` objects.
|
||||
|
||||
```python
|
||||
def add_timestamp(request):
|
||||
request.headers['x-request-timestamp'] = datetime.now(tz=datetime.utc).isoformat()
|
||||
|
||||
client = httpx.Client(event_hooks={'request': [add_timestamp]})
|
||||
```
|
||||
|
||||
Event hooks must always be set as a **list of callables**, and you may register
|
||||
multiple event hooks for each type of event.
|
||||
|
||||
As well as being able to set event hooks on instantiating the client, there
|
||||
is also an `.event_hooks` property, that allows you to inspect and modify
|
||||
the installed hooks.
|
||||
|
||||
```python
|
||||
client = httpx.Client()
|
||||
client.event_hooks['request'] = [log_request]
|
||||
client.event_hooks['response'] = [log_response, raise_on_4xx_5xx]
|
||||
```
|
||||
|
||||
!!! note
|
||||
If you are using HTTPX's async support, then you need to be aware that
|
||||
hooks registered with `httpx.AsyncClient` MUST be async functions,
|
||||
rather than plain functions.
|
||||
@ -1,242 +0,0 @@
|
||||
# Extensions
|
||||
|
||||
Request and response extensions provide a untyped space where additional information may be added.
|
||||
|
||||
Extensions should be used for features that may not be available on all transports, and that do not fit neatly into [the simplified request/response model](https://www.encode.io/httpcore/extensions/) that the underlying `httpcore` package uses as its API.
|
||||
|
||||
Several extensions are supported on the request:
|
||||
|
||||
```python
|
||||
# Request timeouts actually implemented as an extension on
|
||||
# the request, ensuring that they are passed throughout the
|
||||
# entire call stack.
|
||||
client = httpx.Client()
|
||||
response = client.get(
|
||||
"https://www.example.com",
|
||||
extensions={"timeout": {"connect": 5.0}}
|
||||
)
|
||||
response.request.extensions["timeout"]
|
||||
{"connect": 5.0}
|
||||
```
|
||||
|
||||
And on the response:
|
||||
|
||||
```python
|
||||
client = httpx.Client()
|
||||
response = client.get("https://www.example.com")
|
||||
print(response.extensions["http_version"]) # b"HTTP/1.1"
|
||||
# Other server responses could have been
|
||||
# b"HTTP/0.9", b"HTTP/1.0", or b"HTTP/1.1"
|
||||
```
|
||||
|
||||
## Request Extensions
|
||||
|
||||
### `"trace"`
|
||||
|
||||
The trace extension allows a callback handler to be installed to monitor the internal
|
||||
flow of events within the underlying `httpcore` transport.
|
||||
|
||||
The simplest way to explain this is with an example:
|
||||
|
||||
```python
|
||||
import httpx
|
||||
|
||||
def log(event_name, info):
|
||||
print(event_name, info)
|
||||
|
||||
client = httpx.Client()
|
||||
response = client.get("https://www.example.com/", extensions={"trace": log})
|
||||
# connection.connect_tcp.started {'host': 'www.example.com', 'port': 443, 'local_address': None, 'timeout': None}
|
||||
# connection.connect_tcp.complete {'return_value': <httpcore.backends.sync.SyncStream object at 0x1093f94d0>}
|
||||
# connection.start_tls.started {'ssl_context': <ssl.SSLContext object at 0x1093ee750>, 'server_hostname': b'www.example.com', 'timeout': None}
|
||||
# connection.start_tls.complete {'return_value': <httpcore.backends.sync.SyncStream object at 0x1093f9450>}
|
||||
# http11.send_request_headers.started {'request': <Request [b'GET']>}
|
||||
# http11.send_request_headers.complete {'return_value': None}
|
||||
# http11.send_request_body.started {'request': <Request [b'GET']>}
|
||||
# http11.send_request_body.complete {'return_value': None}
|
||||
# http11.receive_response_headers.started {'request': <Request [b'GET']>}
|
||||
# http11.receive_response_headers.complete {'return_value': (b'HTTP/1.1', 200, b'OK', [(b'Age', b'553715'), (b'Cache-Control', b'max-age=604800'), (b'Content-Type', b'text/html; charset=UTF-8'), (b'Date', b'Thu, 21 Oct 2021 17:08:42 GMT'), (b'Etag', b'"3147526947+ident"'), (b'Expires', b'Thu, 28 Oct 2021 17:08:42 GMT'), (b'Last-Modified', b'Thu, 17 Oct 2019 07:18:26 GMT'), (b'Server', b'ECS (nyb/1DCD)'), (b'Vary', b'Accept-Encoding'), (b'X-Cache', b'HIT'), (b'Content-Length', b'1256')])}
|
||||
# http11.receive_response_body.started {'request': <Request [b'GET']>}
|
||||
# http11.receive_response_body.complete {'return_value': None}
|
||||
# http11.response_closed.started {}
|
||||
# http11.response_closed.complete {'return_value': None}
|
||||
```
|
||||
|
||||
The `event_name` and `info` arguments here will be one of the following:
|
||||
|
||||
* `{event_type}.{event_name}.started`, `<dictionary of keyword arguments>`
|
||||
* `{event_type}.{event_name}.complete`, `{"return_value": <...>}`
|
||||
* `{event_type}.{event_name}.failed`, `{"exception": <...>}`
|
||||
|
||||
Note that when using async code the handler function passed to `"trace"` must be an `async def ...` function.
|
||||
|
||||
The following event types are currently exposed...
|
||||
|
||||
**Establishing the connection**
|
||||
|
||||
* `"connection.connect_tcp"`
|
||||
* `"connection.connect_unix_socket"`
|
||||
* `"connection.start_tls"`
|
||||
|
||||
**HTTP/1.1 events**
|
||||
|
||||
* `"http11.send_request_headers"`
|
||||
* `"http11.send_request_body"`
|
||||
* `"http11.receive_response"`
|
||||
* `"http11.receive_response_body"`
|
||||
* `"http11.response_closed"`
|
||||
|
||||
**HTTP/2 events**
|
||||
|
||||
* `"http2.send_connection_init"`
|
||||
* `"http2.send_request_headers"`
|
||||
* `"http2.send_request_body"`
|
||||
* `"http2.receive_response_headers"`
|
||||
* `"http2.receive_response_body"`
|
||||
* `"http2.response_closed"`
|
||||
|
||||
The exact set of trace events may be subject to change across different versions of `httpcore`. If you need to rely on a particular set of events it is recommended that you pin installation of the package to a fixed version.
|
||||
|
||||
### `"sni_hostname"`
|
||||
|
||||
The server's hostname, which is used to confirm the hostname supplied by the SSL certificate.
|
||||
|
||||
If you want to connect to an explicit IP address rather than using the standard DNS hostname lookup, then you'll need to use this request extension.
|
||||
|
||||
For example:
|
||||
|
||||
``` python
|
||||
# Connect to '185.199.108.153' but use 'www.encode.io' in the Host header,
|
||||
# and use 'www.encode.io' when SSL verifying the server hostname.
|
||||
client = httpx.Client()
|
||||
headers = {"Host": "www.encode.io"}
|
||||
extensions = {"sni_hostname": "www.encode.io"}
|
||||
response = client.get(
|
||||
"https://185.199.108.153/path",
|
||||
headers=headers,
|
||||
extensions=extensions
|
||||
)
|
||||
```
|
||||
|
||||
### `"timeout"`
|
||||
|
||||
A dictionary of `str: Optional[float]` timeout values.
|
||||
|
||||
May include values for `'connect'`, `'read'`, `'write'`, or `'pool'`.
|
||||
|
||||
For example:
|
||||
|
||||
```python
|
||||
# Timeout if a connection takes more than 5 seconds to established, or if
|
||||
# we are blocked waiting on the connection pool for more than 10 seconds.
|
||||
client = httpx.Client()
|
||||
response = client.get(
|
||||
"https://www.example.com",
|
||||
extensions={"timeout": {"connect": 5.0, "pool": 10.0}}
|
||||
)
|
||||
```
|
||||
|
||||
This extension is how the `httpx` timeouts are implemented, ensuring that the timeout values are associated with the request instance and passed throughout the stack. You shouldn't typically be working with this extension directly, but use the higher level `timeout` API instead.
|
||||
|
||||
### `"target"`
|
||||
|
||||
The target that is used as [the HTTP target instead of the URL path](https://datatracker.ietf.org/doc/html/rfc2616#section-5.1.2).
|
||||
|
||||
This enables support constructing requests that would otherwise be unsupported.
|
||||
|
||||
* URL paths with non-standard escaping applied.
|
||||
* Forward proxy requests using an absolute URI.
|
||||
* Tunneling proxy requests using `CONNECT` with hostname as the target.
|
||||
* Server-wide `OPTIONS *` requests.
|
||||
|
||||
Some examples:
|
||||
|
||||
Using the 'target' extension to send requests without the standard path escaping rules...
|
||||
|
||||
```python
|
||||
# Typically a request to "https://www.example.com/test^path" would
|
||||
# connect to "www.example.com" and send an HTTP/1.1 request like...
|
||||
#
|
||||
# GET /test%5Epath HTTP/1.1
|
||||
#
|
||||
# Using the target extension we can include the literal '^'...
|
||||
#
|
||||
# GET /test^path HTTP/1.1
|
||||
#
|
||||
# Note that requests must still be valid HTTP requests.
|
||||
# For example including whitespace in the target will raise a `LocalProtocolError`.
|
||||
extensions = {"target": b"/test^path"}
|
||||
response = httpx.get("https://www.example.com", extensions=extensions)
|
||||
```
|
||||
|
||||
The `target` extension also allows server-wide `OPTIONS *` requests to be constructed...
|
||||
|
||||
```python
|
||||
# This will send the following request...
|
||||
#
|
||||
# CONNECT * HTTP/1.1
|
||||
extensions = {"target": b"*"}
|
||||
response = httpx.request("CONNECT", "https://www.example.com", extensions=extensions)
|
||||
```
|
||||
|
||||
## Response Extensions
|
||||
|
||||
### `"http_version"`
|
||||
|
||||
The HTTP version, as bytes. Eg. `b"HTTP/1.1"`.
|
||||
|
||||
When using HTTP/1.1 the response line includes an explicit version, and the value of this key could feasibly be one of `b"HTTP/0.9"`, `b"HTTP/1.0"`, or `b"HTTP/1.1"`.
|
||||
|
||||
When using HTTP/2 there is no further response versioning included in the protocol, and the value of this key will always be `b"HTTP/2"`.
|
||||
|
||||
### `"reason_phrase"`
|
||||
|
||||
The reason-phrase of the HTTP response, as bytes. For example `b"OK"`. Some servers may include a custom reason phrase, although this is not recommended.
|
||||
|
||||
HTTP/2 onwards does not include a reason phrase on the wire.
|
||||
|
||||
When no key is included, a default based on the status code may be used.
|
||||
|
||||
### `"stream_id"`
|
||||
|
||||
When HTTP/2 is being used the `"stream_id"` response extension can be accessed to determine the ID of the data stream that the response was sent on.
|
||||
|
||||
### `"network_stream"`
|
||||
|
||||
The `"network_stream"` extension allows developers to handle HTTP `CONNECT` and `Upgrade` requests, by providing an API that steps outside the standard request/response model, and can directly read or write to the network.
|
||||
|
||||
The interface provided by the network stream:
|
||||
|
||||
* `read(max_bytes, timeout = None) -> bytes`
|
||||
* `write(buffer, timeout = None)`
|
||||
* `close()`
|
||||
* `start_tls(ssl_context, server_hostname = None, timeout = None) -> NetworkStream`
|
||||
* `get_extra_info(info) -> Any`
|
||||
|
||||
This API can be used as the foundation for working with HTTP proxies, WebSocket upgrades, and other advanced use-cases.
|
||||
|
||||
See the [network backends documentation](https://www.encode.io/httpcore/network-backends/) for more information on working directly with network streams.
|
||||
|
||||
**Extra network information**
|
||||
|
||||
The network stream abstraction also allows access to various low-level information that may be exposed by the underlying socket:
|
||||
|
||||
```python
|
||||
response = httpx.get("https://www.example.com")
|
||||
network_stream = response.extensions["network_stream"]
|
||||
|
||||
client_addr = network_stream.get_extra_info("client_addr")
|
||||
server_addr = network_stream.get_extra_info("server_addr")
|
||||
print("Client address", client_addr)
|
||||
print("Server address", server_addr)
|
||||
```
|
||||
|
||||
The socket SSL information is also available through this interface, although you need to ensure that the underlying connection is still open, in order to access it...
|
||||
|
||||
```python
|
||||
with httpx.stream("GET", "https://www.example.com") as response:
|
||||
network_stream = response.extensions["network_stream"]
|
||||
|
||||
ssl_object = network_stream.get_extra_info("ssl_object")
|
||||
print("TLS version", ssl_object.version())
|
||||
```
|
||||
@ -1,83 +0,0 @@
|
||||
HTTPX supports setting up [HTTP proxies](https://en.wikipedia.org/wiki/Proxy_server#Web_proxy_servers) via the `proxy` parameter to be passed on client initialization or top-level API functions like `httpx.get(..., proxy=...)`.
|
||||
|
||||
<div align="center">
|
||||
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/2/27/Open_proxy_h2g2bob.svg/480px-Open_proxy_h2g2bob.svg.png"/>
|
||||
<figcaption><em>Diagram of how a proxy works (source: Wikipedia). The left hand side "Internet" blob may be your HTTPX client requesting <code>example.com</code> through a proxy.</em></figcaption>
|
||||
</div>
|
||||
|
||||
## HTTP Proxies
|
||||
|
||||
To route all traffic (HTTP and HTTPS) to a proxy located at `http://localhost:8030`, pass the proxy URL to the client...
|
||||
|
||||
```python
|
||||
with httpx.Client(proxy="http://localhost:8030") as client:
|
||||
...
|
||||
```
|
||||
|
||||
For more advanced use cases, pass a mounts `dict`. For example, to route HTTP and HTTPS requests to 2 different proxies, respectively located at `http://localhost:8030`, and `http://localhost:8031`, pass a `dict` of proxy URLs:
|
||||
|
||||
```python
|
||||
proxy_mounts = {
|
||||
"http://": httpx.HTTPTransport(proxy="http://localhost:8030"),
|
||||
"https://": httpx.HTTPTransport(proxy="http://localhost:8031"),
|
||||
}
|
||||
|
||||
with httpx.Client(mounts=proxy_mounts) as client:
|
||||
...
|
||||
```
|
||||
|
||||
For detailed information about proxy routing, see the [Routing](#routing) section.
|
||||
|
||||
!!! tip "Gotcha"
|
||||
In most cases, the proxy URL for the `https://` key _should_ use the `http://` scheme (that's not a typo!).
|
||||
|
||||
This is because HTTP proxying requires initiating a connection with the proxy server. While it's possible that your proxy supports doing it via HTTPS, most proxies only support doing it via HTTP.
|
||||
|
||||
For more information, see [FORWARD vs TUNNEL](#forward-vs-tunnel).
|
||||
|
||||
## Authentication
|
||||
|
||||
Proxy credentials can be passed as the `userinfo` section of the proxy URL. For example:
|
||||
|
||||
```python
|
||||
with httpx.Client(proxy="http://username:password@localhost:8030") as client:
|
||||
...
|
||||
```
|
||||
|
||||
## Proxy mechanisms
|
||||
|
||||
!!! note
|
||||
This section describes **advanced** proxy concepts and functionality.
|
||||
|
||||
### FORWARD vs TUNNEL
|
||||
|
||||
In general, the flow for making an HTTP request through a proxy is as follows:
|
||||
|
||||
1. The client connects to the proxy (initial connection request).
|
||||
2. The proxy transfers data to the server on your behalf.
|
||||
|
||||
How exactly step 2/ is performed depends on which of two proxying mechanisms is used:
|
||||
|
||||
* **Forwarding**: the proxy makes the request for you, and sends back the response it obtained from the server.
|
||||
* **Tunnelling**: the proxy establishes a TCP connection to the server on your behalf, and the client reuses this connection to send the request and receive the response. This is known as an [HTTP Tunnel](https://en.wikipedia.org/wiki/HTTP_tunnel). This mechanism is how you can access websites that use HTTPS from an HTTP proxy (the client "upgrades" the connection to HTTPS by performing the TLS handshake with the server over the TCP connection provided by the proxy).
|
||||
|
||||
### Troubleshooting proxies
|
||||
|
||||
If you encounter issues when setting up proxies, please refer to our [Troubleshooting guide](../troubleshooting.md#proxies).
|
||||
|
||||
## SOCKS
|
||||
|
||||
In addition to HTTP proxies, `httpcore` also supports proxies using the SOCKS protocol.
|
||||
This is an optional feature that requires an additional third-party library be installed before use.
|
||||
|
||||
You can install SOCKS support using `pip`:
|
||||
|
||||
```shell
|
||||
$ pip install httpx[socks]
|
||||
```
|
||||
|
||||
You can now configure a client to make requests via a proxy using the SOCKS protocol:
|
||||
|
||||
```python
|
||||
httpx.Client(proxy='socks5://user:pass@host:port')
|
||||
```
|
||||
@ -1,13 +0,0 @@
|
||||
You can control the connection pool size using the `limits` keyword
|
||||
argument on the client. It takes instances of `httpx.Limits` which define:
|
||||
|
||||
- `max_keepalive_connections`, number of allowable keep-alive connections, or `None` to always
|
||||
allow. (Defaults 20)
|
||||
- `max_connections`, maximum number of allowable connections, or `None` for no limits.
|
||||
(Default 100)
|
||||
- `keepalive_expiry`, time limit on idle keep-alive connections in seconds, or `None` for no limits. (Default 5)
|
||||
|
||||
```python
|
||||
limits = httpx.Limits(max_keepalive_connections=5, max_connections=10)
|
||||
client = httpx.Client(limits=limits)
|
||||
```
|
||||
@ -1,89 +0,0 @@
|
||||
When making a request over HTTPS, HTTPX needs to verify the identity of the requested host. To do this, it uses a bundle of SSL certificates (a.k.a. CA bundle) delivered by a trusted certificate authority (CA).
|
||||
|
||||
### Enabling and disabling verification
|
||||
|
||||
By default httpx will verify HTTPS connections, and raise an error for invalid SSL cases...
|
||||
|
||||
```pycon
|
||||
>>> httpx.get("https://expired.badssl.com/")
|
||||
httpx.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:997)
|
||||
```
|
||||
|
||||
You can disable SSL verification completely and allow insecure requests...
|
||||
|
||||
```pycon
|
||||
>>> httpx.get("https://expired.badssl.com/", verify=False)
|
||||
<Response [200 OK]>
|
||||
```
|
||||
|
||||
### Configuring client instances
|
||||
|
||||
If you're using a `Client()` instance you should pass any `verify=<...>` configuration when instantiating the client.
|
||||
|
||||
By default the [certifi CA bundle](https://certifiio.readthedocs.io/en/latest/) is used for SSL verification.
|
||||
|
||||
For more complex configurations you can pass an [SSL Context](https://docs.python.org/3/library/ssl.html) instance...
|
||||
|
||||
```python
|
||||
import certifi
|
||||
import httpx
|
||||
import ssl
|
||||
|
||||
# This SSL context is equivalent to the default `verify=True`.
|
||||
ctx = ssl.create_default_context(cafile=certifi.where())
|
||||
client = httpx.Client(verify=ctx)
|
||||
```
|
||||
|
||||
Using [the `truststore` package](https://truststore.readthedocs.io/) to support system certificate stores...
|
||||
|
||||
```python
|
||||
import ssl
|
||||
import truststore
|
||||
import httpx
|
||||
|
||||
# Use system certificate stores.
|
||||
ctx = truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
||||
client = httpx.Client(verify=ctx)
|
||||
```
|
||||
|
||||
Loding an alternative certificate verification store using [the standard SSL context API](https://docs.python.org/3/library/ssl.html)...
|
||||
|
||||
```python
|
||||
import httpx
|
||||
import ssl
|
||||
|
||||
# Use an explicitly configured certificate store.
|
||||
ctx = ssl.create_default_context(cafile="path/to/certs.pem") # Either cafile or capath.
|
||||
client = httpx.Client(verify=ctx)
|
||||
```
|
||||
|
||||
### Client side certificates
|
||||
|
||||
Client side certificates allow a remote server to verify the client. They tend to be used within private organizations to authenticate requests to remote servers.
|
||||
|
||||
You can specify client-side certificates, using the [`.load_cert_chain()`](https://docs.python.org/3/library/ssl.html#ssl.SSLContext.load_cert_chain) API...
|
||||
|
||||
```python
|
||||
ctx = ssl.create_default_context()
|
||||
ctx.load_cert_chain(certfile="path/to/client.pem") # Optionally also keyfile or password.
|
||||
client = httpx.Client(verify=ctx)
|
||||
```
|
||||
|
||||
### Working with `SSL_CERT_FILE` and `SSL_CERT_DIR`
|
||||
|
||||
`httpx` does respect the `SSL_CERT_FILE` and `SSL_CERT_DIR` environment variables by default. For details, refer to [the section on the environment variables page](../environment_variables.md#ssl_cert_file).
|
||||
|
||||
### Making HTTPS requests to a local server
|
||||
|
||||
When making requests to local servers, such as a development server running on `localhost`, you will typically be using unencrypted HTTP connections.
|
||||
|
||||
If you do need to make HTTPS connections to a local server, for example to test an HTTPS-only service, you will need to create and use your own certificates. Here's one way to do it...
|
||||
|
||||
1. Use [trustme](https://github.com/python-trio/trustme) to generate a pair of server key/cert files, and a client cert file.
|
||||
2. Pass the server key/cert files when starting your local server. (This depends on the particular web server you're using. For example, [Uvicorn](https://www.uvicorn.org) provides the `--ssl-keyfile` and `--ssl-certfile` options.)
|
||||
3. Configure `httpx` to use the certificates stored in `client.pem`.
|
||||
|
||||
```python
|
||||
ctx = ssl.create_default_context(cafile="client.pem")
|
||||
client = httpx.Client(verify=ctx)
|
||||
```
|
||||
@ -1,75 +0,0 @@
|
||||
When accessing `response.text`, we need to decode the response bytes into a unicode text representation.
|
||||
|
||||
By default `httpx` will use `"charset"` information included in the response `Content-Type` header to determine how the response bytes should be decoded into text.
|
||||
|
||||
In cases where no charset information is included on the response, the default behaviour is to assume "utf-8" encoding, which is by far the most widely used text encoding on the internet.
|
||||
|
||||
## Using the default encoding
|
||||
|
||||
To understand this better let's start by looking at the default behaviour for text decoding...
|
||||
|
||||
```python
|
||||
import httpx
|
||||
# Instantiate a client with the default configuration.
|
||||
client = httpx.Client()
|
||||
# Using the client...
|
||||
response = client.get(...)
|
||||
print(response.encoding) # This will either print the charset given in
|
||||
# the Content-Type charset, or else "utf-8".
|
||||
print(response.text) # The text will either be decoded with the Content-Type
|
||||
# charset, or using "utf-8".
|
||||
```
|
||||
|
||||
This is normally absolutely fine. Most servers will respond with a properly formatted Content-Type header, including a charset encoding. And in most cases where no charset encoding is included, UTF-8 is very likely to be used, since it is so widely adopted.
|
||||
|
||||
## Using an explicit encoding
|
||||
|
||||
In some cases we might be making requests to a site where no character set information is being set explicitly by the server, but we know what the encoding is. In this case it's best to set the default encoding explicitly on the client.
|
||||
|
||||
```python
|
||||
import httpx
|
||||
# Instantiate a client with a Japanese character set as the default encoding.
|
||||
client = httpx.Client(default_encoding="shift-jis")
|
||||
# Using the client...
|
||||
response = client.get(...)
|
||||
print(response.encoding) # This will either print the charset given in
|
||||
# the Content-Type charset, or else "shift-jis".
|
||||
print(response.text) # The text will either be decoded with the Content-Type
|
||||
# charset, or using "shift-jis".
|
||||
```
|
||||
|
||||
## Using auto-detection
|
||||
|
||||
In cases where the server is not reliably including character set information, and where we don't know what encoding is being used, we can enable auto-detection to make a best-guess attempt when decoding from bytes to text.
|
||||
|
||||
To use auto-detection you need to set the `default_encoding` argument to a callable instead of a string. This callable should be a function which takes the input bytes as an argument and returns the character set to use for decoding those bytes to text.
|
||||
|
||||
There are two widely used Python packages which both handle this functionality:
|
||||
|
||||
* [`chardet`](https://chardet.readthedocs.io/) - This is a well established package, and is a port of [the auto-detection code in Mozilla](https://www-archive.mozilla.org/projects/intl/chardet.html).
|
||||
* [`charset-normalizer`](https://charset-normalizer.readthedocs.io/) - A newer package, motivated by `chardet`, with a different approach.
|
||||
|
||||
Let's take a look at installing autodetection using one of these packages...
|
||||
|
||||
```shell
|
||||
$ pip install httpx
|
||||
$ pip install chardet
|
||||
```
|
||||
|
||||
Once `chardet` is installed, we can configure a client to use character-set autodetection.
|
||||
|
||||
```python
|
||||
import httpx
|
||||
import chardet
|
||||
|
||||
def autodetect(content):
|
||||
return chardet.detect(content).get("encoding")
|
||||
|
||||
# Using a client with character-set autodetection enabled.
|
||||
client = httpx.Client(default_encoding=autodetect)
|
||||
response = client.get(...)
|
||||
print(response.encoding) # This will either print the charset given in
|
||||
# the Content-Type charset, or else the auto-detected
|
||||
# character set.
|
||||
print(response.text)
|
||||
```
|
||||
@ -1,71 +0,0 @@
|
||||
HTTPX is careful to enforce timeouts everywhere by default.
|
||||
|
||||
The default behavior is to raise a `TimeoutException` after 5 seconds of
|
||||
network inactivity.
|
||||
|
||||
## Setting and disabling timeouts
|
||||
|
||||
You can set timeouts for an individual request:
|
||||
|
||||
```python
|
||||
# Using the top-level API:
|
||||
httpx.get('http://example.com/api/v1/example', timeout=10.0)
|
||||
|
||||
# Using a client instance:
|
||||
with httpx.Client() as client:
|
||||
client.get("http://example.com/api/v1/example", timeout=10.0)
|
||||
```
|
||||
|
||||
Or disable timeouts for an individual request:
|
||||
|
||||
```python
|
||||
# Using the top-level API:
|
||||
httpx.get('http://example.com/api/v1/example', timeout=None)
|
||||
|
||||
# Using a client instance:
|
||||
with httpx.Client() as client:
|
||||
client.get("http://example.com/api/v1/example", timeout=None)
|
||||
```
|
||||
|
||||
## Setting a default timeout on a client
|
||||
|
||||
You can set a timeout on a client instance, which results in the given
|
||||
`timeout` being used as the default for requests made with this client:
|
||||
|
||||
```python
|
||||
client = httpx.Client() # Use a default 5s timeout everywhere.
|
||||
client = httpx.Client(timeout=10.0) # Use a default 10s timeout everywhere.
|
||||
client = httpx.Client(timeout=None) # Disable all timeouts by default.
|
||||
```
|
||||
|
||||
## Fine tuning the configuration
|
||||
|
||||
HTTPX also allows you to specify the timeout behavior in more fine grained detail.
|
||||
|
||||
There are four different types of timeouts that may occur. These are **connect**,
|
||||
**read**, **write**, and **pool** timeouts.
|
||||
|
||||
* The **connect** timeout specifies the maximum amount of time to wait until
|
||||
a socket connection to the requested host is established. If HTTPX is unable to connect
|
||||
within this time frame, a `ConnectTimeout` exception is raised.
|
||||
* The **read** timeout specifies the maximum duration to wait for a chunk of
|
||||
data to be received (for example, a chunk of the response body). If HTTPX is
|
||||
unable to receive data within this time frame, a `ReadTimeout` exception is raised.
|
||||
* The **write** timeout specifies the maximum duration to wait for a chunk of
|
||||
data to be sent (for example, a chunk of the request body). If HTTPX is unable
|
||||
to send data within this time frame, a `WriteTimeout` exception is raised.
|
||||
* The **pool** timeout specifies the maximum duration to wait for acquiring
|
||||
a connection from the connection pool. If HTTPX is unable to acquire a connection
|
||||
within this time frame, a `PoolTimeout` exception is raised. A related
|
||||
configuration here is the maximum number of allowable connections in the
|
||||
connection pool, which is configured by the `limits` argument.
|
||||
|
||||
You can configure the timeout behavior for any of these values...
|
||||
|
||||
```python
|
||||
# A client with a 60s timeout for connecting, and a 10s timeout elsewhere.
|
||||
timeout = httpx.Timeout(10.0, connect=60.0)
|
||||
client = httpx.Client(timeout=timeout)
|
||||
|
||||
response = client.get('http://example.com/')
|
||||
```
|
||||
@ -1,454 +0,0 @@
|
||||
HTTPX's `Client` also accepts a `transport` argument. This argument allows you
|
||||
to provide a custom Transport object that will be used to perform the actual
|
||||
sending of the requests.
|
||||
|
||||
## HTTP Transport
|
||||
|
||||
For some advanced configuration you might need to instantiate a transport
|
||||
class directly, and pass it to the client instance. One example is the
|
||||
`local_address` configuration which is only available via this low-level API.
|
||||
|
||||
```pycon
|
||||
>>> import httpx
|
||||
>>> transport = httpx.HTTPTransport(local_address="0.0.0.0")
|
||||
>>> client = httpx.Client(transport=transport)
|
||||
```
|
||||
|
||||
Connection retries are also available via this interface. Requests will be retried the given number of times in case an `httpx.ConnectError` or an `httpx.ConnectTimeout` occurs, allowing smoother operation under flaky networks. If you need other forms of retry behaviors, such as handling read/write errors or reacting to `503 Service Unavailable`, consider general-purpose tools such as [tenacity](https://github.com/jd/tenacity).
|
||||
|
||||
```pycon
|
||||
>>> import httpx
|
||||
>>> transport = httpx.HTTPTransport(retries=1)
|
||||
>>> client = httpx.Client(transport=transport)
|
||||
```
|
||||
|
||||
Similarly, instantiating a transport directly provides a `uds` option for
|
||||
connecting via a Unix Domain Socket that is only available via this low-level API:
|
||||
|
||||
```pycon
|
||||
>>> import httpx
|
||||
>>> # Connect to the Docker API via a Unix Socket.
|
||||
>>> transport = httpx.HTTPTransport(uds="/var/run/docker.sock")
|
||||
>>> client = httpx.Client(transport=transport)
|
||||
>>> response = client.get("http://docker/info")
|
||||
>>> response.json()
|
||||
{"ID": "...", "Containers": 4, "Images": 74, ...}
|
||||
```
|
||||
|
||||
## WSGI Transport
|
||||
|
||||
You can configure an `httpx` client to call directly into a Python web application using the WSGI protocol.
|
||||
|
||||
This is particularly useful for two main use-cases:
|
||||
|
||||
* Using `httpx` as a client inside test cases.
|
||||
* Mocking out external services during tests or in dev or staging environments.
|
||||
|
||||
### Example
|
||||
|
||||
Here's an example of integrating against a Flask application:
|
||||
|
||||
```python
|
||||
from flask import Flask
|
||||
import httpx
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route("/")
|
||||
def hello():
|
||||
return "Hello World!"
|
||||
|
||||
transport = httpx.WSGITransport(app=app)
|
||||
with httpx.Client(transport=transport, base_url="http://testserver") as client:
|
||||
r = client.get("/")
|
||||
assert r.status_code == 200
|
||||
assert r.text == "Hello World!"
|
||||
```
|
||||
|
||||
### Configuration
|
||||
|
||||
For some more complex cases you might need to customize the WSGI transport. This allows you to:
|
||||
|
||||
* Inspect 500 error responses rather than raise exceptions by setting `raise_app_exceptions=False`.
|
||||
* Mount the WSGI application at a subpath by setting `script_name` (WSGI).
|
||||
* Use a given client address for requests by setting `remote_addr` (WSGI).
|
||||
|
||||
For example:
|
||||
|
||||
```python
|
||||
# Instantiate a client that makes WSGI requests with a client IP of "1.2.3.4".
|
||||
transport = httpx.WSGITransport(app=app, remote_addr="1.2.3.4")
|
||||
with httpx.Client(transport=transport, base_url="http://testserver") as client:
|
||||
...
|
||||
```
|
||||
|
||||
## ASGI Transport
|
||||
|
||||
You can configure an `httpx` client to call directly into an async Python web application using the ASGI protocol.
|
||||
|
||||
This is particularly useful for two main use-cases:
|
||||
|
||||
* Using `httpx` as a client inside test cases.
|
||||
* Mocking out external services during tests or in dev or staging environments.
|
||||
|
||||
### Example
|
||||
|
||||
Let's take this Starlette application as an example:
|
||||
|
||||
```python
|
||||
from starlette.applications import Starlette
|
||||
from starlette.responses import HTMLResponse
|
||||
from starlette.routing import Route
|
||||
|
||||
|
||||
async def hello(request):
|
||||
return HTMLResponse("Hello World!")
|
||||
|
||||
|
||||
app = Starlette(routes=[Route("/", hello)])
|
||||
```
|
||||
|
||||
We can make requests directly against the application, like so:
|
||||
|
||||
```python
|
||||
transport = httpx.ASGITransport(app=app)
|
||||
|
||||
async with httpx.AsyncClient(transport=transport, base_url="http://testserver") as client:
|
||||
r = await client.get("/")
|
||||
assert r.status_code == 200
|
||||
assert r.text == "Hello World!"
|
||||
```
|
||||
|
||||
### Configuration
|
||||
|
||||
For some more complex cases you might need to customise the ASGI transport. This allows you to:
|
||||
|
||||
* Inspect 500 error responses rather than raise exceptions by setting `raise_app_exceptions=False`.
|
||||
* Mount the ASGI application at a subpath by setting `root_path`.
|
||||
* Use a given client address for requests by setting `client`.
|
||||
|
||||
For example:
|
||||
|
||||
```python
|
||||
# Instantiate a client that makes ASGI requests with a client IP of "1.2.3.4",
|
||||
# on port 123.
|
||||
transport = httpx.ASGITransport(app=app, client=("1.2.3.4", 123))
|
||||
async with httpx.AsyncClient(transport=transport, base_url="http://testserver") as client:
|
||||
...
|
||||
```
|
||||
|
||||
See [the ASGI documentation](https://asgi.readthedocs.io/en/latest/specs/www.html#connection-scope) for more details on the `client` and `root_path` keys.
|
||||
|
||||
### ASGI startup and shutdown
|
||||
|
||||
It is not in the scope of HTTPX to trigger ASGI lifespan events of your app.
|
||||
|
||||
However it is suggested to use `LifespanManager` from [asgi-lifespan](https://github.com/florimondmanca/asgi-lifespan#usage) in pair with `AsyncClient`.
|
||||
|
||||
## Custom transports
|
||||
|
||||
A transport instance must implement the low-level Transport API which deals
|
||||
with sending a single request, and returning a response. You should either
|
||||
subclass `httpx.BaseTransport` to implement a transport to use with `Client`,
|
||||
or subclass `httpx.AsyncBaseTransport` to implement a transport to
|
||||
use with `AsyncClient`.
|
||||
|
||||
At the layer of the transport API we're using the familiar `Request` and
|
||||
`Response` models.
|
||||
|
||||
See the `handle_request` and `handle_async_request` docstrings for more details
|
||||
on the specifics of the Transport API.
|
||||
|
||||
A complete example of a custom transport implementation would be:
|
||||
|
||||
```python
|
||||
import json
|
||||
import httpx
|
||||
|
||||
class HelloWorldTransport(httpx.BaseTransport):
|
||||
"""
|
||||
A mock transport that always returns a JSON "Hello, world!" response.
|
||||
"""
|
||||
|
||||
def handle_request(self, request):
|
||||
return httpx.Response(200, json={"text": "Hello, world!"})
|
||||
```
|
||||
|
||||
Or this example, which uses a custom transport and `httpx.Mounts` to always redirect `http://` requests.
|
||||
|
||||
```python
|
||||
class HTTPSRedirect(httpx.BaseTransport):
|
||||
"""
|
||||
A transport that always redirects to HTTPS.
|
||||
"""
|
||||
def handle_request(self, request):
|
||||
url = request.url.copy_with(scheme="https")
|
||||
return httpx.Response(303, headers={"Location": str(url)})
|
||||
|
||||
# A client where any `http` requests are always redirected to `https`
|
||||
transport = httpx.Mounts({
|
||||
'http://': HTTPSRedirect()
|
||||
'https://': httpx.HTTPTransport()
|
||||
})
|
||||
client = httpx.Client(transport=transport)
|
||||
```
|
||||
|
||||
A useful pattern here is custom transport classes that wrap the default HTTP implementation. For example...
|
||||
|
||||
```python
|
||||
class DebuggingTransport(httpx.BaseTransport):
|
||||
def __init__(self, **kwargs):
|
||||
self._wrapper = httpx.HTTPTransport(**kwargs)
|
||||
|
||||
def handle_request(self, request):
|
||||
print(f">>> {request}")
|
||||
response = self._wrapper.handle_request(request)
|
||||
print(f"<<< {response}")
|
||||
return response
|
||||
|
||||
def close(self):
|
||||
self._wrapper.close()
|
||||
|
||||
transport = DebuggingTransport()
|
||||
client = httpx.Client(transport=transport)
|
||||
```
|
||||
|
||||
Here's another case, where we're using a round-robin across a number of different proxies...
|
||||
|
||||
```python
|
||||
class ProxyRoundRobin(httpx.BaseTransport):
|
||||
def __init__(self, proxies, **kwargs):
|
||||
self._transports = [
|
||||
httpx.HTTPTransport(proxy=proxy, **kwargs)
|
||||
for proxy in proxies
|
||||
]
|
||||
self._idx = 0
|
||||
|
||||
def handle_request(self, request):
|
||||
transport = self._transports[self._idx]
|
||||
self._idx = (self._idx + 1) % len(self._transports)
|
||||
return transport.handle_request(request)
|
||||
|
||||
def close(self):
|
||||
for transport in self._transports:
|
||||
transport.close()
|
||||
|
||||
proxies = [
|
||||
httpx.Proxy("http://127.0.0.1:8081"),
|
||||
httpx.Proxy("http://127.0.0.1:8082"),
|
||||
httpx.Proxy("http://127.0.0.1:8083"),
|
||||
]
|
||||
transport = ProxyRoundRobin(proxies=proxies)
|
||||
client = httpx.Client(transport=transport)
|
||||
```
|
||||
|
||||
## Mock transports
|
||||
|
||||
During testing it can often be useful to be able to mock out a transport,
|
||||
and return pre-determined responses, rather than making actual network requests.
|
||||
|
||||
The `httpx.MockTransport` class accepts a handler function, which can be used
|
||||
to map requests onto pre-determined responses:
|
||||
|
||||
```python
|
||||
def handler(request):
|
||||
return httpx.Response(200, json={"text": "Hello, world!"})
|
||||
|
||||
|
||||
# Switch to a mock transport, if the TESTING environment variable is set.
|
||||
if os.environ.get('TESTING', '').upper() == "TRUE":
|
||||
transport = httpx.MockTransport(handler)
|
||||
else:
|
||||
transport = httpx.HTTPTransport()
|
||||
|
||||
client = httpx.Client(transport=transport)
|
||||
```
|
||||
|
||||
For more advanced use-cases you might want to take a look at either [the third-party
|
||||
mocking library, RESPX](https://lundberg.github.io/respx/), or the [pytest-httpx library](https://github.com/Colin-b/pytest_httpx).
|
||||
|
||||
## Mounting transports
|
||||
|
||||
You can also mount transports against given schemes or domains, to control
|
||||
which transport an outgoing request should be routed via, with [the same style
|
||||
used for specifying proxy routing](#routing).
|
||||
|
||||
```python
|
||||
import httpx
|
||||
|
||||
class HTTPSRedirectTransport(httpx.BaseTransport):
|
||||
"""
|
||||
A transport that always redirects to HTTPS.
|
||||
"""
|
||||
|
||||
def handle_request(self, method, url, headers, stream, extensions):
|
||||
scheme, host, port, path = url
|
||||
if port is None:
|
||||
location = b"https://%s%s" % (host, path)
|
||||
else:
|
||||
location = b"https://%s:%d%s" % (host, port, path)
|
||||
stream = httpx.ByteStream(b"")
|
||||
headers = [(b"location", location)]
|
||||
extensions = {}
|
||||
return 303, headers, stream, extensions
|
||||
|
||||
|
||||
# A client where any `http` requests are always redirected to `https`
|
||||
mounts = {'http://': HTTPSRedirectTransport()}
|
||||
client = httpx.Client(mounts=mounts)
|
||||
```
|
||||
|
||||
A couple of other sketches of how you might take advantage of mounted transports...
|
||||
|
||||
Disabling HTTP/2 on a single given domain...
|
||||
|
||||
```python
|
||||
mounts = {
|
||||
"all://": httpx.HTTPTransport(http2=True),
|
||||
"all://*example.org": httpx.HTTPTransport()
|
||||
}
|
||||
client = httpx.Client(mounts=mounts)
|
||||
```
|
||||
|
||||
Mocking requests to a given domain:
|
||||
|
||||
```python
|
||||
# All requests to "example.org" should be mocked out.
|
||||
# Other requests occur as usual.
|
||||
def handler(request):
|
||||
return httpx.Response(200, json={"text": "Hello, World!"})
|
||||
|
||||
mounts = {"all://example.org": httpx.MockTransport(handler)}
|
||||
client = httpx.Client(mounts=mounts)
|
||||
```
|
||||
|
||||
Adding support for custom schemes:
|
||||
|
||||
```python
|
||||
# Support URLs like "file:///Users/sylvia_green/websites/new_client/index.html"
|
||||
mounts = {"file://": FileSystemTransport()}
|
||||
client = httpx.Client(mounts=mounts)
|
||||
```
|
||||
|
||||
### Routing
|
||||
|
||||
HTTPX provides a powerful mechanism for routing requests, allowing you to write complex rules that specify which transport should be used for each request.
|
||||
|
||||
The `mounts` dictionary maps URL patterns to HTTP transports. HTTPX matches requested URLs against URL patterns to decide which transport should be used, if any. Matching is done from most specific URL patterns (e.g. `https://<domain>:<port>`) to least specific ones (e.g. `https://`).
|
||||
|
||||
HTTPX supports routing requests based on **scheme**, **domain**, **port**, or a combination of these.
|
||||
|
||||
### Wildcard routing
|
||||
|
||||
Route everything through a transport...
|
||||
|
||||
```python
|
||||
mounts = {
|
||||
"all://": httpx.HTTPTransport(proxy="http://localhost:8030"),
|
||||
}
|
||||
```
|
||||
|
||||
### Scheme routing
|
||||
|
||||
Route HTTP requests through one transport, and HTTPS requests through another...
|
||||
|
||||
```python
|
||||
mounts = {
|
||||
"http://": httpx.HTTPTransport(proxy="http://localhost:8030"),
|
||||
"https://": httpx.HTTPTransport(proxy="http://localhost:8031"),
|
||||
}
|
||||
```
|
||||
|
||||
### Domain routing
|
||||
|
||||
Proxy all requests on domain "example.com", let other requests pass through...
|
||||
|
||||
```python
|
||||
mounts = {
|
||||
"all://example.com": httpx.HTTPTransport(proxy="http://localhost:8030"),
|
||||
}
|
||||
```
|
||||
|
||||
Proxy HTTP requests on domain "example.com", let HTTPS and other requests pass through...
|
||||
|
||||
```python
|
||||
mounts = {
|
||||
"http://example.com": httpx.HTTPTransport(proxy="http://localhost:8030"),
|
||||
}
|
||||
```
|
||||
|
||||
Proxy all requests to "example.com" and its subdomains, let other requests pass through...
|
||||
|
||||
```python
|
||||
mounts = {
|
||||
"all://*example.com": httpx.HTTPTransport(proxy="http://localhost:8030"),
|
||||
}
|
||||
```
|
||||
|
||||
Proxy all requests to strict subdomains of "example.com", let "example.com" and other requests pass through...
|
||||
|
||||
```python
|
||||
mounts = {
|
||||
"all://*.example.com": httpx.HTTPTransport(proxy="http://localhost:8030"),
|
||||
}
|
||||
```
|
||||
|
||||
### Port routing
|
||||
|
||||
Proxy HTTPS requests on port 1234 to "example.com"...
|
||||
|
||||
```python
|
||||
mounts = {
|
||||
"https://example.com:1234": httpx.HTTPTransport(proxy="http://localhost:8030"),
|
||||
}
|
||||
```
|
||||
|
||||
Proxy all requests on port 1234...
|
||||
|
||||
```python
|
||||
mounts = {
|
||||
"all://*:1234": httpx.HTTPTransport(proxy="http://localhost:8030"),
|
||||
}
|
||||
```
|
||||
|
||||
### No-proxy support
|
||||
|
||||
It is also possible to define requests that _shouldn't_ be routed through the transport.
|
||||
|
||||
To do so, pass `None` as the proxy URL. For example...
|
||||
|
||||
```python
|
||||
mounts = {
|
||||
# Route requests through a proxy by default...
|
||||
"all://": httpx.HTTPTransport(proxy="http://localhost:8031"),
|
||||
# Except those for "example.com".
|
||||
"all://example.com": None,
|
||||
}
|
||||
```
|
||||
|
||||
### Complex configuration example
|
||||
|
||||
You can combine the routing features outlined above to build complex proxy routing configurations. For example...
|
||||
|
||||
```python
|
||||
mounts = {
|
||||
# Route all traffic through a proxy by default...
|
||||
"all://": httpx.HTTPTransport(proxy="http://localhost:8030"),
|
||||
# But don't use proxies for HTTPS requests to "domain.io"...
|
||||
"https://domain.io": None,
|
||||
# And use another proxy for requests to "example.com" and its subdomains...
|
||||
"all://*example.com": httpx.HTTPTransport(proxy="http://localhost:8031"),
|
||||
# And yet another proxy if HTTP is used,
|
||||
# and the "internal" subdomain on port 5550 is requested...
|
||||
"http://internal.example.com:5550": httpx.HTTPTransport(proxy="http://localhost:8032"),
|
||||
}
|
||||
```
|
||||
|
||||
### Environment variables
|
||||
|
||||
There are also environment variables that can be used to control the dictionary of the client mounts.
|
||||
They can be used to configure HTTP proxying for clients.
|
||||
|
||||
See documentation on [`HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY`](../environment_variables.md#http_proxy-https_proxy-all_proxy)
|
||||
and [`NO_PROXY`](../environment_variables.md#no_proxy) for more information.
|
||||
176
docs/api.md
176
docs/api.md
@ -1,176 +0,0 @@
|
||||
# Developer 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.
|
||||
|
||||
::: httpx.request
|
||||
:docstring:
|
||||
|
||||
::: httpx.get
|
||||
:docstring:
|
||||
|
||||
::: httpx.options
|
||||
:docstring:
|
||||
|
||||
::: httpx.head
|
||||
:docstring:
|
||||
|
||||
::: httpx.post
|
||||
:docstring:
|
||||
|
||||
::: httpx.put
|
||||
:docstring:
|
||||
|
||||
::: httpx.patch
|
||||
:docstring:
|
||||
|
||||
::: httpx.delete
|
||||
:docstring:
|
||||
|
||||
::: httpx.stream
|
||||
:docstring:
|
||||
|
||||
## `Client`
|
||||
|
||||
::: httpx.Client
|
||||
:docstring:
|
||||
:members: headers cookies params auth request get head options post put patch delete stream build_request send close
|
||||
|
||||
## `AsyncClient`
|
||||
|
||||
::: httpx.AsyncClient
|
||||
:docstring:
|
||||
:members: headers cookies params auth request get head options post put patch delete stream build_request send aclose
|
||||
|
||||
|
||||
## `Response`
|
||||
|
||||
*An HTTP response.*
|
||||
|
||||
* `def __init__(...)`
|
||||
* `.status_code` - **int**
|
||||
* `.reason_phrase` - **str**
|
||||
* `.http_version` - `"HTTP/2"` or `"HTTP/1.1"`
|
||||
* `.url` - **URL**
|
||||
* `.headers` - **Headers**
|
||||
* `.content` - **bytes**
|
||||
* `.text` - **str**
|
||||
* `.encoding` - **str**
|
||||
* `.is_redirect` - **bool**
|
||||
* `.request` - **Request**
|
||||
* `.next_request` - **Optional[Request]**
|
||||
* `.cookies` - **Cookies**
|
||||
* `.history` - **List[Response]**
|
||||
* `.elapsed` - **[timedelta](https://docs.python.org/3/library/datetime.html)**
|
||||
* The amount of time elapsed between sending the request and calling `close()` on the corresponding response received for that request.
|
||||
[total_seconds()](https://docs.python.org/3/library/datetime.html#datetime.timedelta.total_seconds) to correctly get
|
||||
the total elapsed seconds.
|
||||
* `def .raise_for_status()` - **Response**
|
||||
* `def .json()` - **Any**
|
||||
* `def .read()` - **bytes**
|
||||
* `def .iter_raw([chunk_size])` - **bytes iterator**
|
||||
* `def .iter_bytes([chunk_size])` - **bytes iterator**
|
||||
* `def .iter_text([chunk_size])` - **text iterator**
|
||||
* `def .iter_lines()` - **text iterator**
|
||||
* `def .close()` - **None**
|
||||
* `def .next()` - **Response**
|
||||
* `def .aread()` - **bytes**
|
||||
* `def .aiter_raw([chunk_size])` - **async bytes iterator**
|
||||
* `def .aiter_bytes([chunk_size])` - **async bytes iterator**
|
||||
* `def .aiter_text([chunk_size])` - **async text iterator**
|
||||
* `def .aiter_lines()` - **async text iterator**
|
||||
* `def .aclose()` - **None**
|
||||
* `def .anext()` - **Response**
|
||||
|
||||
## `Request`
|
||||
|
||||
*An HTTP request. Can be constructed explicitly for more control over exactly
|
||||
what gets sent over the wire.*
|
||||
|
||||
```pycon
|
||||
>>> request = httpx.Request("GET", "https://example.org", headers={'host': 'example.org'})
|
||||
>>> response = client.send(request)
|
||||
```
|
||||
|
||||
* `def __init__(method, url, [params], [headers], [cookies], [content], [data], [files], [json], [stream])`
|
||||
* `.method` - **str**
|
||||
* `.url` - **URL**
|
||||
* `.content` - **byte**, **byte iterator**, or **byte async iterator**
|
||||
* `.headers` - **Headers**
|
||||
* `.cookies` - **Cookies**
|
||||
|
||||
## `URL`
|
||||
|
||||
*A normalized, IDNA supporting URL.*
|
||||
|
||||
```pycon
|
||||
>>> url = URL("https://example.org/")
|
||||
>>> url.host
|
||||
'example.org'
|
||||
```
|
||||
|
||||
* `def __init__(url, **kwargs)`
|
||||
* `.scheme` - **str**
|
||||
* `.authority` - **str**
|
||||
* `.host` - **str**
|
||||
* `.port` - **int**
|
||||
* `.path` - **str**
|
||||
* `.query` - **str**
|
||||
* `.raw_path` - **str**
|
||||
* `.fragment` - **str**
|
||||
* `.is_ssl` - **bool**
|
||||
* `.is_absolute_url` - **bool**
|
||||
* `.is_relative_url` - **bool**
|
||||
* `def .copy_with([scheme], [authority], [path], [query], [fragment])` - **URL**
|
||||
|
||||
## `Headers`
|
||||
|
||||
*A case-insensitive multi-dict.*
|
||||
|
||||
```pycon
|
||||
>>> headers = Headers({'Content-Type': 'application/json'})
|
||||
>>> headers['content-type']
|
||||
'application/json'
|
||||
```
|
||||
|
||||
* `def __init__(self, headers, encoding=None)`
|
||||
* `def copy()` - **Headers**
|
||||
|
||||
## `Cookies`
|
||||
|
||||
*A dict-like cookie store.*
|
||||
|
||||
```pycon
|
||||
>>> cookies = Cookies()
|
||||
>>> cookies.set("name", "value", domain="example.org")
|
||||
```
|
||||
|
||||
* `def __init__(cookies: [dict, Cookies, CookieJar])`
|
||||
* `.jar` - **CookieJar**
|
||||
* `def extract_cookies(response)`
|
||||
* `def set_cookie_header(request)`
|
||||
* `def set(name, value, [domain], [path])`
|
||||
* `def get(name, [domain], [path])`
|
||||
* `def delete(name, [domain], [path])`
|
||||
* `def clear([domain], [path])`
|
||||
* *Standard mutable mapping interface*
|
||||
|
||||
## `Proxy`
|
||||
|
||||
*A configuration of the proxy server.*
|
||||
|
||||
```pycon
|
||||
>>> proxy = Proxy("http://proxy.example.com:8030")
|
||||
>>> client = Client(proxy=proxy)
|
||||
```
|
||||
|
||||
* `def __init__(url, [ssl_context], [auth], [headers])`
|
||||
* `.url` - **URL**
|
||||
* `.auth` - **tuple[str, str]**
|
||||
* `.headers` - **Headers**
|
||||
* `.ssl_context` - **SSLContext**
|
||||
194
docs/async.md
194
docs/async.md
@ -1,194 +0,0 @@
|
||||
# Async Support
|
||||
|
||||
HTTPX offers a standard synchronous API by default, but also gives you
|
||||
the option of an async client if you need it.
|
||||
|
||||
Async is a concurrency model that is far more efficient than multi-threading,
|
||||
and can provide significant performance benefits and enable the use of
|
||||
long-lived network connections such as WebSockets.
|
||||
|
||||
If you're working with an async web framework then you'll also want to use an
|
||||
async client for sending outgoing HTTP requests.
|
||||
|
||||
## Making Async requests
|
||||
|
||||
To make asynchronous requests, you'll need an `AsyncClient`.
|
||||
|
||||
```pycon
|
||||
>>> async with httpx.AsyncClient() as client:
|
||||
... r = await client.get('https://www.example.com/')
|
||||
...
|
||||
>>> r
|
||||
<Response [200 OK]>
|
||||
```
|
||||
|
||||
!!! tip
|
||||
Use [IPython](https://ipython.readthedocs.io/en/stable/) or Python 3.9+ with `python -m asyncio` to try this code interactively, as they support executing `async`/`await` expressions in the console.
|
||||
|
||||
## API Differences
|
||||
|
||||
If you're using an async client then there are a few bits of API that
|
||||
use async methods.
|
||||
|
||||
### Making requests
|
||||
|
||||
The request methods are all async, so you should use `response = await client.get(...)` style for all of the following:
|
||||
|
||||
* `AsyncClient.get(url, ...)`
|
||||
* `AsyncClient.options(url, ...)`
|
||||
* `AsyncClient.head(url, ...)`
|
||||
* `AsyncClient.post(url, ...)`
|
||||
* `AsyncClient.put(url, ...)`
|
||||
* `AsyncClient.patch(url, ...)`
|
||||
* `AsyncClient.delete(url, ...)`
|
||||
* `AsyncClient.request(method, url, ...)`
|
||||
* `AsyncClient.send(request, ...)`
|
||||
|
||||
### Opening and closing clients
|
||||
|
||||
Use `async with httpx.AsyncClient()` if you want a context-managed client...
|
||||
|
||||
```python
|
||||
async with httpx.AsyncClient() as client:
|
||||
...
|
||||
```
|
||||
|
||||
!!! warning
|
||||
In order to get the most benefit from connection pooling, make sure you're not instantiating multiple client instances - for example by using `async with` inside a "hot loop". This can be achieved either by having a single scoped client that's passed throughout wherever it's needed, or by having a single global client instance.
|
||||
|
||||
Alternatively, use `await client.aclose()` if you want to close a client explicitly:
|
||||
|
||||
```python
|
||||
client = httpx.AsyncClient()
|
||||
...
|
||||
await client.aclose()
|
||||
```
|
||||
|
||||
### Streaming responses
|
||||
|
||||
The `AsyncClient.stream(method, url, ...)` method is an async context block.
|
||||
|
||||
```pycon
|
||||
>>> client = httpx.AsyncClient()
|
||||
>>> async with client.stream('GET', 'https://www.example.com/') as response:
|
||||
... async for chunk in response.aiter_bytes():
|
||||
... ...
|
||||
```
|
||||
|
||||
The async response streaming methods are:
|
||||
|
||||
* `Response.aread()` - For conditionally reading a response inside a stream block.
|
||||
* `Response.aiter_bytes()` - For streaming the response content as bytes.
|
||||
* `Response.aiter_text()` - For streaming the response content as text.
|
||||
* `Response.aiter_lines()` - For streaming the response content as lines of text.
|
||||
* `Response.aiter_raw()` - For streaming the raw response bytes, without applying content decoding.
|
||||
* `Response.aclose()` - For closing the response. You don't usually need this, since `.stream` block closes the response automatically on exit.
|
||||
|
||||
For situations when context block usage is not practical, it is possible to enter "manual mode" by sending a [`Request` instance](advanced/clients.md#request-instances) using `client.send(..., stream=True)`.
|
||||
|
||||
Example in the context of forwarding the response to a streaming web endpoint with [Starlette](https://www.starlette.io):
|
||||
|
||||
```python
|
||||
import httpx
|
||||
from starlette.background import BackgroundTask
|
||||
from starlette.responses import StreamingResponse
|
||||
|
||||
client = httpx.AsyncClient()
|
||||
|
||||
async def home(request):
|
||||
req = client.build_request("GET", "https://www.example.com/")
|
||||
r = await client.send(req, stream=True)
|
||||
return StreamingResponse(r.aiter_text(), background=BackgroundTask(r.aclose))
|
||||
```
|
||||
|
||||
!!! warning
|
||||
When using this "manual streaming mode", it is your duty as a developer to make sure that `Response.aclose()` is called eventually. Failing to do so would leave connections open, most likely resulting in resource leaks down the line.
|
||||
|
||||
### Streaming requests
|
||||
|
||||
When sending a streaming request body with an `AsyncClient` instance, you should use an async bytes generator instead of a bytes generator:
|
||||
|
||||
```python
|
||||
async def upload_bytes():
|
||||
... # yield byte content
|
||||
|
||||
await client.post(url, content=upload_bytes())
|
||||
```
|
||||
|
||||
### Explicit transport instances
|
||||
|
||||
When instantiating a transport instance directly, you need to use `httpx.AsyncHTTPTransport`.
|
||||
|
||||
For instance:
|
||||
|
||||
```pycon
|
||||
>>> import httpx
|
||||
>>> transport = httpx.AsyncHTTPTransport(retries=1)
|
||||
>>> async with httpx.AsyncClient(transport=transport) as client:
|
||||
>>> ...
|
||||
```
|
||||
|
||||
## Supported async environments
|
||||
|
||||
HTTPX supports either `asyncio` or `trio` as an async environment.
|
||||
|
||||
It will auto-detect which of those two to use as the backend
|
||||
for socket operations and concurrency primitives.
|
||||
|
||||
### [AsyncIO](https://docs.python.org/3/library/asyncio.html)
|
||||
|
||||
AsyncIO is Python's [built-in library](https://docs.python.org/3/library/asyncio.html)
|
||||
for writing concurrent code with the async/await syntax.
|
||||
|
||||
```python
|
||||
import asyncio
|
||||
import httpx
|
||||
|
||||
async def main():
|
||||
async with httpx.AsyncClient() as client:
|
||||
response = await client.get('https://www.example.com/')
|
||||
print(response)
|
||||
|
||||
asyncio.run(main())
|
||||
```
|
||||
|
||||
### [Trio](https://github.com/python-trio/trio)
|
||||
|
||||
Trio is [an alternative async library](https://trio.readthedocs.io/en/stable/),
|
||||
designed around the [the principles of structured concurrency](https://en.wikipedia.org/wiki/Structured_concurrency).
|
||||
|
||||
```python
|
||||
import httpx
|
||||
import trio
|
||||
|
||||
async def main():
|
||||
async with httpx.AsyncClient() as client:
|
||||
response = await client.get('https://www.example.com/')
|
||||
print(response)
|
||||
|
||||
trio.run(main)
|
||||
```
|
||||
|
||||
!!! important
|
||||
The `trio` package must be installed to use the Trio backend.
|
||||
|
||||
|
||||
### [AnyIO](https://github.com/agronholm/anyio)
|
||||
|
||||
AnyIO is an [asynchronous networking and concurrency library](https://anyio.readthedocs.io/) that works on top of either `asyncio` or `trio`. It blends in with native libraries of your chosen backend (defaults to `asyncio`).
|
||||
|
||||
```python
|
||||
import httpx
|
||||
import anyio
|
||||
|
||||
async def main():
|
||||
async with httpx.AsyncClient() as client:
|
||||
response = await client.get('https://www.example.com/')
|
||||
print(response)
|
||||
|
||||
anyio.run(main, backend='trio')
|
||||
```
|
||||
|
||||
## Calling into Python Web Apps
|
||||
|
||||
For details on calling directly into ASGI applications, see [the `ASGITransport` docs](../advanced/transports#asgitransport).
|
||||
@ -1,56 +0,0 @@
|
||||
# Code of Conduct
|
||||
|
||||
We expect contributors to our projects and online spaces to follow [the Python Software Foundation’s Code of Conduct](https://www.python.org/psf/conduct/).
|
||||
|
||||
The Python community is made up of members from around the globe with a diverse set of skills, personalities, and experiences. It is through these differences that our community experiences great successes and continued growth. When you're working with members of the community, this Code of Conduct will help steer your interactions and keep Python a positive, successful, and growing community.
|
||||
|
||||
## Our Community
|
||||
|
||||
Members of the Python community are **open, considerate, and respectful**. Behaviours that reinforce these values contribute to a positive environment, and include:
|
||||
|
||||
* **Being open.** Members of the community are open to collaboration, whether it's on PEPs, patches, problems, or otherwise.
|
||||
* **Focusing on what is best for the community.** We're respectful of the processes set forth in the community, and we work within them.
|
||||
* **Acknowledging time and effort.** We're respectful of the volunteer efforts that permeate the Python community. We're thoughtful when addressing the efforts of others, keeping in mind that often times the labor was completed simply for the good of the community.
|
||||
* **Being respectful of differing viewpoints and experiences.** We're receptive to constructive comments and criticism, as the experiences and skill sets of other members contribute to the whole of our efforts.
|
||||
* **Showing empathy towards other community members.** We're attentive in our communications, whether in person or online, and we're tactful when approaching differing views.
|
||||
* **Being considerate.** Members of the community are considerate of their peers -- other Python users.
|
||||
* **Being respectful.** We're respectful of others, their positions, their skills, their commitments, and their efforts.
|
||||
* **Gracefully accepting constructive criticism.** When we disagree, we are courteous in raising our issues.
|
||||
* **Using welcoming and inclusive language.** We're accepting of all who wish to take part in our activities, fostering an environment where anyone can participate and everyone can make a difference.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Every member of our community has the right to have their identity respected. The Python community is dedicated to providing a positive experience for everyone, regardless of age, gender identity and expression, sexual orientation, disability, physical appearance, body size, ethnicity, nationality, race, or religion (or lack thereof), education, or socio-economic status.
|
||||
|
||||
## Inappropriate Behavior
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* Harassment of any participants in any form
|
||||
* Deliberate intimidation, stalking, or following
|
||||
* Logging or taking screenshots of online activity for harassment purposes
|
||||
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
||||
* Violent threats or language directed against another person
|
||||
* Incitement of violence or harassment towards any individual, including encouraging a person to commit suicide or to engage in self-harm
|
||||
* Creating additional online accounts in order to harass another person or circumvent a ban
|
||||
* Sexual language and imagery in online communities or in any conference venue, including talks
|
||||
* Insults, put downs, or jokes that are based upon stereotypes, that are exclusionary, or that hold others up for ridicule
|
||||
* Excessive swearing
|
||||
* Unwelcome sexual attention or advances
|
||||
* Unwelcome physical contact, including simulated physical contact (eg, textual descriptions like "hug" or "backrub") without consent or after a request to stop
|
||||
* Pattern of inappropriate social contact, such as requesting/assuming inappropriate levels of intimacy with others
|
||||
* Sustained disruption of online community discussions, in-person presentations, or other in-person events
|
||||
* Continued one-on-one communication after requests to cease
|
||||
* Other conduct that is inappropriate for a professional audience including people of many different backgrounds
|
||||
|
||||
Community members asked to stop any inappropriate behavior are expected to comply immediately.
|
||||
|
||||
## Enforcement
|
||||
|
||||
We take Code of Conduct violations seriously, and will act to ensure our spaces are welcoming, inclusive, and professional environments to communicate in.
|
||||
|
||||
If you need to raise a Code of Conduct report, you may do so privately by email to tom@tomchristie.com.
|
||||
|
||||
Reports will be treated confidentially.
|
||||
|
||||
Alternately you may [make a report to the Python Software Foundation](https://www.python.org/psf/conduct/reporting/).
|
||||
@ -1,232 +0,0 @@
|
||||
# Requests Compatibility Guide
|
||||
|
||||
HTTPX aims to be broadly compatible with the `requests` API, although there are a
|
||||
few design differences in places.
|
||||
|
||||
This documentation outlines places where the API differs...
|
||||
|
||||
## Redirects
|
||||
|
||||
Unlike `requests`, HTTPX does **not follow redirects by default**.
|
||||
|
||||
We differ in behaviour here [because auto-redirects can easily mask unnecessary network
|
||||
calls being made](https://github.com/encode/httpx/discussions/1785).
|
||||
|
||||
You can still enable behaviour to automatically follow redirects, but you need to
|
||||
do so explicitly...
|
||||
|
||||
```python
|
||||
response = client.get(url, follow_redirects=True)
|
||||
```
|
||||
|
||||
Or else instantiate a client, with redirect following enabled by default...
|
||||
|
||||
```python
|
||||
client = httpx.Client(follow_redirects=True)
|
||||
```
|
||||
|
||||
## Client instances
|
||||
|
||||
The HTTPX equivalent of `requests.Session` is `httpx.Client`.
|
||||
|
||||
```python
|
||||
session = requests.Session(**kwargs)
|
||||
```
|
||||
|
||||
is generally equivalent to
|
||||
|
||||
```python
|
||||
client = httpx.Client(**kwargs)
|
||||
```
|
||||
|
||||
## Request URLs
|
||||
|
||||
Accessing `response.url` will return a `URL` instance, rather than a string.
|
||||
|
||||
Use `str(response.url)` if you need a string instance.
|
||||
|
||||
## Determining the next redirect request
|
||||
|
||||
The `requests` library exposes an attribute `response.next`, which can be used to obtain the next redirect request.
|
||||
|
||||
```python
|
||||
session = requests.Session()
|
||||
request = requests.Request("GET", ...).prepare()
|
||||
while request is not None:
|
||||
response = session.send(request, allow_redirects=False)
|
||||
request = response.next
|
||||
```
|
||||
|
||||
In HTTPX, this attribute is instead named `response.next_request`. For example:
|
||||
|
||||
```python
|
||||
client = httpx.Client()
|
||||
request = client.build_request("GET", ...)
|
||||
while request is not None:
|
||||
response = client.send(request)
|
||||
request = response.next_request
|
||||
```
|
||||
|
||||
## Request Content
|
||||
|
||||
For uploading raw text or binary content we prefer to use a `content` parameter,
|
||||
in order to better separate this usage from the case of uploading form data.
|
||||
|
||||
For example, using `content=...` to upload raw content:
|
||||
|
||||
```python
|
||||
# Uploading text, bytes, or a bytes iterator.
|
||||
httpx.post(..., content=b"Hello, world")
|
||||
```
|
||||
|
||||
And using `data=...` to send form data:
|
||||
|
||||
```python
|
||||
# Uploading form data.
|
||||
httpx.post(..., data={"message": "Hello, world"})
|
||||
```
|
||||
|
||||
Using the `data=<text/byte content>` will raise a deprecation warning,
|
||||
and is expected to be fully removed with the HTTPX 1.0 release.
|
||||
|
||||
## Upload files
|
||||
|
||||
HTTPX strictly enforces that upload files must be opened in binary mode, in order
|
||||
to avoid character encoding issues that can result from attempting to upload files
|
||||
opened in text mode.
|
||||
|
||||
## Content encoding
|
||||
|
||||
HTTPX uses `utf-8` for encoding `str` request bodies. For example, when using `content=<str>` the request body will be encoded to `utf-8` before being sent over the wire. This differs from Requests which uses `latin1`. If you need an explicit encoding, pass encoded bytes explicitly, e.g. `content=<str>.encode("latin1")`.
|
||||
For response bodies, assuming the server didn't send an explicit encoding then HTTPX will do its best to figure out an appropriate encoding. HTTPX makes a guess at the encoding to use for decoding the response using `charset_normalizer`. Fallback to that or any content with less than 32 octets will be decoded using `utf-8` with the `error="replace"` decoder strategy.
|
||||
|
||||
## Cookies
|
||||
|
||||
If using a client instance, then cookies should always be set on the client rather than on a per-request basis.
|
||||
|
||||
This usage is supported:
|
||||
|
||||
```python
|
||||
client = httpx.Client(cookies=...)
|
||||
client.post(...)
|
||||
```
|
||||
|
||||
This usage is **not** supported:
|
||||
|
||||
```python
|
||||
client = httpx.Client()
|
||||
client.post(..., cookies=...)
|
||||
```
|
||||
|
||||
We prefer enforcing a stricter API here because it provides clearer expectations around cookie persistence, particularly when redirects occur.
|
||||
|
||||
## Status Codes
|
||||
|
||||
In our documentation we prefer the uppercased versions, such as `codes.NOT_FOUND`, but also provide lower-cased versions for API compatibility with `requests`.
|
||||
|
||||
Requests includes various synonyms for status codes that HTTPX does not support.
|
||||
|
||||
## Streaming responses
|
||||
|
||||
HTTPX provides a `.stream()` interface rather than using `stream=True`. This ensures that streaming responses are always properly closed outside of the stream block, and makes it visually clearer at which points streaming I/O APIs may be used with a response.
|
||||
|
||||
For example:
|
||||
|
||||
```python
|
||||
with httpx.stream("GET", "https://www.example.com") as response:
|
||||
...
|
||||
```
|
||||
|
||||
Within a `stream()` block request data is made available with:
|
||||
|
||||
* `.iter_bytes()` - Instead of `response.iter_content()`
|
||||
* `.iter_text()` - Instead of `response.iter_content(decode_unicode=True)`
|
||||
* `.iter_lines()` - Corresponding to `response.iter_lines()`
|
||||
* `.iter_raw()` - Use this instead of `response.raw`
|
||||
* `.read()` - Read the entire response body, making `response.text` and `response.content` available.
|
||||
|
||||
## Timeouts
|
||||
|
||||
HTTPX defaults to including reasonable [timeouts](quickstart.md#timeouts) for all network operations, while Requests has no timeouts by default.
|
||||
|
||||
To get the same behavior as Requests, set the `timeout` parameter to `None`:
|
||||
|
||||
```python
|
||||
httpx.get('https://www.example.com', timeout=None)
|
||||
```
|
||||
|
||||
## Proxy keys
|
||||
|
||||
HTTPX uses the mounts argument for HTTP proxying and transport routing.
|
||||
It can do much more than proxies and allows you to configure more than just the proxy route.
|
||||
For more detailed documentation, see [Mounting Transports](advanced/transports.md#mounting-transports).
|
||||
|
||||
When using `httpx.Client(mounts={...})` to map to a selection of different transports, we use full URL schemes, such as `mounts={"http://": ..., "https://": ...}`.
|
||||
|
||||
This is different to the `requests` usage of `proxies={"http": ..., "https": ...}`.
|
||||
|
||||
This change is for better consistency with more complex mappings, that might also include domain names, such as `mounts={"all://": ..., httpx.HTTPTransport(proxy="all://www.example.com": None})` which maps all requests onto a proxy, except for requests to "www.example.com" which have an explicit exclusion.
|
||||
|
||||
Also note that `requests.Session.request(...)` allows a `proxies=...` parameter, whereas `httpx.Client.request(...)` does not allow `mounts=...`.
|
||||
|
||||
## SSL configuration
|
||||
|
||||
When using a `Client` instance, the ssl configurations should always be passed on client instantiation, rather than passed to the request method.
|
||||
|
||||
If you need more than one different SSL configuration, you should use different client instances for each SSL configuration.
|
||||
|
||||
## Request body on HTTP methods
|
||||
|
||||
The HTTP `GET`, `DELETE`, `HEAD`, and `OPTIONS` methods are specified as not supporting a request body. To stay in line with this, the `.get`, `.delete`, `.head` and `.options` functions do not support `content`, `files`, `data`, or `json` arguments.
|
||||
|
||||
If you really do need to send request data using these http methods you should use the generic `.request` function instead.
|
||||
|
||||
```python
|
||||
httpx.request(
|
||||
method="DELETE",
|
||||
url="https://www.example.com/",
|
||||
content=b'A request body on a DELETE request.'
|
||||
)
|
||||
```
|
||||
|
||||
## Checking for success and failure responses
|
||||
|
||||
We don't support `response.is_ok` since the naming is ambiguous there, and might incorrectly imply an equivalence to `response.status_code == codes.OK`. Instead we provide the `response.is_success` property, which can be used to check for a 2xx response.
|
||||
|
||||
## Request instantiation
|
||||
|
||||
There is no notion of [prepared requests](https://requests.readthedocs.io/en/stable/user/advanced/#prepared-requests) in HTTPX. If you need to customize request instantiation, see [Request instances](advanced/clients.md#request-instances).
|
||||
|
||||
Besides, `httpx.Request()` does not support the `auth`, `timeout`, `follow_redirects`, `mounts`, `verify` and `cert` parameters. However these are available in `httpx.request`, `httpx.get`, `httpx.post` etc., as well as on [`Client` instances](advanced/clients.md#client-instances).
|
||||
|
||||
## Mocking
|
||||
|
||||
If you need to mock HTTPX the same way that test utilities like `responses` and `requests-mock` does for `requests`, see [RESPX](https://github.com/lundberg/respx).
|
||||
|
||||
## Caching
|
||||
|
||||
If you use `cachecontrol` or `requests-cache` to add HTTP Caching support to the `requests` library, you can use [Hishel](https://hishel.com) for HTTPX.
|
||||
|
||||
## Networking layer
|
||||
|
||||
`requests` defers most of its HTTP networking code to the excellent [`urllib3` library](https://urllib3.readthedocs.io/en/latest/).
|
||||
|
||||
On the other hand, HTTPX uses [HTTPCore](https://github.com/encode/httpcore) as its core HTTP networking layer, which is a different project than `urllib3`.
|
||||
|
||||
## Query Parameters
|
||||
|
||||
`requests` omits `params` whose values are `None` (e.g. `requests.get(..., params={"foo": None})`). This is not supported by HTTPX.
|
||||
|
||||
For both query params (`params=`) and form data (`data=`), `requests` supports sending a list of tuples (e.g. `requests.get(..., params=[('key1', 'value1'), ('key1', 'value2')])`). This is not supported by HTTPX. Instead, use a dictionary with lists as values. E.g.: `httpx.get(..., params={'key1': ['value1', 'value2']})` or with form data: `httpx.post(..., data={'key1': ['value1', 'value2']})`.
|
||||
|
||||
## Event Hooks
|
||||
|
||||
`requests` allows event hooks to mutate `Request` and `Response` objects. See [examples](https://requests.readthedocs.io/en/master/user/advanced/#event-hooks) given in the documentation for `requests`.
|
||||
|
||||
In HTTPX, event hooks may access properties of requests and responses, but event hook callbacks cannot mutate the original request/response.
|
||||
|
||||
If you are looking for more control, consider checking out [Custom Transports](advanced/transports.md#custom-transports).
|
||||
|
||||
## Exceptions and Errors
|
||||
|
||||
`requests` exception hierarchy is slightly different to the `httpx` exception hierarchy. `requests` exposes a top level `RequestException`, where as `httpx` exposes a top level `HTTPError`. see the exceptions exposes in requests [here](https://requests.readthedocs.io/en/latest/_modules/requests/exceptions/). See the `httpx` error hierarchy [here](https://www.python-httpx.org/exceptions/).
|
||||
@ -1,232 +0,0 @@
|
||||
# Contributing
|
||||
|
||||
Thank you for being interested in contributing to HTTPX.
|
||||
There are many ways you can contribute to 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 behaviour?
|
||||
|
||||
Contributions should generally start out with [a discussion](https://github.com/encode/httpx/discussions).
|
||||
Possible bugs may be raised as a "Potential Issue" discussion, feature requests may
|
||||
be raised as an "Ideas" discussion. We can then determine if the discussion needs
|
||||
to be escalated into an "Issue" or not, or if we'd consider a pull request.
|
||||
|
||||
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
|
||||
|
||||
You should always try to reduce any examples to the *simplest possible case*
|
||||
that demonstrates the issue.
|
||||
|
||||
Some possibly useful tips for narrowing down potential issues...
|
||||
|
||||
- Does the issue exist on HTTP/1.1, or HTTP/2, or both?
|
||||
- Does the issue exist with `Client`, `AsyncClient`, or both?
|
||||
- When using `AsyncClient` does the issue exist when using `asyncio` or `trio`, or both?
|
||||
|
||||
## 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
|
||||
```
|
||||
|
||||
You can now install the project and its dependencies using:
|
||||
|
||||
```shell
|
||||
$ cd httpx
|
||||
$ scripts/install
|
||||
```
|
||||
|
||||
## Testing and Linting
|
||||
|
||||
We use custom shell scripts to automate testing, linting,
|
||||
and documentation building workflow.
|
||||
|
||||
To run the tests, use:
|
||||
|
||||
```shell
|
||||
$ scripts/test
|
||||
```
|
||||
|
||||
!!! warning
|
||||
The test suite spawns testing servers on ports **8000** and **8001**.
|
||||
Make sure these are not in use, so the tests can run properly.
|
||||
|
||||
Any additional arguments will be passed to `pytest`. See the [pytest documentation](https://docs.pytest.org/en/latest/how-to/usage.html) for more information.
|
||||
|
||||
For example, to run a single test script:
|
||||
|
||||
```shell
|
||||
$ scripts/test tests/test_multipart.py
|
||||
```
|
||||
|
||||
To run the code auto-formatting:
|
||||
|
||||
```shell
|
||||
$ scripts/lint
|
||||
```
|
||||
|
||||
Lastly, to run code checks separately (they are also run as part of `scripts/test`), run:
|
||||
|
||||
```shell
|
||||
$ scripts/check
|
||||
```
|
||||
|
||||
## Documenting
|
||||
|
||||
Documentation pages are located under the `docs/` folder.
|
||||
|
||||
To run the documentation site locally (useful for previewing changes), use:
|
||||
|
||||
```shell
|
||||
$ scripts/docs
|
||||
```
|
||||
|
||||
## Resolving Build / CI Failures
|
||||
|
||||
Once you've submitted your pull request, the test suite will automatically run, and the results will show up in GitHub.
|
||||
If the test suite fails, you'll want to click through to the "Details" link, and try to identify why the test suite failed.
|
||||
|
||||
<p align="center" style="margin: 0 0 10px">
|
||||
<img src="https://raw.githubusercontent.com/encode/httpx/master/docs/img/gh-actions-fail.png" alt='Failing PR commit status'>
|
||||
</p>
|
||||
|
||||
Here are some common ways the test suite can fail:
|
||||
|
||||
### Check Job Failed
|
||||
|
||||
<p align="center" style="margin: 0 0 10px">
|
||||
<img src="https://raw.githubusercontent.com/encode/httpx/master/docs/img/gh-actions-fail-check.png" alt='Failing GitHub action lint job'>
|
||||
</p>
|
||||
|
||||
This job failing means there is either a code formatting issue or type-annotation issue.
|
||||
You can look at the job output to figure out why it's failed or within a shell run:
|
||||
|
||||
```shell
|
||||
$ scripts/check
|
||||
```
|
||||
|
||||
It may be worth it to run `$ scripts/lint` to attempt auto-formatting the code
|
||||
and if that job succeeds commit the changes.
|
||||
|
||||
### Docs Job Failed
|
||||
|
||||
This job failing means the documentation failed to build. This can happen for
|
||||
a variety of reasons like invalid markdown or missing configuration within `mkdocs.yml`.
|
||||
|
||||
### Python 3.X Job Failed
|
||||
|
||||
<p align="center" style="margin: 0 0 10px">
|
||||
<img src="https://raw.githubusercontent.com/encode/httpx/master/docs/img/gh-actions-fail-test.png" alt='Failing GitHub action test job'>
|
||||
</p>
|
||||
|
||||
This job failing means the unit tests failed or not all code paths are covered by unit tests.
|
||||
|
||||
If tests are failing you will see this message under the coverage report:
|
||||
|
||||
`=== 1 failed, 435 passed, 1 skipped, 1 xfailed in 11.09s ===`
|
||||
|
||||
If tests succeed but coverage doesn't reach our current threshold, you will see this
|
||||
message under the coverage report:
|
||||
|
||||
`FAIL Required test coverage of 100% not reached. Total coverage: 99.00%`
|
||||
|
||||
## Releasing
|
||||
|
||||
*This section is targeted at HTTPX maintainers.*
|
||||
|
||||
Before releasing a new version, create a pull request that includes:
|
||||
|
||||
- **An update to the changelog**:
|
||||
- We follow the format from [keepachangelog](https://keepachangelog.com/en/1.0.0/).
|
||||
- [Compare](https://github.com/encode/httpx/compare/) `master` with the tag of the latest release, and list all entries that are of interest to our users:
|
||||
- Things that **must** go in the changelog: added, changed, deprecated or removed features, and bug fixes.
|
||||
- Things that **should not** go in the changelog: changes to documentation, tests or tooling.
|
||||
- Try sorting entries in descending order of impact / importance.
|
||||
- Keep it concise and to-the-point. 🎯
|
||||
- **A version bump**: see `__version__.py`.
|
||||
|
||||
For an example, see [#1006](https://github.com/encode/httpx/pull/1006).
|
||||
|
||||
Once the release PR is merged, create a
|
||||
[new release](https://github.com/encode/httpx/releases/new) including:
|
||||
|
||||
- Tag version like `0.13.3`.
|
||||
- Release title `Version 0.13.3`
|
||||
- Description copied from the changelog.
|
||||
|
||||
Once created this release will be automatically uploaded to PyPI.
|
||||
|
||||
If something goes wrong with the PyPI job the release can be published using the
|
||||
`scripts/publish` script.
|
||||
|
||||
## Development proxy setup
|
||||
|
||||
To test and debug requests via a proxy it's best to run a proxy server locally.
|
||||
Any server should do but HTTPCore's test suite uses
|
||||
[`mitmproxy`](https://mitmproxy.org/) which is written in Python, it's fully
|
||||
featured and has excellent UI and tools for introspection of requests.
|
||||
|
||||
You can install `mitmproxy` using `pip install mitmproxy` or [several
|
||||
other ways](https://docs.mitmproxy.org/stable/overview-installation/).
|
||||
|
||||
`mitmproxy` does require setting up local TLS certificates for HTTPS requests,
|
||||
as its main purpose is to allow developers to inspect requests that pass through
|
||||
it. We can set them up follows:
|
||||
|
||||
1. [`pip install trustme-cli`](https://github.com/sethmlarson/trustme-cli/).
|
||||
2. `trustme-cli -i example.org www.example.org`, assuming you want to test
|
||||
connecting to that domain, this will create three files: `server.pem`,
|
||||
`server.key` and `client.pem`.
|
||||
3. `mitmproxy` requires a PEM file that includes the private key and the
|
||||
certificate so we need to concatenate them:
|
||||
`cat server.key server.pem > server.withkey.pem`.
|
||||
4. Start the proxy server `mitmproxy --certs server.withkey.pem`, or use the
|
||||
[other mitmproxy commands](https://docs.mitmproxy.org/stable/) with different
|
||||
UI options.
|
||||
|
||||
At this point the server is ready to start serving requests, you'll need to
|
||||
configure HTTPX as described in the
|
||||
[proxy section](https://www.python-httpx.org/advanced/proxies/#http-proxies) and
|
||||
the [SSL certificates section](https://www.python-httpx.org/advanced/ssl/),
|
||||
this is where our previously generated `client.pem` comes in:
|
||||
|
||||
```python
|
||||
ctx = ssl.create_default_context(cafile="/path/to/client.pem")
|
||||
client = httpx.Client(proxy="http://127.0.0.1:8080/", verify=ctx)
|
||||
```
|
||||
|
||||
Note, however, that HTTPS requests will only succeed to the host specified
|
||||
in the SSL/TLS certificate we generated, HTTPS requests to other hosts will
|
||||
raise an error like:
|
||||
|
||||
```
|
||||
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate
|
||||
verify failed: Hostname mismatch, certificate is not valid for
|
||||
'duckduckgo.com'. (_ssl.c:1108)
|
||||
```
|
||||
|
||||
If you want to make requests to more hosts you'll need to regenerate the
|
||||
certificates and include all the hosts you intend to connect to in the
|
||||
seconds step, i.e.
|
||||
|
||||
`trustme-cli -i example.org www.example.org duckduckgo.com www.duckduckgo.com`
|
||||
@ -1,79 +0,0 @@
|
||||
# Environment Variables
|
||||
|
||||
The HTTPX library can be configured via environment variables.
|
||||
Environment variables are used by default. To ignore environment variables, `trust_env` has to be set `False`. There are two ways to set `trust_env` to disable environment variables:
|
||||
|
||||
* On the client via `httpx.Client(trust_env=False)`.
|
||||
* Using the top-level API, such as `httpx.get("<url>", trust_env=False)`.
|
||||
|
||||
Here is a list of environment variables that HTTPX recognizes and what function they serve:
|
||||
|
||||
## Proxies
|
||||
|
||||
The environment variables documented below are used as a convention by various HTTP tooling, including:
|
||||
|
||||
* [cURL](https://github.com/curl/curl/blob/master/docs/MANUAL.md#environment-variables)
|
||||
* [requests](https://github.com/psf/requests/blob/master/docs/user/advanced.rst#proxies)
|
||||
|
||||
For more information on using proxies in HTTPX, see [HTTP Proxying](advanced/proxies.md#http-proxying).
|
||||
|
||||
### `HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY`
|
||||
|
||||
Valid values: A URL to a proxy
|
||||
|
||||
`HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY` set the proxy to be used for `http`, `https`, or all requests respectively.
|
||||
|
||||
```bash
|
||||
export HTTP_PROXY=http://my-external-proxy.com:1234
|
||||
|
||||
# This request will be sent through the proxy
|
||||
python -c "import httpx; httpx.get('http://example.com')"
|
||||
|
||||
# This request will be sent directly, as we set `trust_env=False`
|
||||
python -c "import httpx; httpx.get('http://example.com', trust_env=False)"
|
||||
|
||||
```
|
||||
|
||||
### `NO_PROXY`
|
||||
|
||||
Valid values: a comma-separated list of hostnames/urls
|
||||
|
||||
`NO_PROXY` disables the proxy for specific urls
|
||||
|
||||
```bash
|
||||
export HTTP_PROXY=http://my-external-proxy.com:1234
|
||||
export NO_PROXY=http://127.0.0.1,python-httpx.org
|
||||
|
||||
# As in the previous example, this request will be sent through the proxy
|
||||
python -c "import httpx; httpx.get('http://example.com')"
|
||||
|
||||
# These requests will be sent directly, bypassing the proxy
|
||||
python -c "import httpx; httpx.get('http://127.0.0.1:5000/my-api')"
|
||||
python -c "import httpx; httpx.get('https://www.python-httpx.org')"
|
||||
```
|
||||
|
||||
## `SSL_CERT_FILE`
|
||||
|
||||
Valid values: a filename
|
||||
|
||||
If this environment variable is set then HTTPX will load
|
||||
CA certificate from the specified file instead of the default
|
||||
location.
|
||||
|
||||
Example:
|
||||
|
||||
```console
|
||||
SSL_CERT_FILE=/path/to/ca-certs/ca-bundle.crt python -c "import httpx; httpx.get('https://example.com')"
|
||||
```
|
||||
|
||||
## `SSL_CERT_DIR`
|
||||
|
||||
Valid values: a directory following an [OpenSSL specific layout](https://www.openssl.org/docs/manmaster/man3/SSL_CTX_load_verify_locations.html).
|
||||
|
||||
If this environment variable is set and the directory follows an [OpenSSL specific layout](https://www.openssl.org/docs/manmaster/man3/SSL_CTX_load_verify_locations.html) (ie. you ran `c_rehash`) then HTTPX will load CA certificates from this directory instead of the default location.
|
||||
|
||||
Example:
|
||||
|
||||
```console
|
||||
SSL_CERT_DIR=/path/to/ca-certs/ python -c "import httpx; httpx.get('https://example.com')"
|
||||
```
|
||||
@ -1,124 +0,0 @@
|
||||
# Exceptions
|
||||
|
||||
This page lists exceptions that may be raised when using HTTPX.
|
||||
|
||||
For an overview of how to work with HTTPX exceptions, see [Exceptions (Quickstart)](quickstart.md#exceptions).
|
||||
|
||||
## The exception hierarchy
|
||||
|
||||
* HTTPError
|
||||
* RequestError
|
||||
* TransportError
|
||||
* TimeoutException
|
||||
* ConnectTimeout
|
||||
* ReadTimeout
|
||||
* WriteTimeout
|
||||
* PoolTimeout
|
||||
* NetworkError
|
||||
* ConnectError
|
||||
* ReadError
|
||||
* WriteError
|
||||
* CloseError
|
||||
* ProtocolError
|
||||
* LocalProtocolError
|
||||
* RemoteProtocolError
|
||||
* ProxyError
|
||||
* UnsupportedProtocol
|
||||
* DecodingError
|
||||
* TooManyRedirects
|
||||
* HTTPStatusError
|
||||
* InvalidURL
|
||||
* CookieConflict
|
||||
* StreamError
|
||||
* StreamConsumed
|
||||
* ResponseNotRead
|
||||
* RequestNotRead
|
||||
* StreamClosed
|
||||
|
||||
---
|
||||
|
||||
## Exception classes
|
||||
|
||||
::: httpx.HTTPError
|
||||
:docstring:
|
||||
|
||||
::: httpx.RequestError
|
||||
:docstring:
|
||||
|
||||
::: httpx.TransportError
|
||||
:docstring:
|
||||
|
||||
::: httpx.TimeoutException
|
||||
:docstring:
|
||||
|
||||
::: httpx.ConnectTimeout
|
||||
:docstring:
|
||||
|
||||
::: httpx.ReadTimeout
|
||||
:docstring:
|
||||
|
||||
::: httpx.WriteTimeout
|
||||
:docstring:
|
||||
|
||||
::: httpx.PoolTimeout
|
||||
:docstring:
|
||||
|
||||
::: httpx.NetworkError
|
||||
:docstring:
|
||||
|
||||
::: httpx.ConnectError
|
||||
:docstring:
|
||||
|
||||
::: httpx.ReadError
|
||||
:docstring:
|
||||
|
||||
::: httpx.WriteError
|
||||
:docstring:
|
||||
|
||||
::: httpx.CloseError
|
||||
:docstring:
|
||||
|
||||
::: httpx.ProtocolError
|
||||
:docstring:
|
||||
|
||||
::: httpx.LocalProtocolError
|
||||
:docstring:
|
||||
|
||||
::: httpx.RemoteProtocolError
|
||||
:docstring:
|
||||
|
||||
::: httpx.ProxyError
|
||||
:docstring:
|
||||
|
||||
::: httpx.UnsupportedProtocol
|
||||
:docstring:
|
||||
|
||||
::: httpx.DecodingError
|
||||
:docstring:
|
||||
|
||||
::: httpx.TooManyRedirects
|
||||
:docstring:
|
||||
|
||||
::: httpx.HTTPStatusError
|
||||
:docstring:
|
||||
|
||||
::: httpx.InvalidURL
|
||||
:docstring:
|
||||
|
||||
::: httpx.CookieConflict
|
||||
:docstring:
|
||||
|
||||
::: httpx.StreamError
|
||||
:docstring:
|
||||
|
||||
::: httpx.StreamConsumed
|
||||
:docstring:
|
||||
|
||||
::: httpx.StreamClosed
|
||||
:docstring:
|
||||
|
||||
::: httpx.ResponseNotRead
|
||||
:docstring:
|
||||
|
||||
::: httpx.RequestNotRead
|
||||
:docstring:
|
||||
@ -1,68 +0,0 @@
|
||||
# HTTP/2
|
||||
|
||||
HTTP/2 is a major new iteration of the HTTP protocol, that provides a far more
|
||||
efficient transport, with potential performance benefits. HTTP/2 does not change
|
||||
the core semantics of the request or response, but alters the way that data is
|
||||
sent to and from the server.
|
||||
|
||||
Rather than the text format that HTTP/1.1 uses, HTTP/2 is a binary format.
|
||||
The binary format provides full request and response multiplexing, and efficient
|
||||
compression of HTTP headers. The stream multiplexing means that where HTTP/1.1
|
||||
requires one TCP stream for each concurrent request, HTTP/2 allows a single TCP
|
||||
stream to handle multiple concurrent requests.
|
||||
|
||||
HTTP/2 also provides support for functionality such as response prioritization,
|
||||
and server push.
|
||||
|
||||
For a comprehensive guide to HTTP/2 you may want to check out "[http2 explained](https://http2-explained.haxx.se/)".
|
||||
|
||||
## Enabling HTTP/2
|
||||
|
||||
When using the `httpx` client, HTTP/2 support is not enabled by default, because
|
||||
HTTP/1.1 is a mature, battle-hardened transport layer, and our HTTP/1.1
|
||||
implementation may be considered the more robust option at this point in time.
|
||||
It is possible that a future version of `httpx` may enable HTTP/2 support by default.
|
||||
|
||||
If you're issuing highly concurrent requests you might want to consider
|
||||
trying out our HTTP/2 support. You can do so by first making sure to install
|
||||
the optional HTTP/2 dependencies...
|
||||
|
||||
```shell
|
||||
$ pip install httpx[http2]
|
||||
```
|
||||
|
||||
And then instantiating a client with HTTP/2 support enabled:
|
||||
|
||||
```python
|
||||
client = httpx.AsyncClient(http2=True)
|
||||
...
|
||||
```
|
||||
|
||||
You can also instantiate a client as a context manager, to ensure that all
|
||||
HTTP connections are nicely scoped, and will be closed once the context block
|
||||
is exited.
|
||||
|
||||
```python
|
||||
async with httpx.AsyncClient(http2=True) as client:
|
||||
...
|
||||
```
|
||||
|
||||
HTTP/2 support is available on both `Client` and `AsyncClient`, although it's
|
||||
typically more useful in async contexts if you're issuing lots of concurrent
|
||||
requests.
|
||||
|
||||
## Inspecting the HTTP version
|
||||
|
||||
Enabling HTTP/2 support on the client does not *necessarily* mean that your
|
||||
requests and responses will be transported over HTTP/2, since both the client
|
||||
*and* the server need to support HTTP/2. If you connect to a server that only
|
||||
supports HTTP/1.1 the client will use a standard HTTP/1.1 connection instead.
|
||||
|
||||
You can determine which version of the HTTP protocol was used by examining
|
||||
the `.http_version` property on the response.
|
||||
|
||||
```python
|
||||
client = httpx.AsyncClient(http2=True)
|
||||
response = await client.get(...)
|
||||
print(response.http_version) # "HTTP/1.0", "HTTP/1.1", or "HTTP/2".
|
||||
```
|
||||
150
docs/index.md
150
docs/index.md
@ -1,150 +0,0 @@
|
||||
<p align="center" style="margin: 0 0 10px">
|
||||
<img width="350" height="208" src="https://raw.githubusercontent.com/encode/httpx/master/docs/img/butterfly.png" alt='HTTPX'>
|
||||
</p>
|
||||
|
||||
<h1 align="center" style="font-size: 3rem; margin: -15px 0">
|
||||
HTTPX
|
||||
</h1>
|
||||
|
||||
---
|
||||
|
||||
<div align="center">
|
||||
<p>
|
||||
<a href="https://github.com/encode/httpx/actions">
|
||||
<img src="https://github.com/encode/httpx/workflows/Test%20Suite/badge.svg" alt="Test Suite">
|
||||
</a>
|
||||
<a href="https://pypi.org/project/httpx/">
|
||||
<img src="https://badge.fury.io/py/httpx.svg" alt="Package version">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<em>A next-generation HTTP client for Python.</em>
|
||||
</div>
|
||||
|
||||
HTTPX is a fully featured HTTP client for Python 3, which provides sync and async APIs, and support for both HTTP/1.1 and HTTP/2.
|
||||
|
||||
---
|
||||
|
||||
Install HTTPX using pip:
|
||||
|
||||
```shell
|
||||
$ pip install httpx
|
||||
```
|
||||
|
||||
Now, let's get started:
|
||||
|
||||
```pycon
|
||||
>>> import httpx
|
||||
>>> r = httpx.get('https://www.example.org/')
|
||||
>>> r
|
||||
<Response [200 OK]>
|
||||
>>> r.status_code
|
||||
200
|
||||
>>> r.headers['content-type']
|
||||
'text/html; charset=UTF-8'
|
||||
>>> r.text
|
||||
'<!doctype html>\n<html>\n<head>\n<title>Example Domain</title>...'
|
||||
```
|
||||
|
||||
Or, using the command-line client.
|
||||
|
||||
```shell
|
||||
# The command line client is an optional dependency.
|
||||
$ pip install 'httpx[cli]'
|
||||
```
|
||||
|
||||
Which now allows us to use HTTPX directly from the command-line...
|
||||
|
||||

|
||||
|
||||
Sending a request...
|
||||
|
||||

|
||||
|
||||
## Features
|
||||
|
||||
HTTPX builds on the well-established usability of `requests`, and gives you:
|
||||
|
||||
* A broadly [requests-compatible API](compatibility.md).
|
||||
* Standard synchronous interface, but with [async support if you need it](async.md).
|
||||
* HTTP/1.1 [and HTTP/2 support](http2.md).
|
||||
* Ability to make requests directly to [WSGI applications](advanced/transports.md#wsgi-transport) or [ASGI applications](advanced/transports.md#asgi-transport).
|
||||
* Strict timeouts everywhere.
|
||||
* Fully type annotated.
|
||||
* 100% test coverage.
|
||||
|
||||
Plus all the standard features of `requests`...
|
||||
|
||||
* International Domains and URLs
|
||||
* Keep-Alive & Connection Pooling
|
||||
* Sessions with Cookie Persistence
|
||||
* Browser-style SSL Verification
|
||||
* Basic/Digest Authentication
|
||||
* Elegant Key/Value Cookies
|
||||
* Automatic Decompression
|
||||
* Automatic Content Decoding
|
||||
* Unicode Response Bodies
|
||||
* Multipart File Uploads
|
||||
* HTTP(S) Proxy Support
|
||||
* Connection Timeouts
|
||||
* Streaming Downloads
|
||||
* .netrc Support
|
||||
* Chunked Requests
|
||||
|
||||
## Documentation
|
||||
|
||||
For a run-through of all the basics, head over to the [QuickStart](quickstart.md).
|
||||
|
||||
For more advanced topics, see the **Advanced** section,
|
||||
the [async support](async.md) section, or the [HTTP/2](http2.md) section.
|
||||
|
||||
The [Developer Interface](api.md) provides a comprehensive API reference.
|
||||
|
||||
To find out about tools that integrate with HTTPX, see [Third Party Packages](third_party_packages.md).
|
||||
|
||||
## Dependencies
|
||||
|
||||
The HTTPX project relies on these excellent libraries:
|
||||
|
||||
* `httpcore` - The underlying transport implementation for `httpx`.
|
||||
* `h11` - HTTP/1.1 support.
|
||||
* `certifi` - SSL certificates.
|
||||
* `idna` - Internationalized domain name support.
|
||||
* `sniffio` - Async library autodetection.
|
||||
|
||||
As well as these optional installs:
|
||||
|
||||
* `h2` - HTTP/2 support. *(Optional, with `httpx[http2]`)*
|
||||
* `socksio` - SOCKS proxy support. *(Optional, with `httpx[socks]`)*
|
||||
* `rich` - Rich terminal support. *(Optional, with `httpx[cli]`)*
|
||||
* `click` - Command line client support. *(Optional, with `httpx[cli]`)*
|
||||
* `brotli` or `brotlicffi` - Decoding for "brotli" compressed responses. *(Optional, with `httpx[brotli]`)*
|
||||
* `zstandard` - Decoding for "zstd" compressed responses. *(Optional, with `httpx[zstd]`)*
|
||||
|
||||
A huge amount of credit is due to `requests` for the API layout that
|
||||
much of this work follows, as well as to `urllib3` for plenty of design
|
||||
inspiration around the lower-level networking details.
|
||||
|
||||
## Installation
|
||||
|
||||
Install with pip:
|
||||
|
||||
```shell
|
||||
$ pip install httpx
|
||||
```
|
||||
|
||||
Or, to include the optional HTTP/2 support, use:
|
||||
|
||||
```shell
|
||||
$ pip install httpx[http2]
|
||||
```
|
||||
|
||||
To include the optional brotli and zstandard decoders support, use:
|
||||
|
||||
```shell
|
||||
$ pip install httpx[brotli,zstd]
|
||||
```
|
||||
|
||||
HTTPX requires Python 3.9+
|
||||
|
||||
[sync-support]: https://github.com/encode/httpx/issues/572
|
||||
@ -1,81 +0,0 @@
|
||||
# Logging
|
||||
|
||||
If you need to inspect the internal behaviour of `httpx`, you can use Python's standard logging to output information about the underlying network behaviour.
|
||||
|
||||
For example, the following configuration...
|
||||
|
||||
```python
|
||||
import logging
|
||||
import httpx
|
||||
|
||||
logging.basicConfig(
|
||||
format="%(levelname)s [%(asctime)s] %(name)s - %(message)s",
|
||||
datefmt="%Y-%m-%d %H:%M:%S",
|
||||
level=logging.DEBUG
|
||||
)
|
||||
|
||||
httpx.get("https://www.example.com")
|
||||
```
|
||||
|
||||
Will send debug level output to the console, or wherever `stdout` is directed too...
|
||||
|
||||
```
|
||||
DEBUG [2024-09-28 17:27:40] httpcore.connection - connect_tcp.started host='www.example.com' port=443 local_address=None timeout=5.0 socket_options=None
|
||||
DEBUG [2024-09-28 17:27:41] httpcore.connection - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x101f1e8e0>
|
||||
DEBUG [2024-09-28 17:27:41] httpcore.connection - start_tls.started ssl_context=SSLContext(verify=True) server_hostname='www.example.com' timeout=5.0
|
||||
DEBUG [2024-09-28 17:27:41] httpcore.connection - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x1020f49a0>
|
||||
DEBUG [2024-09-28 17:27:41] httpcore.http11 - send_request_headers.started request=<Request [b'GET']>
|
||||
DEBUG [2024-09-28 17:27:41] httpcore.http11 - send_request_headers.complete
|
||||
DEBUG [2024-09-28 17:27:41] httpcore.http11 - send_request_body.started request=<Request [b'GET']>
|
||||
DEBUG [2024-09-28 17:27:41] httpcore.http11 - send_request_body.complete
|
||||
DEBUG [2024-09-28 17:27:41] httpcore.http11 - receive_response_headers.started request=<Request [b'GET']>
|
||||
DEBUG [2024-09-28 17:27:41] httpcore.http11 - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Content-Encoding', b'gzip'), (b'Accept-Ranges', b'bytes'), (b'Age', b'407727'), (b'Cache-Control', b'max-age=604800'), (b'Content-Type', b'text/html; charset=UTF-8'), (b'Date', b'Sat, 28 Sep 2024 13:27:42 GMT'), (b'Etag', b'"3147526947+gzip"'), (b'Expires', b'Sat, 05 Oct 2024 13:27:42 GMT'), (b'Last-Modified', b'Thu, 17 Oct 2019 07:18:26 GMT'), (b'Server', b'ECAcc (dcd/7D43)'), (b'Vary', b'Accept-Encoding'), (b'X-Cache', b'HIT'), (b'Content-Length', b'648')])
|
||||
INFO [2024-09-28 17:27:41] httpx - HTTP Request: GET https://www.example.com "HTTP/1.1 200 OK"
|
||||
DEBUG [2024-09-28 17:27:41] httpcore.http11 - receive_response_body.started request=<Request [b'GET']>
|
||||
DEBUG [2024-09-28 17:27:41] httpcore.http11 - receive_response_body.complete
|
||||
DEBUG [2024-09-28 17:27:41] httpcore.http11 - response_closed.started
|
||||
DEBUG [2024-09-28 17:27:41] httpcore.http11 - response_closed.complete
|
||||
DEBUG [2024-09-28 17:27:41] httpcore.connection - close.started
|
||||
DEBUG [2024-09-28 17:27:41] httpcore.connection - close.complete
|
||||
```
|
||||
|
||||
Logging output includes information from both the high-level `httpx` logger, and the network-level `httpcore` logger, which can be configured separately.
|
||||
|
||||
For handling more complex logging configurations you might want to use the dictionary configuration style...
|
||||
|
||||
```python
|
||||
import logging.config
|
||||
import httpx
|
||||
|
||||
LOGGING_CONFIG = {
|
||||
"version": 1,
|
||||
"handlers": {
|
||||
"default": {
|
||||
"class": "logging.StreamHandler",
|
||||
"formatter": "http",
|
||||
"stream": "ext://sys.stderr"
|
||||
}
|
||||
},
|
||||
"formatters": {
|
||||
"http": {
|
||||
"format": "%(levelname)s [%(asctime)s] %(name)s - %(message)s",
|
||||
"datefmt": "%Y-%m-%d %H:%M:%S",
|
||||
}
|
||||
},
|
||||
'loggers': {
|
||||
'httpx': {
|
||||
'handlers': ['default'],
|
||||
'level': 'DEBUG',
|
||||
},
|
||||
'httpcore': {
|
||||
'handlers': ['default'],
|
||||
'level': 'DEBUG',
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
logging.config.dictConfig(LOGGING_CONFIG)
|
||||
httpx.get('https://www.example.com')
|
||||
```
|
||||
|
||||
The exact formatting of the debug logging may be subject to change across different versions of `httpx` and `httpcore`. If you need to rely on a particular format it is recommended that you pin installation of these packages to fixed versions.
|
||||
@ -1,547 +0,0 @@
|
||||
# QuickStart
|
||||
|
||||
First, start by importing HTTPX:
|
||||
|
||||
```pycon
|
||||
>>> import httpx
|
||||
```
|
||||
|
||||
Now, let’s try to get a webpage.
|
||||
|
||||
```pycon
|
||||
>>> r = httpx.get('https://httpbin.org/get')
|
||||
>>> r
|
||||
<Response [200 OK]>
|
||||
```
|
||||
|
||||
Similarly, to make an HTTP POST request:
|
||||
|
||||
```pycon
|
||||
>>> r = httpx.post('https://httpbin.org/post', data={'key': 'value'})
|
||||
```
|
||||
|
||||
The PUT, DELETE, HEAD, and OPTIONS requests all follow the same style:
|
||||
|
||||
```pycon
|
||||
>>> r = httpx.put('https://httpbin.org/put', data={'key': 'value'})
|
||||
>>> r = httpx.delete('https://httpbin.org/delete')
|
||||
>>> r = httpx.head('https://httpbin.org/get')
|
||||
>>> r = httpx.options('https://httpbin.org/get')
|
||||
```
|
||||
|
||||
## Passing Parameters in URLs
|
||||
|
||||
To include URL query parameters in the request, use the `params` keyword:
|
||||
|
||||
```pycon
|
||||
>>> params = {'key1': 'value1', 'key2': 'value2'}
|
||||
>>> r = httpx.get('https://httpbin.org/get', params=params)
|
||||
```
|
||||
|
||||
To see how the values get encoding into the URL string, we can inspect the
|
||||
resulting URL that was used to make the request:
|
||||
|
||||
```pycon
|
||||
>>> r.url
|
||||
URL('https://httpbin.org/get?key2=value2&key1=value1')
|
||||
```
|
||||
|
||||
You can also pass a list of items as a value:
|
||||
|
||||
```pycon
|
||||
>>> params = {'key1': 'value1', 'key2': ['value2', 'value3']}
|
||||
>>> r = httpx.get('https://httpbin.org/get', params=params)
|
||||
>>> r.url
|
||||
URL('https://httpbin.org/get?key1=value1&key2=value2&key2=value3')
|
||||
```
|
||||
|
||||
## Response Content
|
||||
|
||||
HTTPX will automatically handle decoding the response content into Unicode text.
|
||||
|
||||
```pycon
|
||||
>>> r = httpx.get('https://www.example.org/')
|
||||
>>> r.text
|
||||
'<!doctype html>\n<html>\n<head>\n<title>Example Domain</title>...'
|
||||
```
|
||||
|
||||
You can inspect what encoding will be used to decode the response.
|
||||
|
||||
```pycon
|
||||
>>> r.encoding
|
||||
'UTF-8'
|
||||
```
|
||||
|
||||
In some cases the response may not contain an explicit encoding, in which case HTTPX
|
||||
will attempt to automatically determine an encoding to use.
|
||||
|
||||
```pycon
|
||||
>>> r.encoding
|
||||
None
|
||||
>>> r.text
|
||||
'<!doctype html>\n<html>\n<head>\n<title>Example Domain</title>...'
|
||||
```
|
||||
|
||||
If you need to override the standard behaviour and explicitly set the encoding to
|
||||
use, then you can do that too.
|
||||
|
||||
```pycon
|
||||
>>> r.encoding = 'ISO-8859-1'
|
||||
```
|
||||
|
||||
## Binary Response Content
|
||||
|
||||
The response content can also be accessed as bytes, for non-text responses:
|
||||
|
||||
```pycon
|
||||
>>> r.content
|
||||
b'<!doctype html>\n<html>\n<head>\n<title>Example Domain</title>...'
|
||||
```
|
||||
|
||||
Any `gzip` and `deflate` HTTP response encodings will automatically
|
||||
be decoded for you. If `brotlipy` is installed, then the `brotli` response
|
||||
encoding will be supported. If `zstandard` is installed, then `zstd`
|
||||
response encodings will also be supported.
|
||||
|
||||
For example, to create an image from binary data returned by a request, you can use the following code:
|
||||
|
||||
```pycon
|
||||
>>> from PIL import Image
|
||||
>>> from io import BytesIO
|
||||
>>> i = Image.open(BytesIO(r.content))
|
||||
```
|
||||
|
||||
## JSON Response Content
|
||||
|
||||
Often Web API responses will be encoded as JSON.
|
||||
|
||||
```pycon
|
||||
>>> r = httpx.get('https://api.github.com/events')
|
||||
>>> r.json()
|
||||
[{u'repository': {u'open_issues': 0, u'url': 'https://github.com/...' ... }}]
|
||||
```
|
||||
|
||||
## Custom Headers
|
||||
|
||||
To include additional headers in the outgoing request, use the `headers` keyword argument:
|
||||
|
||||
```pycon
|
||||
>>> url = 'https://httpbin.org/headers'
|
||||
>>> headers = {'user-agent': 'my-app/0.0.1'}
|
||||
>>> r = httpx.get(url, headers=headers)
|
||||
```
|
||||
|
||||
## Sending Form Encoded Data
|
||||
|
||||
Some types of HTTP requests, such as `POST` and `PUT` requests, can include data
|
||||
in the request body. One common way of including that is as form-encoded data,
|
||||
which is used for HTML forms.
|
||||
|
||||
```pycon
|
||||
>>> data = {'key1': 'value1', 'key2': 'value2'}
|
||||
>>> r = httpx.post("https://httpbin.org/post", data=data)
|
||||
>>> print(r.text)
|
||||
{
|
||||
...
|
||||
"form": {
|
||||
"key2": "value2",
|
||||
"key1": "value1"
|
||||
},
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
Form encoded data can also include multiple values from a given key.
|
||||
|
||||
```pycon
|
||||
>>> data = {'key1': ['value1', 'value2']}
|
||||
>>> r = httpx.post("https://httpbin.org/post", data=data)
|
||||
>>> print(r.text)
|
||||
{
|
||||
...
|
||||
"form": {
|
||||
"key1": [
|
||||
"value1",
|
||||
"value2"
|
||||
]
|
||||
},
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
## Sending Multipart File Uploads
|
||||
|
||||
You can also upload files, using HTTP multipart encoding:
|
||||
|
||||
```pycon
|
||||
>>> with open('report.xls', 'rb') as report_file:
|
||||
... files = {'upload-file': report_file}
|
||||
... r = httpx.post("https://httpbin.org/post", files=files)
|
||||
>>> print(r.text)
|
||||
{
|
||||
...
|
||||
"files": {
|
||||
"upload-file": "<... binary content ...>"
|
||||
},
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
You can also explicitly set the filename and content type, by using a tuple
|
||||
of items for the file value:
|
||||
|
||||
```pycon
|
||||
>>> with open('report.xls', 'rb') as report_file:
|
||||
... files = {'upload-file': ('report.xls', report_file, 'application/vnd.ms-excel')}
|
||||
... r = httpx.post("https://httpbin.org/post", files=files)
|
||||
>>> print(r.text)
|
||||
{
|
||||
...
|
||||
"files": {
|
||||
"upload-file": "<... binary content ...>"
|
||||
},
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
If you need to include non-file data fields in the multipart form, use the `data=...` parameter:
|
||||
|
||||
```pycon
|
||||
>>> data = {'message': 'Hello, world!'}
|
||||
>>> with open('report.xls', 'rb') as report_file:
|
||||
... files = {'file': report_file}
|
||||
... r = httpx.post("https://httpbin.org/post", data=data, files=files)
|
||||
>>> print(r.text)
|
||||
{
|
||||
...
|
||||
"files": {
|
||||
"file": "<... binary content ...>"
|
||||
},
|
||||
"form": {
|
||||
"message": "Hello, world!",
|
||||
},
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
## Sending JSON Encoded Data
|
||||
|
||||
Form encoded data is okay if all you need is a simple key-value data structure.
|
||||
For more complicated data structures you'll often want to use JSON encoding instead.
|
||||
|
||||
```pycon
|
||||
>>> data = {'integer': 123, 'boolean': True, 'list': ['a', 'b', 'c']}
|
||||
>>> r = httpx.post("https://httpbin.org/post", json=data)
|
||||
>>> print(r.text)
|
||||
{
|
||||
...
|
||||
"json": {
|
||||
"boolean": true,
|
||||
"integer": 123,
|
||||
"list": [
|
||||
"a",
|
||||
"b",
|
||||
"c"
|
||||
]
|
||||
},
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
## Sending Binary Request Data
|
||||
|
||||
For other encodings, you should use the `content=...` parameter, passing
|
||||
either a `bytes` type or a generator that yields `bytes`.
|
||||
|
||||
```pycon
|
||||
>>> content = b'Hello, world'
|
||||
>>> r = httpx.post("https://httpbin.org/post", content=content)
|
||||
```
|
||||
|
||||
You may also want to set a custom `Content-Type` header when uploading
|
||||
binary data.
|
||||
|
||||
## Response Status Codes
|
||||
|
||||
We can inspect the HTTP status code of the response:
|
||||
|
||||
```pycon
|
||||
>>> r = httpx.get('https://httpbin.org/get')
|
||||
>>> r.status_code
|
||||
200
|
||||
```
|
||||
|
||||
HTTPX also includes an easy shortcut for accessing status codes by their text phrase.
|
||||
|
||||
```pycon
|
||||
>>> r.status_code == httpx.codes.OK
|
||||
True
|
||||
```
|
||||
|
||||
We can raise an exception for any responses which are not a 2xx success code:
|
||||
|
||||
```pycon
|
||||
>>> not_found = httpx.get('https://httpbin.org/status/404')
|
||||
>>> not_found.status_code
|
||||
404
|
||||
>>> not_found.raise_for_status()
|
||||
Traceback (most recent call last):
|
||||
File "/Users/tomchristie/GitHub/encode/httpcore/httpx/models.py", line 837, in raise_for_status
|
||||
raise HTTPStatusError(message, response=self)
|
||||
httpx._exceptions.HTTPStatusError: 404 Client Error: Not Found for url: https://httpbin.org/status/404
|
||||
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/404
|
||||
```
|
||||
|
||||
Any successful response codes will return the `Response` instance rather than raising an exception.
|
||||
|
||||
```pycon
|
||||
>>> r.raise_for_status()
|
||||
```
|
||||
|
||||
The method returns the response instance, allowing you to use it inline. For example:
|
||||
|
||||
```pycon
|
||||
>>> r = httpx.get('...').raise_for_status()
|
||||
>>> data = httpx.get('...').raise_for_status().json()
|
||||
```
|
||||
|
||||
## Response Headers
|
||||
|
||||
The response headers are available as a dictionary-like interface.
|
||||
|
||||
```pycon
|
||||
>>> r.headers
|
||||
Headers({
|
||||
'content-encoding': 'gzip',
|
||||
'transfer-encoding': 'chunked',
|
||||
'connection': 'close',
|
||||
'server': 'nginx/1.0.4',
|
||||
'x-runtime': '148ms',
|
||||
'etag': '"e1ca502697e5c9317743dc078f67693f"',
|
||||
'content-type': 'application/json'
|
||||
})
|
||||
```
|
||||
|
||||
The `Headers` data type is case-insensitive, so you can use any capitalization.
|
||||
|
||||
```pycon
|
||||
>>> r.headers['Content-Type']
|
||||
'application/json'
|
||||
|
||||
>>> r.headers.get('content-type')
|
||||
'application/json'
|
||||
```
|
||||
|
||||
Multiple values for a single response header are represented as a single comma-separated value, as per [RFC 7230](https://tools.ietf.org/html/rfc7230#section-3.2):
|
||||
|
||||
> A recipient MAY combine multiple header fields with the same field name into one “field-name: field-value” pair, without changing the semantics of the message, by appending each subsequent field-value to the combined field value in order, separated by a comma.
|
||||
|
||||
## Streaming Responses
|
||||
|
||||
For large downloads you may want to use streaming responses that do not load the entire response body into memory at once.
|
||||
|
||||
You can stream the binary content of the response...
|
||||
|
||||
```pycon
|
||||
>>> with httpx.stream("GET", "https://www.example.com") as r:
|
||||
... for data in r.iter_bytes():
|
||||
... print(data)
|
||||
```
|
||||
|
||||
Or the text of the response...
|
||||
|
||||
```pycon
|
||||
>>> with httpx.stream("GET", "https://www.example.com") as r:
|
||||
... for text in r.iter_text():
|
||||
... print(text)
|
||||
```
|
||||
|
||||
Or stream the text, on a line-by-line basis...
|
||||
|
||||
```pycon
|
||||
>>> with httpx.stream("GET", "https://www.example.com") as r:
|
||||
... for line in r.iter_lines():
|
||||
... print(line)
|
||||
```
|
||||
|
||||
HTTPX will use universal line endings, normalising all cases to `\n`.
|
||||
|
||||
In some cases you might want to access the raw bytes on the response without applying any HTTP content decoding. In this case any content encoding that the web server has applied such as `gzip`, `deflate`, `brotli`, or `zstd` will
|
||||
not be automatically decoded.
|
||||
|
||||
```pycon
|
||||
>>> with httpx.stream("GET", "https://www.example.com") as r:
|
||||
... for chunk in r.iter_raw():
|
||||
... print(chunk)
|
||||
```
|
||||
|
||||
If you're using streaming responses in any of these ways then the `response.content` and `response.text` attributes will not be available, and will raise errors if accessed. However you can also use the response streaming functionality to conditionally load the response body:
|
||||
|
||||
```pycon
|
||||
>>> with httpx.stream("GET", "https://www.example.com") as r:
|
||||
... if int(r.headers['Content-Length']) < TOO_LONG:
|
||||
... r.read()
|
||||
... print(r.text)
|
||||
```
|
||||
|
||||
## Cookies
|
||||
|
||||
Any cookies that are set on the response can be easily accessed:
|
||||
|
||||
```pycon
|
||||
>>> r = httpx.get('https://httpbin.org/cookies/set?chocolate=chip')
|
||||
>>> r.cookies['chocolate']
|
||||
'chip'
|
||||
```
|
||||
|
||||
To include cookies in an outgoing request, use the `cookies` parameter:
|
||||
|
||||
```pycon
|
||||
>>> cookies = {"peanut": "butter"}
|
||||
>>> r = httpx.get('https://httpbin.org/cookies', cookies=cookies)
|
||||
>>> r.json()
|
||||
{'cookies': {'peanut': 'butter'}}
|
||||
```
|
||||
|
||||
Cookies are returned in a `Cookies` instance, which is a dict-like data structure
|
||||
with additional API for accessing cookies by their domain or path.
|
||||
|
||||
```pycon
|
||||
>>> cookies = httpx.Cookies()
|
||||
>>> cookies.set('cookie_on_domain', 'hello, there!', domain='httpbin.org')
|
||||
>>> cookies.set('cookie_off_domain', 'nope.', domain='example.org')
|
||||
>>> r = httpx.get('http://httpbin.org/cookies', cookies=cookies)
|
||||
>>> r.json()
|
||||
{'cookies': {'cookie_on_domain': 'hello, there!'}}
|
||||
```
|
||||
|
||||
## Redirection and History
|
||||
|
||||
By default, HTTPX will **not** follow redirects for all HTTP methods, although
|
||||
this can be explicitly enabled.
|
||||
|
||||
For example, GitHub redirects all HTTP requests to HTTPS.
|
||||
|
||||
```pycon
|
||||
>>> r = httpx.get('http://github.com/')
|
||||
>>> r.status_code
|
||||
301
|
||||
>>> r.history
|
||||
[]
|
||||
>>> r.next_request
|
||||
<Request('GET', 'https://github.com/')>
|
||||
```
|
||||
|
||||
You can modify the default redirection handling with the `follow_redirects` parameter:
|
||||
|
||||
```pycon
|
||||
>>> r = httpx.get('http://github.com/', follow_redirects=True)
|
||||
>>> r.url
|
||||
URL('https://github.com/')
|
||||
>>> r.status_code
|
||||
200
|
||||
>>> r.history
|
||||
[<Response [301 Moved Permanently]>]
|
||||
```
|
||||
|
||||
The `history` property of the response can be used to inspect any followed redirects.
|
||||
It contains a list of any redirect responses that were followed, in the order
|
||||
in which they were made.
|
||||
|
||||
## Timeouts
|
||||
|
||||
HTTPX defaults to including reasonable timeouts for all network operations,
|
||||
meaning that if a connection is not properly established then it should always
|
||||
raise an error rather than hanging indefinitely.
|
||||
|
||||
The default timeout for network inactivity is five seconds. You can modify the
|
||||
value to be more or less strict:
|
||||
|
||||
```pycon
|
||||
>>> httpx.get('https://github.com/', timeout=0.001)
|
||||
```
|
||||
|
||||
You can also disable the timeout behavior completely...
|
||||
|
||||
```pycon
|
||||
>>> httpx.get('https://github.com/', timeout=None)
|
||||
```
|
||||
|
||||
For advanced timeout management, see [Timeout fine-tuning](advanced/timeouts.md#fine-tuning-the-configuration).
|
||||
|
||||
## Authentication
|
||||
|
||||
HTTPX supports Basic and Digest HTTP authentication.
|
||||
|
||||
To provide Basic authentication credentials, pass a 2-tuple of
|
||||
plaintext `str` or `bytes` objects as the `auth` argument to the request
|
||||
functions:
|
||||
|
||||
```pycon
|
||||
>>> httpx.get("https://example.com", auth=("my_user", "password123"))
|
||||
```
|
||||
|
||||
To provide credentials for Digest authentication you'll need to instantiate
|
||||
a `DigestAuth` object with the plaintext username and password as arguments.
|
||||
This object can be then passed as the `auth` argument to the request methods
|
||||
as above:
|
||||
|
||||
```pycon
|
||||
>>> auth = httpx.DigestAuth("my_user", "password123")
|
||||
>>> httpx.get("https://example.com", auth=auth)
|
||||
<Response [200 OK]>
|
||||
```
|
||||
|
||||
## Exceptions
|
||||
|
||||
HTTPX will raise exceptions if an error occurs.
|
||||
|
||||
The most important exception classes in HTTPX are `RequestError` and `HTTPStatusError`.
|
||||
|
||||
The `RequestError` class is a superclass that encompasses any exception that occurs
|
||||
while issuing an HTTP request. These exceptions include a `.request` attribute.
|
||||
|
||||
```python
|
||||
try:
|
||||
response = httpx.get("https://www.example.com/")
|
||||
except httpx.RequestError as exc:
|
||||
print(f"An error occurred while requesting {exc.request.url!r}.")
|
||||
```
|
||||
|
||||
The `HTTPStatusError` class is raised by `response.raise_for_status()` on responses which are not a 2xx success code.
|
||||
These exceptions include both a `.request` and a `.response` attribute.
|
||||
|
||||
```python
|
||||
response = httpx.get("https://www.example.com/")
|
||||
try:
|
||||
response.raise_for_status()
|
||||
except httpx.HTTPStatusError as exc:
|
||||
print(f"Error response {exc.response.status_code} while requesting {exc.request.url!r}.")
|
||||
```
|
||||
|
||||
There is also a base class `HTTPError` that includes both of these categories, and can be used
|
||||
to catch either failed requests, or 4xx and 5xx responses.
|
||||
|
||||
You can either use this base class to catch both categories...
|
||||
|
||||
```python
|
||||
try:
|
||||
response = httpx.get("https://www.example.com/")
|
||||
response.raise_for_status()
|
||||
except httpx.HTTPError as exc:
|
||||
print(f"Error while requesting {exc.request.url!r}.")
|
||||
```
|
||||
|
||||
Or handle each case explicitly...
|
||||
|
||||
```python
|
||||
try:
|
||||
response = httpx.get("https://www.example.com/")
|
||||
response.raise_for_status()
|
||||
except httpx.RequestError as exc:
|
||||
print(f"An error occurred while requesting {exc.request.url!r}.")
|
||||
except httpx.HTTPStatusError as exc:
|
||||
print(f"Error response {exc.response.status_code} while requesting {exc.request.url!r}.")
|
||||
```
|
||||
|
||||
For a full list of available exceptions, see [Exceptions (API Reference)](exceptions.md).
|
||||
@ -1,107 +0,0 @@
|
||||
# Third Party Packages
|
||||
|
||||
As HTTPX usage grows, there is an expanding community of developers building tools and libraries that integrate with HTTPX, or depend on HTTPX. Here are some of them.
|
||||
|
||||
<!-- NOTE: Entries are alphabetised. -->
|
||||
|
||||
## Plugins
|
||||
|
||||
### Hishel
|
||||
|
||||
[GitHub](https://github.com/karpetrosyan/hishel) - [Documentation](https://hishel.com/)
|
||||
|
||||
An elegant HTTP Cache implementation for HTTPX and HTTP Core.
|
||||
|
||||
### HTTPX-Auth
|
||||
|
||||
[GitHub](https://github.com/Colin-b/httpx_auth) - [Documentation](https://colin-b.github.io/httpx_auth/)
|
||||
|
||||
Provides authentication classes to be used with HTTPX's [authentication parameter](advanced/authentication.md#customizing-authentication).
|
||||
|
||||
### httpx-caching
|
||||
|
||||
[Github](https://github.com/johtso/httpx-caching)
|
||||
|
||||
This package adds caching functionality to HTTPX
|
||||
|
||||
### httpx-secure
|
||||
|
||||
[GitHub](https://github.com/Zaczero/httpx-secure)
|
||||
|
||||
Drop-in SSRF protection for httpx with DNS caching and custom validation support.
|
||||
|
||||
### httpx-socks
|
||||
|
||||
[GitHub](https://github.com/romis2012/httpx-socks)
|
||||
|
||||
Proxy (HTTP, SOCKS) transports for httpx.
|
||||
|
||||
### httpx-sse
|
||||
|
||||
[GitHub](https://github.com/florimondmanca/httpx-sse)
|
||||
|
||||
Allows consuming Server-Sent Events (SSE) with HTTPX.
|
||||
|
||||
### httpx-retries
|
||||
|
||||
[GitHub](https://github.com/will-ockmore/httpx-retries) - [Documentation](https://will-ockmore.github.io/httpx-retries/)
|
||||
|
||||
A retry layer for HTTPX.
|
||||
|
||||
### httpx-ws
|
||||
|
||||
[GitHub](https://github.com/frankie567/httpx-ws) - [Documentation](https://frankie567.github.io/httpx-ws/)
|
||||
|
||||
WebSocket support for HTTPX.
|
||||
|
||||
### pytest-HTTPX
|
||||
|
||||
[GitHub](https://github.com/Colin-b/pytest_httpx) - [Documentation](https://colin-b.github.io/pytest_httpx/)
|
||||
|
||||
Provides a [pytest](https://docs.pytest.org/en/latest/) fixture to mock HTTPX within test cases.
|
||||
|
||||
### RESPX
|
||||
|
||||
[GitHub](https://github.com/lundberg/respx) - [Documentation](https://lundberg.github.io/respx/)
|
||||
|
||||
A utility for mocking out HTTPX.
|
||||
|
||||
### rpc.py
|
||||
|
||||
[Github](https://github.com/abersheeran/rpc.py) - [Documentation](https://github.com/abersheeran/rpc.py#rpcpy)
|
||||
|
||||
A fast and powerful RPC framework based on ASGI/WSGI. Use HTTPX as the client of the RPC service.
|
||||
|
||||
## Libraries with HTTPX support
|
||||
|
||||
### Authlib
|
||||
|
||||
[GitHub](https://github.com/lepture/authlib) - [Documentation](https://docs.authlib.org/en/latest/)
|
||||
|
||||
A python library for building OAuth and OpenID Connect clients and servers. Includes an [OAuth HTTPX client](https://docs.authlib.org/en/latest/client/httpx.html).
|
||||
|
||||
### Gidgethub
|
||||
|
||||
[GitHub](https://github.com/brettcannon/gidgethub) - [Documentation](https://gidgethub.readthedocs.io/en/latest/index.html)
|
||||
|
||||
An asynchronous GitHub API library. Includes [HTTPX support](https://gidgethub.readthedocs.io/en/latest/httpx.html).
|
||||
|
||||
### httpdbg
|
||||
|
||||
[GitHub](https://github.com/cle-b/httpdbg) - [Documentation](https://httpdbg.readthedocs.io/)
|
||||
|
||||
A tool for python developers to easily debug the HTTP(S) client requests in a python program.
|
||||
|
||||
### VCR.py
|
||||
|
||||
[GitHub](https://github.com/kevin1024/vcrpy) - [Documentation](https://vcrpy.readthedocs.io/)
|
||||
|
||||
Record and repeat requests.
|
||||
|
||||
## Gists
|
||||
|
||||
### urllib3-transport
|
||||
|
||||
[GitHub](https://gist.github.com/florimondmanca/d56764d78d748eb9f73165da388e546e)
|
||||
|
||||
This public gist provides an example implementation for a [custom transport](advanced/transports.md#custom-transports) implementation on top of the battle-tested [`urllib3`](https://urllib3.readthedocs.io) library.
|
||||
@ -1,63 +0,0 @@
|
||||
# Troubleshooting
|
||||
|
||||
This page lists some common problems or issues you could encounter while developing with HTTPX, as well as possible solutions.
|
||||
|
||||
## Proxies
|
||||
|
||||
---
|
||||
|
||||
### "`The handshake operation timed out`" on HTTPS requests when using a proxy
|
||||
|
||||
**Description**: When using a proxy and making an HTTPS request, you see an exception looking like this:
|
||||
|
||||
```console
|
||||
httpx.ProxyError: _ssl.c:1091: The handshake operation timed out
|
||||
```
|
||||
|
||||
**Similar issues**: [encode/httpx#1412](https://github.com/encode/httpx/issues/1412), [encode/httpx#1433](https://github.com/encode/httpx/issues/1433)
|
||||
|
||||
**Resolution**: it is likely that you've set up your proxies like this...
|
||||
|
||||
```python
|
||||
mounts = {
|
||||
"http://": httpx.HTTPTransport(proxy="http://myproxy.org"),
|
||||
"https://": httpx.HTTPTransport(proxy="https://myproxy.org"),
|
||||
}
|
||||
```
|
||||
|
||||
Using this setup, you're telling HTTPX to connect to the proxy using HTTP for HTTP requests, and using HTTPS for HTTPS requests.
|
||||
|
||||
But if you get the error above, it is likely that your proxy doesn't support connecting via HTTPS. Don't worry: that's a [common gotcha](advanced/proxies.md#http-proxies).
|
||||
|
||||
Change the scheme of your HTTPS proxy to `http://...` instead of `https://...`:
|
||||
|
||||
```python
|
||||
mounts = {
|
||||
"http://": httpx.HTTPTransport(proxy="http://myproxy.org"),
|
||||
"https://": httpx.HTTPTransport(proxy="http://myproxy.org"),
|
||||
}
|
||||
```
|
||||
|
||||
This can be simplified to:
|
||||
|
||||
```python
|
||||
proxy = "http://myproxy.org"
|
||||
with httpx.Client(proxy=proxy) as client:
|
||||
...
|
||||
```
|
||||
|
||||
For more information, see [Proxies: FORWARD vs TUNNEL](advanced/proxies.md#forward-vs-tunnel).
|
||||
|
||||
---
|
||||
|
||||
### Error when making requests to an HTTPS proxy
|
||||
|
||||
**Description**: your proxy _does_ support connecting via HTTPS, but you are seeing errors along the lines of...
|
||||
|
||||
```console
|
||||
httpx.ProxyError: [SSL: PRE_MAC_LENGTH_TOO_LONG] invalid alert (_ssl.c:1091)
|
||||
```
|
||||
|
||||
**Similar issues**: [encode/httpx#1424](https://github.com/encode/httpx/issues/1424).
|
||||
|
||||
**Resolution**: HTTPX does not properly support HTTPS proxies at this time. If that's something you're interested in having, please see [encode/httpx#1434](https://github.com/encode/httpx/issues/1434) and consider lending a hand there.
|
||||
1223
environment_variables/index.html
Normal file
1223
environment_variables/index.html
Normal file
File diff suppressed because it is too large
Load Diff
1285
exceptions/index.html
Normal file
1285
exceptions/index.html
Normal file
File diff suppressed because it is too large
Load Diff
1151
http2/index.html
Normal file
1151
http2/index.html
Normal file
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user