Skip to content

Commit

Permalink
Refactoring external change to address code-review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
johnhurt authored and eaufavor committed Mar 22, 2024
1 parent 7166444 commit 838c20e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .bleep
Original file line number Diff line number Diff line change
@@ -1 +1 @@
51069b16b63684ec579bbe0ef3ab1a0ee07cf51d
7d3baa7e49e9b5c7d76775971c9f57f604209f38
41 changes: 22 additions & 19 deletions pingora-core/src/protocols/http/v1/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,31 +428,34 @@ impl HttpSession {
is_buf_keepalive(self.get_header(header::CONNECTION).map(|v| v.as_bytes()))
}

// `Keep-Alive: timeout=5, max=1000` => 5, 1000
/// `Keep-Alive: timeout=5, max=1000` => 5, 1000
/// This is defined in the below spec, this not part of any RFC, so
/// it's behavior is different on different platforms.
/// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive
fn get_keepalive_values(&self) -> (Option<u64>, Option<usize>) {
if let Some(keep_alive_header) = self.get_header("Keep-Alive") {
let Ok(header_value) = str::from_utf8(keep_alive_header.as_bytes()) else {
return (None, None);
};
let Some(keep_alive_header) = self.get_header("Keep-Alive") else {
return (None, None);
};

let mut timeout = None;
let mut max = None;
let Ok(header_value) = str::from_utf8(keep_alive_header.as_bytes()) else {
return (None, None);
};

for param in header_value.split(',') {
let parts: Vec<&str> = param.split('=').map(|s| s.trim()).collect();
match &parts.as_slice() {
["timeout", timeout_value] => {
timeout = timeout_value.trim().parse::<u64>().ok()
}
["max", max_value] => max = max_value.trim().parse::<usize>().ok(),
_ => {}
let mut timeout = None;
let mut max = None;

for param in header_value.split(',') {
let mut parts = param.splitn(2, '=').map(|s| s.trim());
match (parts.next(), parts.next()) {
(Some("timeout"), Some(timeout_value)) => {
timeout = timeout_value.trim().parse().ok()
}
(Some("max"), Some(max_value)) => max = max_value.trim().parse().ok(),
_ => {}
}

(timeout, max)
} else {
(None, None)
}

(timeout, max)
}

/// Close the connection abruptly. This allows to signal the server that the connection is closed
Expand Down

0 comments on commit 838c20e

Please sign in to comment.