Skip to content

Commit

Permalink
handle empty attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
majorgreys committed May 22, 2020
1 parent 0b9fbcd commit 3ac4620
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@ def collect_request_attributes(scope):
server = scope.get("server") or ["0.0.0.0", 80]
port = server[1]
server_host = server[0] + (":" + str(port) if port != 80 else "")
http_url = scope.get("scheme") + "://" + server_host + scope.get("path")
if scope.get("query_string"):
http_url = (
scope.get("scheme") + "://" + server_host + scope.get("path", "")
if scope.get("scheme") and server_host and scope.get("path")
else None
)
if scope.get("query_string") and http_url:
http_url = http_url + ("?" + scope.get("query_string").decode("utf8"))

result = {
Expand All @@ -107,6 +111,9 @@ def collect_request_attributes(scope):
result["net.peer.ip"] = scope.get("client")[0]
result["net.peer.port"] = scope.get("client")[1]

# remove None values
result = {k: v for k, v in result.items() if v is not None}

return result


Expand Down

0 comments on commit 3ac4620

Please sign in to comment.