Skip to content

Commit 80b80cb

Browse files
authored
Encode path with latin1 in WSGI (#326)
1 parent f3396b3 commit 80b80cb

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/wsgi/callbacks.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use itertools::Itertools;
1111
use percent_encoding::percent_decode_str;
1212
use pyo3::{
1313
prelude::*,
14-
types::{IntoPyDict, PyDict},
14+
types::{IntoPyDict, PyBytes, PyDict},
1515
};
1616
use std::borrow::Cow;
1717
use std::net::SocketAddr;
@@ -39,7 +39,7 @@ fn run_callback(
3939
.uri
4040
.path_and_query()
4141
.map_or_else(|| ("", ""), |pq| (pq.path(), pq.query().unwrap_or("")));
42-
let path = percent_decode_str(path_raw).decode_utf8().unwrap();
42+
let path = percent_decode_str(path_raw).collect_vec();
4343
let version = match parts.version {
4444
Version::HTTP_10 => "HTTP/1",
4545
Version::HTTP_11 => "HTTP/1.1",
@@ -75,7 +75,10 @@ fn run_callback(
7575
environ.set_item(pyo3::intern!(py, "SERVER_PORT"), server.1)?;
7676
environ.set_item(pyo3::intern!(py, "REMOTE_ADDR"), client)?;
7777
environ.set_item(pyo3::intern!(py, "REQUEST_METHOD"), parts.method.as_str())?;
78-
environ.set_item(pyo3::intern!(py, "PATH_INFO"), path)?;
78+
environ.set_item(
79+
pyo3::intern!(py, "PATH_INFO"),
80+
PyBytes::new_bound(py, &path).call_method1(pyo3::intern!(py, "decode"), (pyo3::intern!(py, "latin1"),))?,
81+
)?;
7982
environ.set_item(pyo3::intern!(py, "QUERY_STRING"), query_string)?;
8083
environ.set_item(pyo3::intern!(py, "wsgi.url_scheme"), scheme)?;
8184
environ.set_item(pyo3::intern!(py, "wsgi.input"), Py::new(py, WSGIBody::new(rt, body))?)?;

0 commit comments

Comments
 (0)