Skip to content

Commit

Permalink
Rewrite confusing error messages if someone accesses an HTTP Web UI u…
Browse files Browse the repository at this point in the history
…sing https
  • Loading branch information
Lars Holmberg committed May 24, 2024
1 parent 16bdb83 commit 84ada19
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion locust/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,17 @@ def start_server(self):
(self.host, self.port), self.app, log=None, keyfile=self.tls_key, certfile=self.tls_cert
)
else:
self.server = pywsgi.WSGIServer((self.host, self.port), self.app, log=None)

class RewriteFilter(logging.Filter):
def filter(self, record) -> bool:
msg = record.msg
if msg.find("gevent._socket3.socket at") and msg.find("Invalid HTTP method: '\x16\x03"):
record.msg = f"A request against Locust's Web UI was made using https:// instead of http:// (underlying error was {record.msg})"
return True

logger.addFilter(RewriteFilter())
self.server = pywsgi.WSGIServer((self.host, self.port), self.app, log=None, error_log=logger)

self.server.serve_forever()

def stop(self):
Expand Down

0 comments on commit 84ada19

Please sign in to comment.