Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing directly optional request argument in WSGI middleware #46

Closed
gzlatkov opened this issue Jun 6, 2016 · 1 comment
Closed

Comments

@gzlatkov
Copy link

gzlatkov commented Jun 6, 2016

QUERY_STRING is an optional argument for environ, hence should probably be accessed using get. Moreover, I think exceptions should not be just pass-ed. Currently, if QUERY_STRING is absent, KeyError will result in request be equal to {} which will throw another exception when we try to access headers.

Valid for both python2 and python3

python2/raygun4py/middleware/wsgi.py:

try:
    request = {
        'httpMethod': environ['REQUEST_METHOD'],
        'url': environ['PATH_INFO'],
        'ipAddress': environ['REMOTE_ADDR'],
        'hostName': environ['HTTP_HOST'].replace(' ', ''),
        'queryString': environ['QUERY_STRING'],
        'headers': {},
        'form': {},
        'rawData': {}
    }
except Exception:
    pass

for key, value in environ.items():
    if key.startswith('HTTP_'):
       request['headers'][key] = value
@fundead
Copy link
Contributor

fundead commented Jun 6, 2016

Thanks for your feedback here, looks reasonable. We'll be integrating it in the next release which should be in the near term.

Regards,

Callum Gavin
Raygun Limited

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants