|
1 | | -import io |
2 | 1 | import json |
3 | 2 | import logging |
4 | 3 | import logging.config |
5 | 4 | import sys |
| 5 | +from io import BytesIO |
6 | 6 | from urllib.parse import parse_qsl as _parse_query_string |
7 | 7 |
|
8 | 8 | from cookies_samesite_compat import CookiesSameSiteCompatMiddleware |
9 | 9 |
|
10 | 10 | import satosa |
11 | 11 | import satosa.logging_util as lu |
| 12 | + |
12 | 13 | from .base import SATOSABase |
13 | 14 | from .context import Context |
14 | 15 | from .response import ServiceError, NotFound |
@@ -68,14 +69,22 @@ def unpack_request(environ, content_length=0): |
68 | 69 | return data |
69 | 70 |
|
70 | 71 |
|
| 72 | +def collect_server_headers(environ): |
| 73 | + headers = { |
| 74 | + header_name: header_value |
| 75 | + for header_name, header_value in environ.items() |
| 76 | + if header_name.startswith("SERVER_") |
| 77 | + } |
| 78 | + return headers |
| 79 | + |
| 80 | + |
71 | 81 | def collect_http_headers(environ): |
72 | 82 | headers = { |
73 | 83 | header_name: header_value |
74 | 84 | for header_name, header_value in environ.items() |
75 | 85 | if ( |
76 | 86 | header_name.startswith("HTTP_") |
77 | 87 | or header_name.startswith("REMOTE_") |
78 | | - or header_name.startswith("SERVER_") |
79 | 88 | ) |
80 | 89 | } |
81 | 90 | return headers |
@@ -119,19 +128,21 @@ def __call__(self, environ, start_response, debug=False): |
119 | 128 | context.path = path |
120 | 129 |
|
121 | 130 | # copy wsgi.input stream to allow it to be re-read later by satosa plugins |
122 | | - # see: http://stackoverflow.com/ |
123 | | - # questions/1783383/how-do-i-copy-wsgi-input-if-i-want-to-process-post-data-more-than-once |
| 131 | + # see: http://stackoverflow.com/questions/1783383/how-do-i-copy-wsgi-input-if-i-want-to-process-post-data-more-than-once |
124 | 132 | content_length = int(environ.get('CONTENT_LENGTH', '0') or '0') |
125 | | - body = io.BytesIO(environ['wsgi.input'].read(content_length)) |
| 133 | + body = BytesIO(environ['wsgi.input'].read(content_length)) |
126 | 134 | environ['wsgi.input'] = body |
| 135 | + |
127 | 136 | context.request = unpack_request(environ, content_length) |
128 | 137 | context.request_uri = environ.get("REQUEST_URI") |
129 | 138 | context.request_method = environ.get("REQUEST_METHOD") |
| 139 | + context.qs_params = parse_query_string(environ.get("QUERY_STRING")) |
| 140 | + context.server = collect_server_headers(environ) |
130 | 141 | context.http_headers = collect_http_headers(environ) |
131 | | - environ['wsgi.input'].seek(0) |
| 142 | + context.cookie = context.http_headers.get("HTTP_COOKIE", "") |
| 143 | + context.request_authorization = context.http_headers.get("HTTP_AUTHORIZATION", "") |
132 | 144 |
|
133 | | - context.cookie = environ.get("HTTP_COOKIE", "") |
134 | | - context.request_authorization = environ.get("HTTP_AUTHORIZATION", "") |
| 145 | + environ['wsgi.input'].seek(0) |
135 | 146 |
|
136 | 147 | try: |
137 | 148 | resp = self.run(context) |
|
0 commit comments