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

FEAT: add stat support for chunked transfer-encoding #33

Closed
quosa opened this issue Sep 18, 2012 · 1 comment
Closed

FEAT: add stat support for chunked transfer-encoding #33

quosa opened this issue Sep 18, 2012 · 1 comment
Assignees
Milestone

Comments

@quosa
Copy link

quosa commented Sep 18, 2012

Hi,
I replaced the HttpBrowser in Locust.client with our client SDK that uses httplib directly. The switch itself (monkey-patching the log_request decorator) was fairly straightforward. However, I came across a problem in stats I could not easily solve: my client does most requests with accept-encoding: gzip and the HTTP 1.1 default keep-alive connections which results in Transfer-Encoding: chunked and Content-Encoding: gzip responses. Since chunked responses do not have the Content-Length header the stats module (stats.py:on_request_success) defaults to 0 content length.

I couldn't figure out how to elegantly patch the on_request_success function, but would you have a proposal?

@heyman
Copy link
Member

heyman commented Nov 27, 2012

Hi!

Sorry for not replying to this sooner.

In the current master branch of locust (and soon in the 0.6 release), the old HTTP client has been replaced with a small wrapper around python-requests (http://python-requests.org). The events.request_success event has also been modified to not take a response object as argument, but rather the content-length as an integer. So if you're rolling your own client it should now be easy to trigger the request_success event and sending in the length of the response body instead of the content-length header.

We could do this change in the locust code (report the length of response.content instead of the content-length header). However, this would trigger a full body download even if the user has made the request using prefetch=False (http://docs.python-requests.org/en/latest/user/advanced/#body-content-workflow), and I'm not sure if we really want to disable that feature.

One option could be to use the length of response.content unless prefetch is set to False, in which case we try to use the content-length header, and last we fallback to 0. However, this would result in us having two different ways of getting the content size which doesn't seem optimal. Despite this, it might be the solution that would work best in most situations. Any input on this @Jahaja @cgbystrom ?

@ghost ghost assigned heyman Nov 29, 2012
@heyman heyman closed this as completed in 81ac588 Nov 29, 2012
pancaprima added a commit to pancaprima/locust that referenced this issue May 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants