Skip to content

Commit

Permalink
updated the get arguments as per the spec
Browse files Browse the repository at this point in the history
  • Loading branch information
nprajilesh committed Oct 25, 2020
1 parent 7c3a32c commit 136eac6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,23 @@
from opentelemetry.trace.status import Status, StatusCanonicalCode


# pylint:disable=arguments-differ
class CarrierGetter(DictGetter):
def get(self, scope: dict, header_name: str) -> typing.List[str]:
headers = scope.get("headers")
def get(self, carrier: dict, key: str) -> typing.List[str]:
"""Getter implementation to retrieve a HTTP header value from the ASGI
scope.
Args:
carrier: ASGI scope object
key: header name in scope
Returns:
A list with a single string with the header value if it exists,
else an empty list.
"""
headers = carrier.get("headers")
return [
value.decode("utf8")
for (key, value) in headers
if key.decode("utf8") == header_name
_value.decode("utf8")
for (_key, _value) in headers
if _key.decode("utf8") == key
]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,20 @@ def hello():
_HTTP_VERSION_PREFIX = "HTTP/"


# pylint:disable=arguments-differ
class CarrierGetter(DictGetter):
def get(self, environ: dict, header_name: str) -> typing.List[str]:
"""Retrieve a HTTP header value from the PEP3333-conforming WSGI environ.
def get(self, carrier: dict, key: str) -> typing.List[str]:
"""Getter implementation to retrieve a HTTP header value from the
PEP3333-conforming WSGI environ
Args:
carrier: WSGI environ object
key: header name in environ object
Returns:
A list with a single string with the header value if it exists, else an empty list.
A list with a single string with the header value if it exists,
else an empty list.
"""
environ_key = "HTTP_" + header_name.upper().replace("-", "_")
value = environ.get(environ_key)
environ_key = "HTTP_" + key.upper().replace("-", "_")
value = carrier.get(environ_key)
if value is not None:
return [value]
return []
Expand Down

0 comments on commit 136eac6

Please sign in to comment.