Skip to content

Commit a8df553

Browse files
committed
Cleanup lowercase
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
1 parent 05c52d5 commit a8df553

4 files changed

Lines changed: 8 additions & 19 deletions

File tree

src/connectrpc/_protocol_connect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def _normalize_content_type(content_type: str) -> str:
5454
# binary and JSON are always either non-text or utf-8 and the parameters are not
5555
# important for matching to a codec. A custom codec could conceivably need to
5656
# match on parameters, but we will reconsider that if it is ever asked for.
57-
return content_type.partition(";")[0].strip()
57+
return content_type.partition(";")[0].strip().lower()
5858

5959

6060
def codec_name_from_content_type(content_type: str, *, stream: bool) -> str:

src/connectrpc/_server_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ async def __call__(
213213
codec_name = protocol.codec_name_from_content_type(
214214
headers.get("content-type", ""), stream=not is_unary
215215
)
216-
codec = self._codecs.get(codec_name.lower())
216+
codec = self._codecs.get(codec_name)
217217
if not codec:
218218
raise HTTPException(
219219
HTTPStatus.UNSUPPORTED_MEDIA_TYPE,

src/connectrpc/_server_sync.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,12 @@
7070
)
7171

7272

73-
def _normalize_wsgi_headers(environ: WSGIEnvironment) -> dict:
74-
"""Extract and normalize HTTP headers from WSGI environment."""
75-
headers = {}
73+
def _process_headers(environ: WSGIEnvironment) -> Headers:
74+
headers = Headers()
7675
if "CONTENT_TYPE" in environ:
77-
headers["content-type"] = environ["CONTENT_TYPE"].lower()
76+
headers["content-type"] = environ["CONTENT_TYPE"]
7877
if "CONTENT_LENGTH" in environ:
79-
headers["content-length"] = environ["CONTENT_LENGTH"].lower()
78+
headers["content-length"] = environ["CONTENT_LENGTH"]
8079

8180
for key, value in environ.items():
8281
if key.startswith("HTTP_"):
@@ -85,17 +84,6 @@ def _normalize_wsgi_headers(environ: WSGIEnvironment) -> dict:
8584
return headers
8685

8786

88-
def _process_headers(headers: dict) -> Headers:
89-
result = Headers()
90-
for key, value in headers.items():
91-
if isinstance(value, list | tuple):
92-
for v in value:
93-
result.add(key, v)
94-
else:
95-
result.add(key, str(value))
96-
return result
97-
98-
9987
def prepare_response_headers(
10088
base_headers: dict[str, list[str]], selected_encoding: str
10189
) -> dict[str, list[str]]:
@@ -220,7 +208,7 @@ def __call__(
220208

221209
http_method = environ["REQUEST_METHOD"]
222210
http_scheme = environ.get("wsgi.url_scheme", "http")
223-
headers = _process_headers(_normalize_wsgi_headers(environ))
211+
headers = _process_headers(environ)
224212
if ra := environ.get("REMOTE_ADDR"):
225213
port = environ.get("REMOTE_PORT", "0")
226214
client_address = f"{ra}:{port}"

test/test_http.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"application/json;charset=utf-8",
2020
"application/json; charset=utf-8",
2121
"application/json; charset=utf-8; version=1",
22+
"application/JSON",
2223
]
2324

2425

0 commit comments

Comments
 (0)