README.md
This file
Path
README.md
249 lines · 7.0 KiB · Markdown
Last changed by
Drop prepare_requestTom Christiebefore adoptiond8950ef
History of this fileTake it
StuffTom Christiebefore adoption30530d4
lines 1–2why, one step back1# HTTPCore2Merge pull request #43 from encode/badgesTom Christiebefore adoption3553625
lines 3–12why, one step back3<a href="https://travis-ci.org/encode/httpcore">4 <img src="https://travis-ci.org/encode/httpcore.svg?branch=master" alt="Build Status">5</a>6<a href="https://codecov.io/gh/encode/httpcore">7 <img src="https://codecov.io/gh/encode/httpcore/branch/master/graph/badge.svg" alt="Coverage">8</a>9<a href="https://pypi.org/project/httpcore/">10 <img src="https://badge.fury.io/py/httpcore.svg" alt="Package version">11</a>12Truckin' onTom Christiebefore adoption6b60d95
line 13why, one step back13## Feature supportUpdate READMETom Christiebefore adoption665743a
line 14why, one step back14Add cookie interfacesTom Christiebefore adoption0717998
line 15why, one step back15* `HTTP/2` and `HTTP/1.1` support.Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
lines 16–17why, one step back16* `async`/`await` support for non-blocking HTTP requests.17* Strict timeouts everywhere by default.Truckin' onTom Christiebefore adoption6b60d95
line 18why, one step back18* Fully type annotated.Update README.mdTom Christiebefore adoption23e0786
line 19why, one step back19* 100% test coverage.Update READMETom Christiebefore adoption665743a
line 20why, one step back20Truckin' onTom Christiebefore adoption6b60d95
line 21why, one step back21Plus all the standard features of requests...Update READMETom Christiebefore adoption665743a
line 22why, one step back22Truckin' onTom Christiebefore adoption6b60d95
lines 23–24why, one step back23* International Domains and URLs24* Keep-Alive & Connection PoolingAdd cookie interfacesTom Christiebefore adoption0717998
line 25why, one step back25* Sessions with Cookie PersistenceTruckin' onTom Christiebefore adoption6b60d95
line 26why, one step back26* Browser-style SSL VerificationUpdate README.mdTom Christiebefore adoption144ce4f
line 27why, one step back27* Basic/Digest Authentication *TODO - We have Basic, but not Digest yet.*Add cookie interfacesTom Christiebefore adoption0717998
line 28why, one step back28* Elegant Key/Value CookiesTruckin' onTom Christiebefore adoption6b60d95
lines 29–31why, one step back29* Automatic Decompression30* Automatic Content Decoding31* Unicode Response BodiesAdd top-level API (#75)Tom Christiebefore adoptionfc627f3
line 32why, one step back32* Multipart File Uploads *TODO - Request content currently supports URL encoded data, JSON, bytes, or async byte iterators.*Truckin' onTom Christiebefore adoption6b60d95
lines 33–35why, one step back33* HTTP(S) Proxy Support *TODO*34* Connection Timeouts35* Streaming DownloadsUpdate READMETom Christiebefore adoption58461d4
line 36why, one step back36* .netrc Support *TODO*Truckin' onTom Christiebefore adoption6b60d95
line 37why, one step back37* Chunked RequestsUpdate READMETom Christiebefore adoption665743a
line 38why, one step back38Update README.mdTom Christiebefore adoption0d3eb0e
line 39why, one step back39## UsageUpdate README.mdTom Christiebefore adoption01a3c09
line 40why, one step back40Update README.mdTom Christiebefore adoption337eb70
lines 41–42why, one step back41Making a request:42StuffTom Christiebefore adoption30530d4
line 43why, one step back43```pythonTruckin' onTom Christiebefore adoption6b60d95
lines 44–45why, one step back44>>> import httpcore45>>> client = httpcore.Client()Update READMETom Christiebefore adoption58461d4
line 46why, one step back46>>> response = client.get('https://example.com')Truckin' onTom Christiebefore adoption6b60d95
line 47why, one step back47>>> response.status_codeMinor README tweakTom Christiebefore adoption813bb7c
line 48why, one step back48<HTTPStatus.OK: 200>Still truckin' onTom Christiebefore adoption6cb5c0d
lines 49–50why, one step back49>>> response.protocol50'HTTP/2'Truckin' onTom Christiebefore adoption6b60d95
lines 51–52why, one step back51>>> response.text52'<!doctype html>\n<html>\n<head>\n<title>Example Domain</title>\n...'StuffTom Christiebefore adoption30530d4
lines 53–54why, one step back53```54Update READMETom Christiebefore adoption58461d4
line 55why, one step back55Alternatively, async requests:StuffTom Christiebefore adoption30530d4
line 56why, one step back56Update READMETom Christiebefore adoption58461d4
lines 57–58why, one step back57**Note**: Use `ipython` to try this from the console, since it supports `await`.58StuffTom Christiebefore adoption30530d4
line 59why, one step back59```pythonTruckin' onTom Christiebefore adoption6b60d95
line 60why, one step back60>>> import httpcoreUpdate READMETom Christiebefore adoption58461d4
lines 61–62why, one step back61>>> client = httpcore.AsyncClient()62>>> response = await client.get('https://example.com')Truckin' onTom Christiebefore adoption6b60d95
line 63why, one step back63>>> response.status_codeUpdate README.mdTom Christiebefore adoptione7cd76e
line 64why, one step back64<StatusCode.OK: 200>Still truckin' onTom Christiebefore adoption6cb5c0d
lines 65–66why, one step back65>>> response.protocol66'HTTP/2'Truckin' onTom Christiebefore adoption6b60d95
lines 67–68why, one step back67>>> response.text68'<!doctype html>\n<html>\n<head>\n<title>Example Domain</title>\n...'StuffTom Christiebefore adoption30530d4
lines 69–70why, one step back69```70Truckin' onTom Christiebefore adoption6b60d95
line 71why, one step back71---StuffTom Christiebefore adoption30530d4
line 72why, one step back72Update READMETom Christiebefore adoption4fe2f69
lines 73–75why, one step back73## Dependencies7475* `h2` - HTTP/2 support.Add cookie interfacesTom Christiebefore adoption0717998
line 76why, one step back76* `h11` - HTTP/1.1 support.Update READMETom Christiebefore adoption4fe2f69
lines 77–82why, one step back77* `certifi` - SSL certificates.78* `chardet` - Fallback auto-detection for response encoding.79* `idna` - Internationalized domain name support.80* `rfc3986` - URL parsing & normalization.81* `brotlipy` - Decoding for "brotli" compressed responses. *(Optional)*82Update READMETom Christiebefore adoption58461d4
line 83why, one step back83A huge amount of credit is due to `requests` for the API layout thatUpdate README.mdTom Christiebefore adoption84b9691
lines 84–85why, one step back84much of this work follows, as well as to `urllib3` for plenty of design85inspiration around the lower level networking details.Update READMETom Christiebefore adoption4fe2f69
lines 86–88why, one step back8687---88Truckin' onTom Christiebefore adoption6b60d95
line 89why, one step back89## API ReferenceUpdate READMETom Christiebefore adoption68b80dc
line 90why, one step back90Reorganise structureTom Christiebefore adoption0c6f618
line 91why, one step back91### `Client`Update READMETom Christiebefore adoption68b80dc
line 92why, one step back92Update READMETom Christiebefore adoption891548e
lines 93–96why, one step back93*An HTTP client, with connection pooling, redirects, cookie persistence, etc.*9495```python96>>> client = Client()Update READMETom Christiebefore adoption441a1f6
line 97why, one step back97>>> response = client.get('https://example.org')Update READMETom Christiebefore adoption891548e
lines 98–99why, one step back98```99Tweak APITom Christiebefore adoptionc9bb39a
lines 100–109why, one step back100* `def __init__([auth], [cookies], [verify], [cert], [timeout], [pool_limits], [max_redirects], [dispatch])`101* `def .request(method, url, [data], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`102* `def .get(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`103* `def .options(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`104* `def .head(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`105* `def .post(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`106* `def .put(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`107* `def .patch(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`108* `def .delete(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`109* `def .send(request, [stream], [allow_redirects], [verify], [cert], [timeout])`Update READMETom Christiebefore adoption58461d4
line 110why, one step back110* `def .close()`Update README.mdTom Christiebefore adoption01a3c09
line 111why, one step back111Reorganise structureTom Christiebefore adoption0c6f618
line 112why, one step back112### `Response`README tweaksTom Christiebefore adoption8e1a263
line 113why, one step back113Update READMETom Christiebefore adoption4fe2f69
line 114why, one step back114*An HTTP response.*Still truckin' onTom Christiebefore adoption6cb5c0d
line 115why, one step back115Update READMETom Christiebefore adoption2de053e
line 116why, one step back116* `def __init__(...)`Update README.mdTom Christiebefore adoption53a3e55
line 117why, one step back117* `.status_code` - **int** *(Typically a `StatusCode` IntEnum.)*Truckin' onTom Christiebefore adoption6b60d95
lines 118–126why, one step back118* `.reason_phrase` - **str**119* `.protocol` - `"HTTP/2"` or `"HTTP/1.1"`120* `.url` - **URL**121* `.headers` - **Headers**122* `.content` - **bytes**123* `.text` - **str**124* `.encoding` - **str**125* `.is_redirect` - **bool**126* `.request` - **Request**Add cookie interfacesTom Christiebefore adoption0717998
line 127why, one step back127* `.cookies` - **Cookies**Truckin' onTom Christiebefore adoption6b60d95
line 128why, one step back128* `.history` - **List[Response]**Update README.mdTom Christiebefore adoption93d7ba3
line 129why, one step back129* `def .raise_for_status()` - **None**Add response.json()Tom Christiebefore adoption2116d44
line 130why, one step back130* `def .json()` - **Any**Update READMETom Christiebefore adoption58461d4
lines 131–135why, one step back131* `def .read()` - **bytes**132* `def .stream()` - **bytes iterator**133* `def .raw()` - **bytes iterator**134* `def .close()` - **None**135* `def .next()` - **Response**Update READMETom Christiebefore adoptionfa8d296
line 136why, one step back136Reorganise structureTom Christiebefore adoption0c6f618
line 137why, one step back137### `Request`Truckin' onTom Christiebefore adoption6b60d95
line 138why, one step back138Still truckin' onTom Christiebefore adoption6cb5c0d
lines 139–142why, one step back139*An HTTP request. Can be constructed explicitly for more control over exactly140what gets sent over the wire.*141142```pythonUpdate READMETom Christiebefore adoption891548e
line 143why, one step back143>>> request = Request("GET", "https://example.org", headers={'host': 'example.org'})Update READMETom Christiebefore adoptiona5eb829
line 144why, one step back144>>> response = client.send(request)Still truckin' onTom Christiebefore adoption6cb5c0d
lines 145–146why, one step back145```146Add json interfacesTom Christiebefore adoption5a63d31
line 147why, one step back147* `def __init__(method, url, [params], [data], [json], [headers], [cookies])`TweakTom Christiebefore adoptionf6a2aef
line 148why, one step back148* `.method` - **str**Update READMETom Christiebefore adoptionfa8d296
lines 149–151why, one step back149* `.url` - **URL**150* `.content` - **byte** or **byte async iterator**151* `.headers` - **Headers**Add cookie interfacesTom Christiebefore adoption0717998
line 152why, one step back152* `.cookies` - **Cookies**Truckin' onTom Christiebefore adoption6b60d95
line 153why, one step back153Reorganise structureTom Christiebefore adoption0c6f618
line 154why, one step back154### `URL`Truckin' onTom Christiebefore adoption6b60d95
lines 155–156why, one step back155156*A normalized, IDNA supporting URL.*Update READMETom Christiebefore adoption891548e
lines 157–162why, one step back157158```python159>>> url = URL("https://example.org/")160>>> url.host161'example.org'162```Truckin' onTom Christiebefore adoption6b60d95
line 163why, one step back163query_params -> paramsTom Christiebefore adoptionbb70377
line 164why, one step back164* `def __init__(url, allow_relative=False, params=None)`Truckin' onTom Christiebefore adoption6b60d95
lines 165–176why, one step back165* `.scheme` - **str**166* `.authority` - **str**167* `.host` - **str**168* `.port` - **int**169* `.path` - **str**170* `.query` - **str**171* `.full_path` - **str**172* `.fragment` - **str**173* `.is_ssl` - **bool**174* `.origin` - **Origin**175* `.is_absolute_url` - **bool**176* `.is_relative_url` - **bool**Update READMETom Christiebefore adoptionfa8d296
lines 177–178why, one step back177* `def .copy_with([scheme], [authority], [path], [query], [fragment])` - **URL**178* `def .resolve_with(url)` - **URL**Truckin' onTom Christiebefore adoption6b60d95
line 179why, one step back179Reorganise structureTom Christiebefore adoption0c6f618
line 180why, one step back180### `Origin`Truckin' onTom Christiebefore adoption6b60d95
lines 181–183why, one step back181182*A normalized, IDNA supporting set of scheme/host/port info.*183Update README for 0.2.0Tom Christiebefore adoptionbb3d452
line 184why, one step back184```pythonTruckin' onTom Christiebefore adoption6b60d95
lines 185–186why, one step back185>>> Origin('https://example.org') == Origin('HTTPS://EXAMPLE.ORG:443')186TrueREADME tweaksTom Christiebefore adoption8e1a263
lines 187–188why, one step back187```188Update READMETom Christiebefore adoption2de053e
line 189why, one step back189* `def __init__(url)`Truckin' onTom Christiebefore adoption6b60d95
lines 190–192why, one step back190* `.is_ssl` - **bool**191* `.host` - **str**192* `.port` - **int**Added proxy exampleTom Christiebefore adoption87b21b0
line 193why, one step back193Reorganise structureTom Christiebefore adoption0c6f618
line 194why, one step back194### `Headers`Added proxy exampleTom Christiebefore adoption87b21b0
line 195why, one step back195Truckin' onTom Christiebefore adoption6b60d95
lines 196–197why, one step back196*A case-insensitive multi-dict.*197Added proxy exampleTom Christiebefore adoption87b21b0
line 198why, one step back198```pythonTruckin' onTom Christiebefore adoption6b60d95
lines 199–202why, one step back199>>> headers = Headers({'Content-Type': 'application/json'})200>>> headers['content-type']201'application/json'202```Update READMETom Christiebefore adoption2de053e
line 203why, one step back203Add cookie interfacesTom Christiebefore adoption0717998
lines 204–215why, one step back204* `def __init__(self, headers)`205206### `Cookies`207208*A dict-like cookie store.*209210```python211>>> cookies = Cookies()212>>> cookies.set("name", "value", domain="example.org")213```214215* `def __init__(cookies: [dict, Cookies, CookieJar])`TweakTom Christiebefore adoption33a2249
line 216why, one step back216* `.jar` - **CookieJar**Add cookie interfacesTom Christiebefore adoption0717998
lines 217–223why, one step back217* `def extract_cookies(response)`218* `def set_cookie_header(request)`219* `def set(name, value, [domain], [path])`220* `def get(name, [domain], [path])`221* `def delete(name, [domain], [path])`222* `def clear([domain], [path])`223* *Standard mutable mapping interface*Added proxy exampleTom Christiebefore adoption87b21b0
line 224why, one step back224Truckin' onTom Christiebefore adoption6b60d95
line 225why, one step back225___Added proxy exampleTom Christiebefore adoption87b21b0
line 226why, one step back226Truckin' onTom Christiebefore adoption6b60d95
line 227why, one step back227## Alternate backendsAdded proxy exampleTom Christiebefore adoption87b21b0
line 228why, one step back228Update READMETom Christiebefore adoption58461d4
line 229why, one step back229### `AsyncClient`Added proxy exampleTom Christiebefore adoption87b21b0
line 230why, one step back230Update READMETom Christiebefore adoption58461d4
line 231why, one step back231An asyncio client.Added proxy exampleTom Christiebefore adoption87b21b0
line 232why, one step back232Truckin' onTom Christiebefore adoption6b60d95
line 233why, one step back233### `TrioClient`Added proxy exampleTom Christiebefore adoption87b21b0
line 234why, one step back234Truckin' onTom Christiebefore adoption6b60d95
line 235why, one step back235*TODO*Added proxy exampleTom Christiebefore adoption87b21b0
line 236why, one step back236Truckin' onTom Christiebefore adoption6b60d95
line 237why, one step back237---Added proxy exampleTom Christiebefore adoption87b21b0
line 238why, one step back238Truckin' onTom Christiebefore adoption6b60d95
line 239why, one step back239## The StackImprove GatewayService exampleTom Christiebefore adoption9d59a5a
line 240why, one step back240Update READMETom Christiebefore adoption58461d4
lines 241–243why, one step back241There are two main layers in the stack. The client handles redirection,242cookie persistence (TODO), and authentication (TODO). The dispatcher243handles sending the actual request and getting the response.Improve GatewayService exampleTom Christiebefore adoption9d59a5a
line 244why, one step back244Update READMETom Christiebefore adoption58461d4
lines 245–246why, one step back245* `Client` - Redirect, authentication, cookies etc.246* `ConnectionPool(Dispatcher)` - Connection pooling & keep alive.Truckin' onTom Christiebefore adoption6b60d95
lines 247–249why, one step back247 * `HTTPConnection` - A single connection.248 * `HTTP11Connection` - A single HTTP/1.1 connection.249 * `HTTP2Connection` - A single HTTP/2 connection, with multiple streams.