New directive tricot-add-redirect <match-prefix> <redirect-prefix> [301|302|303|307]
#10
1 changed files with 8 additions and 14 deletions
|
@ -144,16 +144,10 @@ impl ProxyEntry {
|
||||||
let mut redirects = vec![];
|
let mut redirects = vec![];
|
||||||
for mid in middleware.into_iter() {
|
for mid in middleware.into_iter() {
|
||||||
match mid {
|
match mid {
|
||||||
ConfigTag::AddHeader(k, v) => add_headers.push((k.to_string(), v.to_string())),
|
ConfigTag::AddHeader(k, v) => add_headers.push((k.to_string(), v.clone())),
|
||||||
ConfigTag::AddRedirect(m, r, c) => redirects.push(((*m).clone(), (*r).clone(), *c)),
|
ConfigTag::AddRedirect(m, r, c) => redirects.push(((*m).clone(), (*r).clone(), *c)),
|
||||||
ConfigTag::LocalLb =>
|
ConfigTag::LocalLb | ConfigTag::GlobalLb => {
|
||||||
/* handled in parent fx */
|
/* handled in parent fx */
|
||||||
{
|
|
||||||
()
|
|
||||||
}
|
|
||||||
ConfigTag::GlobalLb =>
|
|
||||||
/* handled in parent fx */
|
|
||||||
{
|
|
||||||
()
|
()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -251,7 +245,7 @@ enum MatchTag {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum ConfigTag<'a> {
|
enum ConfigTag<'a> {
|
||||||
AddHeader(&'a str, &'a str),
|
AddHeader(&'a str, String),
|
||||||
AddRedirect(UrlPrefix, UrlPrefix, u32),
|
AddRedirect(UrlPrefix, UrlPrefix, u32),
|
||||||
GlobalLb,
|
GlobalLb,
|
||||||
LocalLb,
|
LocalLb,
|
||||||
|
@ -280,8 +274,8 @@ fn parse_tricot_tags(tag: &str) -> Option<ParsedTag> {
|
||||||
UrlPrefix::new(raw_prefix)
|
UrlPrefix::new(raw_prefix)
|
||||||
.map(|prefix| ParsedTag::Frontend(MatchTag::HttpWithTls(prefix, priority)))
|
.map(|prefix| ParsedTag::Frontend(MatchTag::HttpWithTls(prefix, priority)))
|
||||||
}
|
}
|
||||||
["tricot-add-header", header_key, header_value] => Some(ParsedTag::Middleware(
|
["tricot-add-header", header_key, header_values @ ..] => Some(ParsedTag::Middleware(
|
||||||
ConfigTag::AddHeader(header_key, header_value),
|
ConfigTag::AddHeader(header_key, header_values.join(" ")),
|
||||||
)),
|
)),
|
||||||
["tricot-add-redirect", raw_match, raw_replace, maybe_raw_code @ ..] => {
|
["tricot-add-redirect", raw_match, raw_replace, maybe_raw_code @ ..] => {
|
||||||
let (p_match, p_replace) =
|
let (p_match, p_replace) =
|
||||||
|
@ -525,8 +519,8 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_tricot_add_header_tag() {
|
fn test_parse_tricot_add_header_tag() {
|
||||||
match parse_tricot_add_header_tag("tricot-add-header Content-Security-Policy default-src 'none'; img-src 'self'; script-src 'self'; style-src 'self'") {
|
match parse_tricot_tags("tricot-add-header Content-Security-Policy default-src 'none'; img-src 'self'; script-src 'self'; style-src 'self'") {
|
||||||
Some((name, value)) => {
|
Some(ParsedTag::Middleware(ConfigTag::AddHeader(name, value))) => {
|
||||||
assert_eq!(name, "Content-Security-Policy");
|
assert_eq!(name, "Content-Security-Policy");
|
||||||
assert_eq!(value, "default-src 'none'; img-src 'self'; script-src 'self'; style-src 'self'");
|
assert_eq!(value, "default-src 'none'; img-src 'self'; script-src 'self'; style-src 'self'");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue