Skip to content

Commit

Permalink
update example to use traffic policy vs policy
Browse files Browse the repository at this point in the history
  • Loading branch information
TheConcierge committed Jul 9, 2024
1 parent 39d6e0b commit ec7bae8
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions ngrok/examples/axum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async fn start_tunnel() -> anyhow::Result<HttpTunnel> {
// .allow_domain("<domain>")
// .scope("<scope>"),
// )
// .policy(create_policy())?
// .traffic_policy(POLICY_JSON)
// .proxy_proto(ProxyProto::None)
// .remove_request_header("X-Req-Nope")
// .remove_response_header("X-Res-Nope")
Expand All @@ -80,27 +80,26 @@ async fn start_tunnel() -> anyhow::Result<HttpTunnel> {
Ok(tun)
}

#[allow(dead_code)]
fn create_policy() -> Result<Policy, InvalidPolicy> {
Ok(Policy::new()
.add_inbound(
Rule::new("deny_put")
.add_expression("req.Method == 'PUT'")
.add_action(Action::new("deny", None)?),
)
.add_outbound(
Rule::new("200_response")
.add_expression("res.StatusCode == '200'")
.add_action(Action::new(
"custom-response",
Some(
r###"{
"status_code": 200,
"content_type": "text/html",
"content": "Custom 200 response."
}"###,
),
)?),
)
.to_owned())
}
const POLICY_JSON: &str = r###"{

Check failure on line 83 in ngrok/examples/axum.rs

View workflow job for this annotation

GitHub Actions / Clippy

constant `POLICY_JSON` is never used

Check warning on line 83 in ngrok/examples/axum.rs

View workflow job for this annotation

GitHub Actions / Test Stable

constant `POLICY_JSON` is never used

Check warning on line 83 in ngrok/examples/axum.rs

View workflow job for this annotation

GitHub Actions / Udeps

constant `POLICY_JSON` is never used
"Inbound":[
{
"Name":"deny_put",
"Expressions":["req.Method == 'PUT'"],
"Actions":[{"Type":"deny"}]
}],
"Outbound":[
{
"Name":"test_out",
"Expressions":["res.StatusCode == '200'"],
"Actions":[{
"Type":"custom-response",
"Config":{
"status_code":201,
"content": "Custom 200 response.",
"headers": {
"content_type": "text/html"
}
}
}]
}]
}"###;

0 comments on commit ec7bae8

Please sign in to comment.