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

Fixes #476: Correctly handle URI which contains hostname #477

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions pingora-http/src/lib.rs
Original file line number Diff line number Diff line change
@@ -129,18 +129,18 @@ impl RequestHeader {
.try_into()
.explain_err(InvalidHTTPHeader, |_| "invalid method")?;
if let Ok(p) = std::str::from_utf8(path) {
let uri = Uri::builder()
.path_and_query(p)
.build()
// Replace backslashes with forward slashes
let normalized_path = p.replace('\\', "/");
let uri = Uri::from_maybe_shared(normalized_path)
.explain_err(InvalidHTTPHeader, |_| format!("invalid uri {}", p))?;
req.base.uri = uri;
// keep raw_path empty, no need to store twice
} else {
// put a valid utf-8 path into base for read only access
let lossy_str = String::from_utf8_lossy(path);
let uri = Uri::builder()
.path_and_query(lossy_str.as_ref())
.build()
// Replace backslashes with forward slashes
let normalized_path = lossy_str.replace('\\', "/");
let uri = Uri::from_maybe_shared(normalized_path)
.explain_err(InvalidHTTPHeader, |_| format!("invalid uri {}", lossy_str))?;
req.base.uri = uri;
req.raw_path_fallback = path.to_vec();
@@ -658,6 +658,12 @@ mod tests {
assert_eq!(buf, b"FoO: Bar\r\n");
}

#[test]
fn test_hostname() {
let req = RequestHeader::build("GET", b"https://example.com/foo?bar=baz", None).unwrap();
assert_eq!(req.uri.host(), Some("example.com"));
}

#[test]
fn test_single_header_no_case() {
let mut req = RequestHeader::new_no_case(None);