Skip to content
Myr

Merge branch 'master' of github.com:dsoprea/requests

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

Conflicts: docs/user/advanced.rst

authored by Cory Benfield · committed by Cory Benfield · parents 1720e4b, 3ccdfce · Browse files · 1 file+34 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+34 added−2 removed

  • other:+34 added−2 removed

1 file+34 added−2 removed

modified:docs/user/advanced.rst+34 added-2 removed
608 unmodified lines
609The mount call registers a specific instance of a Transport Adapter to a610prefix. Once mounted, any HTTP request made using that session whose URL starts611with the given prefix will use the given Transport Adapter.612613Implementing a Transport Adapter is beyond the scope of this documentation, but614a good start would be to subclass the :class:`requests.adapters.BaseAdapter` class.613Many of the details of implementing a Transport Adapter are beyond the scope of614this documentation, but take a look at the next example for a simple SSL use-615case. For more than that, you might look at subclassing616``requests.adapters.BaseAdapter``.617618Example: Specific SSL Version619-----------------------------620621The Requests team has made a specific choice to use whatever SSL version is622default in the underlying library (`urllib3`_). Normally this is fine, but from623time to time, you might find yourself needing to connect to a service-endpoint624that uses a version that isn't compatible with the default.625626You can use Transport Adapters for this by taking most of the existing627implementation of HTTPAdapter, and adding a parameter *ssl_version* that gets628passed-through to `urllib3`. We'll make a TA that instructs the library to use629SSLv3:630631::632633 import ssl634635 from requests.adapters import HTTPAdapter636 from requests.packages.urllib3.poolmanager import PoolManager637638639 class Ssl3HttpAdapter(HTTPAdapter):640 """"Transport adapter" that allows us to use SSLv3."""641642 def init_poolmanager(self, connections, maxsize, block=False):643 self.poolmanager = PoolManager(num_pools=connections,644 maxsize=maxsize,645 block=block,646 ssl_version=ssl.PROTOCOL_SSLv3)647648.. _`described here`: http://kennethreitz.org/exposures/the-future-of-python-http649.. _`urllib3`: https://github.com/shazow/urllib3650651Blocking Or Non-Blocking?
15 unmodified lines