Skip to content

Commit

Permalink
remove 404 and 503 files
Browse files Browse the repository at this point in the history
parse the newlines of HTTP error files
make it compile

to fix: end-to-end tests, dockerfile, etc.
  • Loading branch information
Keksoj committed Apr 5, 2024
1 parent 55242ba commit a5058c2
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 140 deletions.
1 change: 1 addition & 0 deletions bin/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ address = "0.0.0.0:8443"

# answer_404 = "../lib/assets/404.html"
# answer_503 = "../lib/assets/503.html"
answer_502 = "./502.html"
# sticky_name = "SOZUBALANCEID"

# Configures the client socket to receive a PROXY protocol header
Expand Down
5 changes: 0 additions & 5 deletions command/assets/404.html

This file was deleted.

5 changes: 0 additions & 5 deletions command/assets/503.html

This file was deleted.

4 changes: 2 additions & 2 deletions command/assets/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ buffer_size = 16384
[[listeners]]
address = "0.0.0.0:80"
protocol = "http"
answer_404 = "./assets/404.html"
#expect_proxy = true

[[listeners]]
address = "0.0.0.0:443"
protocol = "https"
answer_404 = "./assets/404.html"
answer_404 = "./assets/custom_404.html"
tls_versions = ["TLS_V12"]

[[listeners]]
Expand All @@ -29,6 +28,7 @@ expect_proxy = true
[clusters]
[clusters.MyCluster]
protocol = "http"
answer_503 = "./assets/custom_503.html"
#sticky_session = false
#https_redirect = false
frontends = [
Expand Down
19 changes: 1 addition & 18 deletions command/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,26 +603,9 @@ impl ListenerBuilder {
active: false,
})
}

/*
TODO: remove this, and remove default 404 and 503 from the assets, we should rely on the lib for defaults
/// Get the 404 and 503 answers from the file system using the provided paths,
/// if none, defaults to HTML files in the sozu assets
fn get_404_503_answers(&self) -> Result<(String, String), ConfigError> {
let answer_404 = match &self.answer_404 {
Some(a_404_path) => read_file(a_404_path)?,
None => String::from(include_str!("../assets/404.html")),
};
let answer_503 = match &self.answer_503 {
Some(a_503_path) => read_file(a_503_path)?,
None => String::from(include_str!("../assets/503.html")),
};
Ok((answer_404, answer_503))
}
*/
}

/// read a custom HTTP answer from a file
fn read_http_answer_file(path: &Option<String>) -> Result<Option<String>, ConfigError> {
match path {
Some(path) => {
Expand Down
11 changes: 7 additions & 4 deletions e2e/src/http_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ pub fn http_request<S1: Into<String>, S2: Into<String>, S3: Into<String>, S4: In

// the default value for the 404 error, as provided in the command lib,
// used as default for listeners
pub fn default_404_answer() -> String {
String::from(include_str!("../../../command/assets/404.html"))
// TODO: make this return a fix 404 error to be compared to in the tests
// TODO: rename this to fix_404_answer
// same for 503
pub fn immutable_404_answer() -> String {
String::from("HTTP/1.1 404 Not Found\r\nCache-Control: no-cache\r\nConnection: close\r\n")
}

// the default value for the 503 error, as provided in the command lib,
// used as default for listeners
pub fn default_503_answer() -> String {
String::from(include_str!("../../../command/assets/503.html"))
pub fn fixed_503_answer() -> String {
String::from("HTTP/1.1 503 Service Unavailable\r\nCache-Control: no-cache\r\nConnection: close\r\n%Content-Length: %CONTENT_LENGTH\r\nSozu-Id: %SOZU_ID\r\n")
}
8 changes: 4 additions & 4 deletions e2e/src/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use sozu_command_lib::{
};

use crate::{
http_utils::{default_404_answer, default_503_answer, http_ok_response, http_request},
http_utils::{immutable_404_answer, fixed_503_answer, http_ok_response, http_request},
mock::{
aggregator::SimpleAggregator,
async_backend::BackendHandle as AsyncBackend,
Expand Down Expand Up @@ -664,7 +664,7 @@ fn try_http_behaviors() -> State {

let response = client.receive();
println!("response: {response:?}");
assert_eq!(response, Some(default_404_answer()));
assert_eq!(response, Some(immutable_404_answer()));
assert_eq!(client.receive(), None);

worker.send_proxy_request_type(RequestType::AddHttpFrontend(RequestHttpFrontend {
Expand All @@ -679,7 +679,7 @@ fn try_http_behaviors() -> State {

let response = client.receive();
println!("response: {response:?}");
assert_eq!(response, Some(default_503_answer()));
assert_eq!(response, Some(fixed_503_answer()));
assert_eq!(client.receive(), None);

let back_address = create_local_address();
Expand Down Expand Up @@ -785,7 +785,7 @@ fn try_http_behaviors() -> State {
let response = client.receive();
println!("request: {request:?}");
println!("response: {response:?}");
assert_eq!(response, Some(default_503_answer()));
assert_eq!(response, Some(fixed_503_answer()));
assert_eq!(client.receive(), None);

worker.send_proxy_request_type(RequestType::RemoveBackend(RemoveBackend {
Expand Down
4 changes: 0 additions & 4 deletions lib/assets/404.html

This file was deleted.

4 changes: 0 additions & 4 deletions lib/assets/503.html

This file was deleted.

Loading

0 comments on commit a5058c2

Please sign in to comment.