Skip to content
Myr

Add Cookies docs

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tom Christie · committed by Tom Christie · parent f296e6d · Browse files · 1 file+33 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+33 added−2 removed

  • other:+33 added−2 removed

1 file+33 added−2 removed

modified:docs/quickstart.md+33 added-2 removed
9 unmodified lines
10```11>>> import http312```1314Now, let’s try to get a webpage. For this example, let’s get GitHub’s public timeline:14Now, let’s try to get a webpage.1516```python17>>> r = http3.get('https://api.github.com/events')17>>> r = http3.get('https://httpbin.org/get')18```1920Similarly, to make an HTTP POST request:21
245 unmodified lines
267Multiple values for a single response header are represented as a single comma separated268value, as per [RFC 7230](https://tools.ietf.org/html/rfc7230#section-3.2):269270> 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.271272## Cookies273274Any cookies that are set on the response can be easily accessed:275276```python277>>> r = http3.get('http://httpbin.org/cookies/set?chocolate=chip', allow_redirects=False)278>>> r.cookies['chocolate']279'chip'280```281282To include cookies in an outgoing request, use the `cookies` parameter:283284```python285>>> cookies = {"peanut": "butter"}286>>> r = http3.get('http://httpbin.org/cookies', cookies=cookies)287>>> r.json()288{'cookies': {'peanut': 'butter'}}289```290291Cookies are returned in a `Cookies` instance, which is a dict-like data structure292but with additional API for accessing cookies by their domain or path.293294```python295>>> cookies = http3.Cookies()296>>> cookies.set('cookie_on_domain', 'hello, there!', domain='httpbin.org')297>>> cookies.set('cookie_off_domain', 'nope.', domain='example.org')298>>> r = http3.get('http://httpbin.org/cookies', cookies=cookies)299>>> r.json()300{'cookies': {'cookie_on_domain': 'hello, there!'}}301```