Shell of Transport Adapter documentation.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Cory Benfield · committed by Cory Benfield · parent c73f653 · Browse files · 1 file·+44 added−8 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+44 added−8 removed
- other:+44 added−8 removed
Provenance
- Commit
e5f1053- Tree
17615a9- Author
Cory Benfield <lukasaoz@gmail.com>- Committer
Cory Benfield <lukasaoz@gmail.com>- Parent
c73f653
1 file changed+44 added−8 removed
modified:docs/user/advanced.rst+44 added-8 removed
78 unmodified lines79 80 Prepared Requests81 -----------------82 83-Whenever you receive a :class:`Response <requests.models.Response>` object 84-from an API call or a Session call, the ``request`` attribute is actually the 85-``PreparedRequest`` that was used. In some cases you may wish to do some extra 86-work to the body or headers (or anything else really) before sending a 83+Whenever you receive a :class:`Response <requests.models.Response>` object84+from an API call or a Session call, the ``request`` attribute is actually the85+``PreparedRequest`` that was used. In some cases you may wish to do some extra86+work to the body or headers (or anything else really) before sending a87 request. The simple recipe for this is the following::88 89 from requests import Request, Session90 15 unmodified lines106 # etc.107 )108 print(resp.status_code)109 110-Since you are not doing anything special with the ``Request`` object, you 111-prepare it immediately and modified the ``PreparedRequest`` object. You then 112-send that with the other parameters you would have sent to ``requests.*`` or 113-``Sesssion.*``. 110+Since you are not doing anything special with the ``Request`` object, you111+prepare it immediately and modified the ``PreparedRequest`` object. You then112+send that with the other parameters you would have sent to ``requests.*`` or113+``Sesssion.*``.114 115 SSL Cert Verification116 ---------------------117 418 unmodified lines536 537 >>> r.links["last"]538 {'url': 'https://api.github.com/users/kennethreitz/repos?page=7&per_page=10', 'rel': 'last'}539 540+Transport Adapters541+------------------542+543+As of v1.0.0, Requests has moved to a modular internal design. Part of the544+reason this was done was to implement Transport Adapters, originally545+`described here`_. Transport Adapters provide a mechanism to define interaction546+methods for an HTTP service. In particular, they allow you to apply per-service547+configuration.548+549+Requests ships with a single Transport Adapter, the550+:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`. This adapter provides the551+default Requests interaction with HTTP and HTTPS using the powerful `urllib3`_552+library. Whenever a Requests :class:`Session <Session>` is initialized, one of553+these is attached to the :class:`Session <Session>` object for HTTP, and one554+for HTTPS.555+556+Requests enables users to create and use their own Transport Adapters that557+provide specific functionality. Once created, a Transport Adapter can be558+mounted to a Session object, along with an indication of which web services559+it should apply to.560+561+::562+563+ >>> s = requests.Session()564+ >>> s.mount('http://www.github.com', MyAdapter())565+566+The mount call registers a specific instance of a Transport Adapter to a567+prefix. Once mounted, any HTTP request made using that session whose URL starts568+with the given prefix will use the given Transport Adapter.569+570+Implementing a Transport Adapter is beyond the scope of this documentation, but571+a good start would be to subclass the ``requests.adapters.BaseAdapter`` class.572+573+.. _`described here`: http://kennethreitz.org/exposures/the-future-of-python-http574+.. _`urllib3`: https://github.com/shazow/urllib3575+