Repository: locustio/locust

Issue:
Repeated secure requests with FastHttpLocust crashes in cookie management
```
from locust.contrib.fasthttp import FastHttpLocust
from locust import task, TaskSet


class UserBehavior(TaskSet):
    @task
    def get_results(self):
        print("about to run")
        self.client.get("/")


class WebsiteUser(FastHttpLocust):
    task_set = UserBehavior
    min_wait = 0
    max_wait = 0
    _catch_exceptions = False
    host = "https://www.mysite.com"

if __name__ == "__main__":
    WebsiteUser().run()
```

```
~ python3 simple.py
about to run
about to run
Traceback (most recent call last):
  File "./simple.py", line 24, in <module>
    WebsiteUser().run()
  File "/Users/lafp/git/locust/locust/core.py", line 158, in run
    task_set_instance.run()
  File "/Users/lafp/git/locust/locust/core.py", line 367, in run
    self.execute_next_task()
  File "/Users/lafp/git/locust/locust/core.py", line 397, in execute_next_task
    self.execute_task(task["callable"], *task["args"], **task["kwargs"])
  File "/Users/lafp/git/locust/locust/core.py", line 409, in execute_task
    task(self, *args, **kwargs)
  File "./simple.py", line 10, in get_results
    self.client.get("/")
  File "/Users/lafp/git/locust/locust/contrib/fasthttp.py", line 210, in get
    return self.request("GET", path, **kwargs)
  File "/Users/lafp/git/locust/locust/contrib/fasthttp.py", line 169, in request
    response = self._send_request_safe_mode(method, url, payload=data, headers=headers, **kwargs)
  File "/Users/lafp/git/locust/locust/contrib/fasthttp.py", line 116, in _send_request_safe_mode
    return self.client.urlopen(url, method=method, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/geventhttpclient/useragent.py", line 340, in urlopen
    self.cookiejar.add_cookie_header(req)
  File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/cookiejar.py", line 1356, in add_cookie_header
    cookies = self._cookies_for_request(request)
  File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/cookiejar.py", line 1282, in _cookies_for_request
    cookies.extend(self._cookies_for_domain(domain, request))
  File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/cookiejar.py", line 1271, in _cookies_for_domain
    if not self._policy.return_ok(cookie, request):
  File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/cookiejar.py", line 1093, in return_ok
    if not fn(cookie, request):
  File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/cookiejar.py", line 1119, in return_ok_secure
    if cookie.secure and request.type != "https":
AttributeError: 'CompatRequest' object has no attribute 'type'
```



Discussion:

Resolving patch:
diff --git a/locust/contrib/fasthttp.py b/locust/contrib/fasthttp.py
--- a/locust/contrib/fasthttp.py
+++ b/locust/contrib/fasthttp.py
@@ -32,6 +32,11 @@ class ConnectionRefusedError(Exception):
 # More info: https://github.com/requests/requests/pull/871
 CompatRequest.unverifiable = False
 
+# Workaround for AttributeError: 'CompatRequest' object has no attribute 'type' in Cookiejar
+# https://github.com/locustio/locust/issues/1138
+# Might allow secure cookies over non-secure connections but that is a minor concern in a load testing tool
+CompatRequest.type = "https"
+
 # Regexp for checking if an absolute URL was specified
 absolute_http_url_regexp = re.compile(r"^https?://", re.I)
 


Test patch: