Skip to content

Commit b50f70b

Browse files
committed
Separate server headers from http headers
Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent 5b110d6 commit b50f70b

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

src/satosa/context.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def __init__(self):
2626
self.request_uri = None
2727
self.request_method = None
2828
self.qs_params = None
29+
self.server = None
2930
self.http_headers = None
3031
self.cookie = None
3132
self.request_authorization = None

src/satosa/proxy_server.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import io
21
import json
32
import logging
43
import logging.config
54
import sys
5+
from io import BytesIO
66
from urllib.parse import parse_qsl as _parse_query_string
77

88
from cookies_samesite_compat import CookiesSameSiteCompatMiddleware
99

1010
import satosa
1111
import satosa.logging_util as lu
12+
1213
from .base import SATOSABase
1314
from .context import Context
1415
from .response import ServiceError, NotFound
@@ -68,14 +69,22 @@ def unpack_request(environ, content_length=0):
6869
return data
6970

7071

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+
7181
def collect_http_headers(environ):
7282
headers = {
7383
header_name: header_value
7484
for header_name, header_value in environ.items()
7585
if (
7686
header_name.startswith("HTTP_")
7787
or header_name.startswith("REMOTE_")
78-
or header_name.startswith("SERVER_")
7988
)
8089
}
8190
return headers
@@ -119,20 +128,21 @@ def __call__(self, environ, start_response, debug=False):
119128
context.path = path
120129

121130
# 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
124132
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))
126134
environ['wsgi.input'] = body
135+
127136
context.request = unpack_request(environ, content_length)
128137
context.request_uri = environ.get("REQUEST_URI")
129138
context.request_method = environ.get("REQUEST_METHOD")
130-
context.http_headers = collect_http_headers(environ)
131139
context.qs_params = parse_query_string(environ.get("QUERY_STRING"))
132-
environ['wsgi.input'].seek(0)
140+
context.server = collect_server_headers(environ)
141+
context.http_headers = collect_http_headers(environ)
142+
context.cookie = context.http_headers.get("HTTP_COOKIE", "")
143+
context.request_authorization = context.http_headers.get("HTTP_AUTHORIZATION", "")
133144

134-
context.cookie = environ.get("HTTP_COOKIE", "")
135-
context.request_authorization = environ.get("HTTP_AUTHORIZATION", "")
145+
environ['wsgi.input'].seek(0)
136146

137147
try:
138148
resp = self.run(context)

0 commit comments

Comments
 (0)