aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorKevin Guthrie <[email protected]>2024-03-15 16:05:01 -0400
committerKevin Guthrie <[email protected]>2024-03-21 18:53:04 +0000
commit1813de78cf64631b23ad238be6692026989de905 (patch)
tree29ca4b2c51a7873df5ee887007f10af213a8a38f
parent4f98089a9e87238f483e975618ea58dd59830f1d (diff)
downloadpingora-yuchen/mar-22-sync.tar.gz
pingora-yuchen/mar-22-sync.zip
Refactoring external change to address code-review commentsyuchen/mar-22-sync
-rw-r--r--.bleep2
-rw-r--r--pingora-core/src/protocols/http/v1/client.rs41
2 files changed, 23 insertions, 20 deletions
diff --git a/.bleep b/.bleep
index 67186fe..a704795 100644
--- a/.bleep
+++ b/.bleep
@@ -1 +1 @@
-51069b16b63684ec579bbe0ef3ab1a0ee07cf51d \ No newline at end of file
+7d3baa7e49e9b5c7d76775971c9f57f604209f38 \ No newline at end of file
diff --git a/pingora-core/src/protocols/http/v1/client.rs b/pingora-core/src/protocols/http/v1/client.rs
index 5d1a55a..4604544 100644
--- a/pingora-core/src/protocols/http/v1/client.rs
+++ b/pingora-core/src/protocols/http/v1/client.rs
@@ -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