locust fasthttp不可以发送上传文件的请求吗
locust,想用fasthttp,我直接class WebLoadtest(FastHttpUser),并且使用了FastHttpSession的request请求,
def request(
self,
method: str,
path: str,
name: str = None,
data: str = None,
catch_response: bool = False,
stream: bool = False,
headers: dict = None,
auth=None,
json: dict = None,
allow_redirects=True,
context: dict = {},
**kwargs,
):
"""
Send and HTTP request
Returns :py:class:`locust.contrib.fasthttp.FastResponse` object.
:param method: method for the new :class:`Request` object.
:param path: Path that will be concatenated with the base host URL that has been specified.
Can also be a full URL, in which case the full URL will be requested, and the base host
is ignored.
:param name: (optional) An argument that can be specified to use as label in Locust's
statistics instead of the URL path. This can be used to group different URL's
that are requested into a single entry in Locust's statistics.
:param catch_response: (optional) Boolean argument that, if set, can be used to make a request
return a context manager to work as argument to a with statement. This will allow the
request to be marked as a fail based on the content of the response, even if the response
code is ok (2xx). The opposite also works, one can use catch_response to catch a request
and then mark it as successful even if the response code was not (i.e 500 or 404).
:param data: (optional) String/bytes to send in the body of the request.
:param json: (optional) Dictionary to send in the body of the request.
Automatically sets Content-Type and Accept headers to "application/json".
Only used if data is not set.
:param headers: (optional) Dictionary of HTTP Headers to send with the request.
:param auth: (optional) Auth (username, password) tuple to enable Basic HTTP Auth.
:param stream: (optional) If set to true the response body will not be consumed immediately
and can instead be consumed by accessing the stream attribute on the Response object.
Another side effect of setting stream to True is that the time for downloading the response
content will not be accounted for in the request time that is reported by Locust.
"""
# prepend url with hostname unless it's already an absolute URL
但是,它好像不支持form-data?
def _make_request(self, url, method='GET', headers=None, payload=None):
req_headers = self.default_headers.copy()
if headers:
req_headers.update(headers)
if payload:
# Adjust headers depending on payload content
content_type = req_headers.get('content-type', None)
if not content_type and isinstance(payload, dict):
req_headers['content-type'] = "application/x-www-form-urlencoded; charset=utf-8"
payload = urlencode(payload)
elif not content_type and isinstance(payload, text_type):
req_headers['content-type'] = 'text/plain; charset=utf-8'
elif not content_type:
req_headers['content-type'] = 'application/octet-stream'
elif content_type.startswith("multipart/form-data"):
# See restkit for some example implementation
# TODO: Implement it
raise NotImplementedError
return self.request_type(url, method=method, headers=req_headers, payload=payload)
问题,我如何进行非纯文本文件,例如图片、mp3发送的post请求呢 如果我想使用fasthttp进行测试(不使用用httpuser),也许我需要用geventhttp重新构造吗