Skip to content

Commit

Permalink
make the method configurable through the cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Geal authored and FlorentinDUBOIS committed Jul 13, 2022
1 parent f96d1ac commit af38431
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
4 changes: 4 additions & 0 deletions bin/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ pub enum HttpFrontendCmd {
hostname: String,
#[structopt(short = "p", long = "path", help="URL prefix of the frontend")]
path_begin: Option<String>,
#[structopt(short = "m", long = "method", help="HTTP method")]
method: Option<String>,
},
#[structopt(name = "remove")]
Remove {
Expand All @@ -255,6 +257,8 @@ pub enum HttpFrontendCmd {
hostname: String,
#[structopt(short = "p", long = "path", help="URL prefix of the frontend")]
path_begin: Option<String>,
#[structopt(short = "m", long = "method", help="HTTP method")]
method: Option<String>,
},
}

Expand Down
12 changes: 7 additions & 5 deletions bin/src/ctl/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1008,15 +1008,15 @@ pub fn remove_application(channel: Channel<CommandRequest,CommandResponse>, time
}

pub fn add_http_frontend(channel: Channel<CommandRequest,CommandResponse>,
timeout: u64, route: Route, address: SocketAddr, hostname: &str, path: &str,
https: bool)
-> Result<(), anyhow::Error> {
timeout: u64, route: Route, address: SocketAddr, hostname: &str, path: &str, method: Option<&str>,
https: bool) -> Result<(), anyhow::Error> {
if https {
order_command(channel, timeout, ProxyRequestData::AddHttpsFrontend(HttpFrontend {
route,
address,
hostname: String::from(hostname),
path: PathRule::Prefix(String::from(path)),
method: method.map(String::from),
position: RulePosition::Tree,
}))
} else {
Expand All @@ -1025,21 +1025,22 @@ pub fn add_http_frontend(channel: Channel<CommandRequest,CommandResponse>,
address,
hostname: String::from(hostname),
path: PathRule::Prefix(String::from(path)),
method: method.map(String::from),
position: RulePosition::Tree,
}))
}
}

pub fn remove_http_frontend(channel: Channel<CommandRequest,CommandResponse>,
timeout: u64, route: Route, address: SocketAddr, hostname: &str, path: &str,
https: bool)
-> Result<(), anyhow::Error> {
method: Option<&str>, https: bool) -> Result<(), anyhow::Error> {
if https {
order_command(channel, timeout, ProxyRequestData::RemoveHttpsFrontend(HttpFrontend {
route,
address,
hostname: String::from(hostname),
path: PathRule::Prefix(String::from(path)),
method: method.map(String::from),
position: RulePosition::Tree,
}))
} else {
Expand All @@ -1048,6 +1049,7 @@ pub fn remove_http_frontend(channel: Channel<CommandRequest,CommandResponse>,
address,
hostname: String::from(hostname),
path: PathRule::Prefix(String::from(path)),
method: method.map(String::from),
position: RulePosition::Tree,
}))
}
Expand Down
20 changes: 12 additions & 8 deletions bin/src/ctl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,23 @@ pub fn ctl(matches: Sozu) -> Result<(), anyhow::Error>{
SubCmd::Frontend{ cmd } => {
match cmd {
FrontendCmd::Http{ cmd } => match cmd {
HttpFrontendCmd::Add{ hostname, path_begin, address, route } => {
add_http_frontend(channel, timeout, route.into(), address, &hostname, &path_begin.unwrap_or("".to_string()), false)
HttpFrontendCmd::Add{ hostname, path_begin, address, method, route } => {
add_http_frontend(channel, timeout, route.into(), address, &hostname,
&path_begin.unwrap_or("".to_string()), method.as_deref(), false)
},
HttpFrontendCmd::Remove{ hostname, path_begin, address, route } => {
remove_http_frontend(channel, timeout, route.into(), address, &hostname, &path_begin.unwrap_or("".to_string()), false)
HttpFrontendCmd::Remove{ hostname, path_begin, address, method, route } => {
remove_http_frontend(channel, timeout, route.into(), address, &hostname,
&path_begin.unwrap_or("".to_string()), method.as_deref(), false)
},
},
FrontendCmd::Https{ cmd } => match cmd {
HttpFrontendCmd::Add{ hostname, path_begin, address, route } => {
add_http_frontend(channel, timeout, route.into(), address, &hostname, &path_begin.unwrap_or("".to_string()), true)
HttpFrontendCmd::Add{ hostname, path_begin, address, method, route } => {
add_http_frontend(channel, timeout, route.into(), address, &hostname,
&path_begin.unwrap_or("".to_string()), method.as_deref(), true)
},
HttpFrontendCmd::Remove{ hostname, path_begin, address, route } => {
remove_http_frontend(channel, timeout, route.into(), address, &hostname, &path_begin.unwrap_or("".to_string()), true)
HttpFrontendCmd::Remove{ hostname, path_begin, address, method, route } => {
remove_http_frontend(channel, timeout, route.into(), address, &hostname,
&path_begin.unwrap_or("".to_string()), method.as_deref(), true)
},
},
FrontendCmd::Tcp { cmd } => match cmd {
Expand Down

0 comments on commit af38431

Please sign in to comment.