Skip to content

Commit

Permalink
stop looking for proxy settings
Browse files Browse the repository at this point in the history
  • Loading branch information
myzhan authored and cgoldberg committed Jul 12, 2019
1 parent 4b1b304 commit 9847c3a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ The :py:class:`HttpLocust <locust.core.HttpLocust>` class inherits from the
:py:class:`Locust <locust.core.Locust>` class, and it adds a client attribute which is an instance of
:py:class:`HttpSession <locust.clients.HttpSession>` that can be used to make HTTP requests.

By default, we stop looking for proxy settings to improve performance. If you really want the test requests
go through a HTTP proxy, you can inherit from the :py:class:`HttpLocust <locust.core.HttpLocust>` class and
set the trust_env field to True. For further details, refer to the documentation of requests.

Another way we could declare tasks, which is usually more convenient, is to use the
``@task`` decorator. The following code is equivalent to the above:

Expand Down
13 changes: 11 additions & 2 deletions locust/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,22 @@ class HttpLocust(Locust):
Instance of HttpSession that is created upon instantiation of Locust.
The client support cookies, and therefore keeps the session between HTTP requests.
"""

trust_env = False
"""
Look for proxy settings will slow down the default http client.
It's the default behavior of the requests library.
We don't need this feature most of the time, so disable it by default.
"""

def __init__(self):
super(HttpLocust, self).__init__()
if self.host is None:
raise LocustError("You must specify the base host. Either in the host attribute in the Locust class, or on the command line using the --host option.")

self.client = HttpSession(base_url=self.host)

session = HttpSession(base_url=self.host)
session.trust_env = self.trust_env
self.client = session


class TaskSetMeta(type):
Expand Down

0 comments on commit 9847c3a

Please sign in to comment.