Skip to content

Commit

Permalink
Add 507 default answer
Browse files Browse the repository at this point in the history
Signed-off-by: Eloi DEMOLIS <eloi.demolis@clever-cloud.com>
  • Loading branch information
Wonshtrum committed Oct 24, 2023
1 parent 12c3234 commit be2cfe6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
1 change: 0 additions & 1 deletion command/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,6 @@ impl ConfigState {
})
.collect();


for front in self.http_fronts.values() {
if let Some(cluster_id) = &front.cluster_id {
if let Some(hasher) = hm.get_mut(cluster_id) {
Expand Down
6 changes: 6 additions & 0 deletions lib/src/protocol/kawa_h1/answers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub struct DefaultAnswers {
pub ServiceUnavailable: Rc<Vec<u8>>,
/// 504
pub GatewayTimeout: Rc<Vec<u8>>,
/// 507
pub InsufficientStorage: Rc<Vec<u8>>,
}

#[allow(non_snake_case)]
Expand Down Expand Up @@ -56,6 +58,9 @@ impl HttpAnswers {
GatewayTimeout: Rc::new(Vec::from(
&b"HTTP/1.1 504 Gateway Timeout\r\nCache-Control: no-cache\r\nConnection: close\r\n\r\n"[..]
)),
InsufficientStorage: Rc::new(Vec::from(
&b"HTTP/1.1 507 Insufficient Storage\r\nCache-Control: no-cache\r\nConnection: close\r\n\r\n"[..]
)),
},
custom: HashMap::new(),
}
Expand Down Expand Up @@ -89,6 +94,7 @@ impl HttpAnswers {
.and_then(|c| c.ServiceUnavailable.clone())
.unwrap_or_else(|| self.default.ServiceUnavailable.clone()),
DefaultAnswerStatus::Answer504 => self.default.GatewayTimeout.clone(),
DefaultAnswerStatus::Answer507 => self.default.InsufficientStorage.clone(),
}
}
}
20 changes: 16 additions & 4 deletions lib/src/protocol/kawa_h1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub enum DefaultAnswerStatus {
Answer502,
Answer503,
Answer504,
Answer507,
}

#[allow(clippy::from_over_into)]
Expand All @@ -80,6 +81,7 @@ impl Into<u16> for DefaultAnswerStatus {
Self::Answer502 => 502,
Self::Answer503 => 503,
Self::Answer504 => 504,
Self::Answer507 => 507,
}
}
}
Expand Down Expand Up @@ -454,7 +456,9 @@ impl<Front: SocketHandler, L: ListenerHandler + L7ListenerHandler> Http<Front, L
_ => (),
}

if !(self.request_stream.is_terminated() && self.request_stream.is_completed()) {
if !(self.request_stream.is_terminated() && self.request_stream.is_completed())
&& self.request_stream.body_size != kawa::BodySize::Empty
{
error!("Response terminated before request, this case is not handled properly yet");
incr!("http.early_response_close");
// FIXME: this will cause problems with pipelining
Expand Down Expand Up @@ -604,8 +608,7 @@ impl<Front: SocketHandler, L: ListenerHandler + L7ListenerHandler> Http<Front, L
self.frontend_readiness.interest.insert(Ready::WRITABLE);
} else {
// server has filled its buffer and we can't empty it
// FIXME: should we send 507 Insufficient Storage ?
self.set_answer(DefaultAnswerStatus::Answer502, None);
self.set_answer(DefaultAnswerStatus::Answer507, None);
}
return SessionResult::Continue;
}
Expand Down Expand Up @@ -781,7 +784,11 @@ impl<Front: SocketHandler, L: ListenerHandler + L7ListenerHandler> Http<Front, L
}
pub fn log_request_error(&mut self, metrics: &mut SessionMetrics, message: &str) {
incr!("http.errors");
error!("{} Could not process request properly got: {}", self.log_context(), message);
error!(
"{} Could not process request properly got: {}",
self.log_context(),
message
);
self.print_state(self.protocol_string());
self.log_request(metrics, Some(message));
}
Expand Down Expand Up @@ -831,6 +838,11 @@ impl<Front: SocketHandler, L: ListenerHandler + L7ListenerHandler> Http<Front, L
self.cluster_id.as_deref(),
self.backend_id.as_deref()
),
DefaultAnswerStatus::Answer507 => incr!(
"http.507.errors",
self.cluster_id.as_deref(),
self.backend_id.as_deref()
),
};
}

Expand Down
6 changes: 5 additions & 1 deletion lib/src/protocol/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,11 @@ impl<Front: SocketHandler, L: ListenerHandler> Pipe<Front, L> {

pub fn log_request_error(&self, metrics: &SessionMetrics, message: &str) {
incr!("pipe.errors");
error!("{} Could not process request properly got: {}", self.log_context(), message);
error!(
"{} Could not process request properly got: {}",
self.log_context(),
message
);
self.print_state(self.protocol_string());
self.log_request(metrics, Some(message));
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ impl SocketHandler for FrontRustls {
Ok(sz) => {
size += sz;
can_read = true;
},
}
Err(e) => match e.kind() {
ErrorKind::WouldBlock => {
break;
Expand Down

0 comments on commit be2cfe6

Please sign in to comment.