eris: fix tests
This commit is contained in:
parent
1b77c0daa6
commit
4b774b486b
1 changed files with 10 additions and 6 deletions
16
src/main.rs
16
src/main.rs
|
@ -388,16 +388,20 @@ fn find_header_end(data: &[u8]) -> Option<usize> {
|
||||||
|
|
||||||
// Extract path from raw request data
|
// Extract path from raw request data
|
||||||
fn extract_path_from_request(data: &[u8]) -> Option<&str> {
|
fn extract_path_from_request(data: &[u8]) -> Option<&str> {
|
||||||
let request_line = data
|
// Get first line from request
|
||||||
|
let first_line = data
|
||||||
.split(|&b| b == b'\r' || b == b'\n')
|
.split(|&b| b == b'\r' || b == b'\n')
|
||||||
.next()
|
.next()
|
||||||
.filter(|line| !line.is_empty())?;
|
.filter(|line| !line.is_empty())?;
|
||||||
|
|
||||||
let mut parts = request_line.split(|&b| b == b' ');
|
// Split by spaces and ensure we have at least 3 parts
|
||||||
let _ = parts.next()?; // Skip HTTP method
|
let parts: Vec<&[u8]> = first_line.split(|&b| b == b' ').collect();
|
||||||
let path = parts.next()?;
|
if parts.len() < 3 || !parts[2].starts_with(b"HTTP/") {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
std::str::from_utf8(path).ok()
|
// Return the path (second element)
|
||||||
|
std::str::from_utf8(parts[1]).ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract header value from raw request data
|
// Extract header value from raw request data
|
||||||
|
@ -1418,7 +1422,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_find_header_end() {
|
fn test_find_header_end() {
|
||||||
let data = b"GET / HTTP/1.1\r\nHost: example.com\r\nUser-Agent: test\r\n\r\nBody content";
|
let data = b"GET / HTTP/1.1\r\nHost: example.com\r\nUser-Agent: test\r\n\r\nBody content";
|
||||||
assert_eq!(find_header_end(data), Some(53));
|
assert_eq!(find_header_end(data), Some(55));
|
||||||
|
|
||||||
let incomplete = b"GET / HTTP/1.1\r\nHost: example.com\r\n";
|
let incomplete = b"GET / HTTP/1.1\r\nHost: example.com\r\n";
|
||||||
assert_eq!(find_header_end(incomplete), None);
|
assert_eq!(find_header_end(incomplete), None);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue