Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stop looking for proxy settings #1046

Merged
merged 2 commits into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions locust/test/testcases.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def no_content_length():
r = send_file(BytesIO("This response does not have content-length in the header".encode('utf-8')),
add_etags=False,
mimetype='text/plain')
r.headers.remove("Content-Length")
return r

@app.errorhandler(404)
Expand Down