aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorKevin Guthrie <[email protected]>2024-03-15 16:05:01 -0400
committerYuchen Wu <[email protected]>2024-03-22 15:00:53 -0700
commit0de54eb9071a9c4baccc6bad7acad11e9c54186f (patch)
tree29ca4b2c51a7873df5ee887007f10af213a8a38f
parent247ce6c4b067dc523cd7fd46ff938297bb5462d6 (diff)
downloadpingora-0de54eb9071a9c4baccc6bad7acad11e9c54186f.tar.gz
pingora-0de54eb9071a9c4baccc6bad7acad11e9c54186f.zip
Refactoring external change to address code-review commentsyuchen/test-marh22
-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