Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirection and URL rewrite #1162

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions bin/src/ctl/request_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@
Some(tags) => tags,
None => BTreeMap::new(),
},
required_auth: todo!(),
redirect: todo!(),

Check warning on line 254 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (nightly, true)

unreachable expression

Check warning on line 254 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (nightly, true)

unreachable expression

Check warning on line 254 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (false, stable)

unreachable expression

Check warning on line 254 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (false, stable)

unreachable expression

Check warning on line 254 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Build Sozu 🦀

unreachable expression

Check warning on line 254 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (false, beta)

unreachable expression

Check warning on line 254 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (false, stable)

unreachable expression

Check warning on line 254 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (false, beta)

unreachable expression

Check warning on line 254 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Build Sozu 🦀

unreachable expression
redirect_scheme: todo!(),
redirect_template: todo!(),
rewrite_host: todo!(),
rewrite_path: todo!(),
rewrite_port: todo!(),
})
.into(),
),
Expand Down Expand Up @@ -298,6 +305,13 @@
Some(tags) => tags,
None => BTreeMap::new(),
},
required_auth: todo!(),
redirect: todo!(),

Check warning on line 309 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (nightly, true)

unreachable expression

Check warning on line 309 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (nightly, true)

unreachable expression

Check warning on line 309 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (nightly, true)

unreachable expression

Check warning on line 309 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (nightly, true)

unreachable expression

Check warning on line 309 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (false, stable)

unreachable expression

Check warning on line 309 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (false, stable)

unreachable expression

Check warning on line 309 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Build Sozu 🦀

unreachable expression

Check warning on line 309 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (false, beta)

unreachable expression

Check warning on line 309 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (false, beta)

unreachable expression

Check warning on line 309 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (false, stable)

unreachable expression

Check warning on line 309 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (false, stable)

unreachable expression

Check warning on line 309 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (false, beta)

unreachable expression

Check warning on line 309 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (false, beta)

unreachable expression

Check warning on line 309 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Build Sozu 🦀

