Skip to content

Commit

Permalink
Added short docs and a test for providing a custom agent.
Browse files Browse the repository at this point in the history
  • Loading branch information
cwaldbieser committed Jul 29, 2015
1 parent 0f0e5fc commit 972b84f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
14 changes: 14 additions & 0 deletions docs/howto.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,17 @@ access as `requests cookies <http://requests.readthedocs.org/en/latest/user/quic
:lines: 7-20

Full example: :download:`using_cookies.py <examples/using_cookies.py>`

Agent Customization
-------------------

`treq` creates its own `twisted.web.client.Agent` with reasonable defaults, but
you may want to provide your own custom agent. A custom agent can be passed
to the various `treq` request methods using the ``agent`` keyword argument.

.. code-block:: python
custom_agent = create_custom_agent(trusted_certs, timeout)
treq.get(url, agent=custom_agent)
7 changes: 6 additions & 1 deletion treq/test/test_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import mock

from treq.test.util import TestCase

import treq
from treq._utils import set_global_pool

Expand Down Expand Up @@ -44,3 +43,9 @@ def test_cached_pool(self):
treq.get('http://test.com')

self.Agent.assert_called_with(mock.ANY, pool=pool)

def test_custom_agent(self):
custom_agent = mock.Mock()
treq.get('https://www.example.org/', agent=custom_agent)
self.HTTPClient.assertCalledWith(custom_agent)

0 comments on commit 972b84f

Please sign in to comment.