Skip to content

Commit

Permalink
Making Mux working again after rebase
Browse files Browse the repository at this point in the history
Signed-off-by: Eloi DEMOLIS <[email protected]>
  • Loading branch information
Wonshtrum committed May 6, 2024
1 parent 54d04a4 commit 96b2b9f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 31 deletions.
12 changes: 8 additions & 4 deletions e2e/src/http_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ pub fn http_request<S1: Into<String>, S2: Into<String>, S3: Into<String>, S4: In

pub fn immutable_answer(status: u16) -> String {
match status {
400 => String::from("HTTP/1.1 400 Bad Request\r\nCache-Control: no-cache\r\nConnection: close\r\n\r\n"),
404 => String::from("HTTP/1.1 404 Not Found\r\nCache-Control: no-cache\r\nConnection: close\r\n\r\n"),
502 => String::from("HTTP/1.1 502 Bad Gateway\r\nCache-Control: no-cache\r\nConnection: close\r\n\r\n"),
503 => String::from("HTTP/1.1 503 Service Unavailable\r\nCache-Control: no-cache\r\nConnection: close\r\n\r\n"),
// 400 => String::from("HTTP/1.1 400 Bad Request\r\nCache-Control: no-cache\r\nConnection: close\r\n\r\n"),
400 => String::from("HTTP/1.1 400 Sozu Default Answer\r\nCache-Control: no-cache\r\nConnection: close\r\nContent-Length: 0\r\n\r\n"),
// 404 => String::from("HTTP/1.1 404 Not Found\r\nCache-Control: no-cache\r\nConnection: close\r\n\r\n"),
404 => String::from("HTTP/1.1 404 Sozu Default Answer\r\nCache-Control: no-cache\r\nConnection: close\r\nContent-Length: 0\r\n\r\n"),
// 502 => String::from("HTTP/1.1 502 Bad Gateway\r\nCache-Control: no-cache\r\nConnection: close\r\n\r\n"),
502 => String::from("HTTP/1.1 502 Sozu Default Answer\r\nCache-Control: no-cache\r\nConnection: close\r\nContent-Length: 0\r\n\r\n"),
// 503 => String::from("HTTP/1.1 503 Service Unavailable\r\nCache-Control: no-cache\r\nConnection: close\r\n\r\n"),
503 => String::from("HTTP/1.1 503 Sozu Default Answer\r\nCache-Control: no-cache\r\nConnection: close\r\nContent-Length: 0\r\n\r\n"),
_ => unimplemented!()
}
}
Expand Down
4 changes: 2 additions & 2 deletions e2e/src/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ fn try_http_behaviors() -> State {
let response = client.receive();
println!("request: {request:?}");
println!("response: {response:?}");
assert_eq!(response, Some(immutable_answer(503)));
assert_eq!(response, Some(immutable_answer(502)));
assert_eq!(client.receive(), None);

worker.send_proxy_request_type(RequestType::RemoveBackend(RemoveBackend {
Expand Down Expand Up @@ -986,7 +986,7 @@ fn try_https_redirect() -> State {
client.connect();
client.send();
let answer = client.receive();
let expected_answer = format!("{answer_301_prefix}https://example.com/redirected?true\r\n\r\n");
let expected_answer = format!("{answer_301_prefix}https://example.com/redirected?true\r\nContent-Length: 0\r\n\r\n");
assert_eq!(answer, Some(expected_answer));

State::Success
Expand Down
2 changes: 1 addition & 1 deletion lib/src/protocol/mux/h2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl Default for H2Settings {
fn default() -> Self {
Self {
settings_header_table_size: 4096,
settings_enable_push: true,
settings_enable_push: false,
settings_max_concurrent_streams: 100,
settings_initial_window_size: (1 << 16) - 1,
settings_max_frame_size: 1 << 14,
Expand Down
45 changes: 23 additions & 22 deletions lib/src/protocol/mux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ use self::h2::Prioriser;
#[macro_export]
macro_rules! println_ {
($($t:expr),*) => {
// print!("{}:{} ", file!(), line!());
// println!($($t),*)
print!("{}:{} ", file!(), line!());
println!($($t),*)
// $(let _ = &$t;)*
};
}
Expand Down Expand Up @@ -1260,26 +1260,27 @@ impl<Front: SocketHandler + std::fmt::Debug> SessionState for Mux<Front> {
// println!("SUCCESS: session {token:?} was removed!");
}
}
// let s = match &mut self.frontend {
// Connection::H1(c) => &mut c.socket,
// Connection::H2(c) => &mut c.socket,
// };
// let mut b = [0; 1024];
// let (size, status) = s.socket_read(&mut b);
// println_!("{size} {status:?} {:?}", &b[..size]);
// for stream in &mut self.context.streams {
// for kawa in [&mut stream.front, &mut stream.back] {
// debug_kawa(kawa);
// kawa.prepare(&mut kawa::h1::BlockConverter);
// let out = kawa.as_io_slice();
// let mut writer = std::io::BufWriter::new(Vec::new());
// let amount = writer.write_vectored(&out).unwrap();
// println_!(
// "amount: {amount}\n{}",
// String::from_utf8_lossy(writer.buffer())
// );
// }
// }
use std::io::Write;
let s = match &mut self.frontend {
Connection::H1(c) => &mut c.socket,
Connection::H2(c) => &mut c.socket,
};
let mut b = [0; 1024];
let (size, status) = s.socket_read(&mut b);
println_!("{size} {status:?} {:?}", &b[..size]);
for stream in &mut self.context.streams {
for kawa in [&mut stream.front, &mut stream.back] {
debug_kawa(kawa);
kawa.prepare(&mut kawa::h1::BlockConverter);
let out = kawa.as_io_slice();
let mut writer = std::io::BufWriter::new(Vec::new());
let amount = writer.write_vectored(&out).unwrap();
println_!(
"amount: {amount}\n{}",
String::from_utf8_lossy(writer.buffer())
);
}
}
}

fn shutting_down(&mut self) -> SessionIsToBeClosed {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ impl SocketHandler for FrontRustls {
(size, SocketResult::Error)
} else if is_closed {
(size, SocketResult::Closed)
} else if !can_read {
(size, SocketResult::WouldBlock)
// } else if !can_read {
// (size, SocketResult::WouldBlock)
} else {
(size, SocketResult::Continue)
}
Expand Down

0 comments on commit 96b2b9f

Please sign in to comment.