unreachable expression
redirect_scheme: todo!(),
redirect_template: todo!(),
rewrite_host: todo!(),
rewrite_path: todo!(),
rewrite_port: todo!(),
})
.into(),
),
Expand Down Expand Up @@ -341,8 +355,8 @@
} => {
let https_listener = ListenerBuilder::new_https(address.into())
.with_public_address(public_address)
.with_answer_404_path(answer_404)
.with_answer_503_path(answer_503)
.with_answer("404", answer_404)
.with_answer("503", answer_503)
.with_tls_versions(tls_versions)
.with_cipher_list(cipher_list)
.with_expect_proxy(expect_proxy)
Expand Down Expand Up @@ -384,8 +398,8 @@
} => {
let http_listener = ListenerBuilder::new_http(address.into())
.with_public_address(public_address)
.with_answer_404_path(answer_404)
.with_answer_503_path(answer_503)
.with_answer("404", answer_404)
.with_answer("503", answer_503)
.with_expect_proxy(expect_proxy)
.with_sticky_name(sticky_name)
.with_front_timeout(front_timeout)
Expand Down
4 changes: 2 additions & 2 deletions command/assets/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protocol = "http"
[[listeners]]
address = "0.0.0.0:443"
protocol = "https"
answer_404 = "./assets/custom_404.html"
answers = { "404" = "./assets/custom_404.html" }
tls_versions = ["TLS_V12"]

[[listeners]]
Expand All @@ -28,7 +28,7 @@ expect_proxy = true
[clusters]
[clusters.MyCluster]
protocol = "http"
answer_503 = "./assets/custom_503.html"
answers = { "503" = "./assets/custom_503.html" }
#sticky_session = false
#https_redirect = false
frontends = [
Expand Down
7 changes: 7 additions & 0 deletions command/assets/custom_200.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
HTTP/1.1 200 OK
%Content-Length: %CONTENT_LENGTH
Sozu-Id: %REQUEST_ID

<h1>%CLUSTER_ID Custom 200</h1>
<p>original url: %ROUTE</p>
<p>rewritten url: %REDIRECT_LOCATION</p>
4 changes: 2 additions & 2 deletions command/assets/custom_404.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
HTTP/1.1 404 Not Found
Cache-Control: no-cache
Connection: close
Sozu-Id: %SOZU_ID
Sozu-Id: %REQUEST_ID

<h1>My own 404 error page</h1>
<p>Your request %SOZU_ID found no frontend and cannot be redirected.</p>
<p>Your request %REQUEST_ID found no frontend and cannot be redirected.</p>
6 changes: 3 additions & 3 deletions command/assets/custom_503.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
Cache-Control: no-cache
Connection: close
%Content-Length: %CONTENT_LENGTH
Sozu-Id: %SOZU_ID
Sozu-Id: %REQUEST_ID

<h1>MyCluster: 503 Service Unavailable</h1>
<p>No server seems to be alive, could not redirect request %SOZU_ID.</p>
<p>No server seems to be alive, could not redirect request %REQUEST_ID.</p>
<pre>
%DETAILS
%MESSAGE
<pre>
52 changes: 24 additions & 28 deletions command/src/command.proto
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ message HttpListenerConfig {
required uint32 request_timeout = 10 [default = 10];
// wether the listener is actively listening on its socket
required bool active = 11 [default = false];
optional CustomHttpAnswers http_answers = 12;
map<string, string> answers = 13;
}

// details of an HTTPS listener
Expand Down Expand Up @@ -161,7 +161,7 @@ message HttpsListenerConfig {
// The tickets allow the client to resume a session. This protects the client
// agains session tracking. Defaults to 4.
required uint64 send_tls13_tickets = 20;
optional CustomHttpAnswers http_answers = 21;
map<string, string> answers = 22;
}

// details of an TCP listener
Expand All @@ -179,31 +179,6 @@ message TcpListenerConfig {
required bool active = 7 [default = false];
}

// custom HTTP answers, useful for 404, 503 pages
message CustomHttpAnswers {
// MovedPermanently
optional string answer_301 = 1;
// BadRequest
optional string answer_400 = 2;
// Unauthorized
optional string answer_401 = 3;
// NotFound
optional string answer_404 = 4;
// RequestTimeout
optional string answer_408 = 5;
// PayloadTooLarge
optional string answer_413 = 6;
// BadGateway
optional string answer_502 = 7;
// ServiceUnavailable
optional string answer_503 = 8;
// GatewayTimeout
optional string answer_504 = 9;
// InsufficientStorage
optional string answer_507 = 10;

}

message ActivateListener {
required SocketAddress address = 1;
required ListenerType proxy = 2;
Expand Down Expand Up @@ -237,6 +212,18 @@ message ListenersList {
map<string, TcpListenerConfig> tcp_listeners = 3;
}

enum RedirectPolicy {
FORWARD = 0;
PERMANENT = 1;
UNAUTHORIZED = 2;
}

enum RedirectScheme {
USE_SAME = 0;
USE_HTTP = 1;
USE_HTTPS = 2;
}

// An HTTP or HTTPS frontend, as order to, or received from, Sōzu
message RequestHttpFrontend {
optional string cluster_id = 1;
Expand All @@ -247,6 +234,13 @@ message RequestHttpFrontend {
required RulePosition position = 6 [default = TREE];
// custom tags to identify the frontend in the access logs
map<string, string> tags = 7;
optional RedirectPolicy redirect = 8;
optional bool required_auth = 9;
optional RedirectScheme redirect_scheme = 10;
optional string redirect_template = 11;
optional string rewrite_host = 12;
optional string rewrite_path = 13;
optional uint32 rewrite_port = 14;
}

message RequestTcpFrontend {
Expand Down Expand Up @@ -374,8 +368,10 @@ message Cluster {
required bool https_redirect = 3;
optional ProxyProtocolConfig proxy_protocol = 4;
required LoadBalancingAlgorithms load_balancing = 5 [default = ROUND_ROBIN];
optional string answer_503 = 6;
optional LoadMetric load_metric = 7;
optional uint32 https_redirect_port = 8;
map<string, string> answers = 9;
repeated uint64 authorized_hashes = 10;
}

enum LoadBalancingAlgorithms {
Expand Down
Loading
Loading