Skip to content

Commit

Permalink
update request header variables where possible (ngrok#759)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminchan authored May 30, 2024
1 parent e5984f8 commit 33076ca
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 54 deletions.
159 changes: 117 additions & 42 deletions docs/http/_http_header_templates.mdx

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/http/request-headers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ For example to include geographical data about the client IP that initiated the
request, you may construct a header value like so.

```bash
ngrok http 80 --request-header-add 'country: ${.ngrok.geo.country_code}'
ngrok http 80 --request-header-add 'country: ${conn.geo.country_code}'
```

If you are specifying variable interpolation from the command line, make sure
Expand Down Expand Up @@ -245,7 +245,7 @@ with `Ctrl+C` and then restart ngrok with a new command.
ngrok http https://httpbin.org \
--domain your-domain.ngrok.app \
--request-header-remove='user-agent' \
--request-header-add='country: ${.ngrok.geo.country_code}'
--request-header-add='country: ${conn.geo.country_code}'
```

Then curl your endpoint again to see how the request headers have been updated:
Expand Down
2 changes: 1 addition & 1 deletion examples/actions/add-headers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const type = "add-headers";
export const config = {
headers: {
"is-ngrok": "1",
country: "${.ngrok.geo.country_code}",
country: "${conn.geo.country_code}",
},
};

Expand Down
2 changes: 1 addition & 1 deletion examples/agent-cli/http-request-headers.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
```bash
ngrok http 80 \
--request-header-add='is-ngrok: 1' \
--request-header-add='country: ${.ngrok.geo.country_code}' \
--request-header-add='country: ${conn.geo.country_code}' \
--request-header-remove='referrer'
```
2 changes: 1 addition & 1 deletion examples/agent-config/http-request-headers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ tunnels:
proto: http
addr: 80
request_header:
add: ["is-ngrok: 1", "country: ${.ngrok.geo.country_code}"]
add: ["is-ngrok: 1", "country: ${conn.geo.country_code}"]
remove: ["referrer"]
```
2 changes: 1 addition & 1 deletion examples/go-sdk/http-request-headers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func ngrokListener(ctx context.Context) (net.Listener, error) {
return ngrok.Listen(ctx,
config.HTTPEndpoint(
config.WithRequestHeader("is-ngrok", "1"),
config.WithRequestHeader("country", "${.ngrok.geo.country_code}"),
config.WithRequestHeader("country", "${conn.geo.country_code}"),
config.WithRemoveRequestHeader("referrer"),
),
ngrok.WithAuthtokenFromEnv(),
Expand Down
2 changes: 1 addition & 1 deletion examples/javascript-sdk/http-request-headers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const ngrok = require("@ngrok/ngrok");
const listener = await ngrok.forward({
addr: 8080,
authtoken_from_env: true,
request_header_add: ["is-ngrok:1", "country:${.ngrok.geo.country_code}"],
request_header_add: ["is-ngrok:1", "country:${conn.geo.country_code}"],
request_header_remove: "referrer",
});

Expand Down
2 changes: 1 addition & 1 deletion examples/k8s/http-request-headers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ modules:
request:
add:
is-ngrok: "1"
country: "${.ngrok.geo.country_code}"
country: "${conn.geo.country_code}"
remove: ["referrer"]
---
apiVersion: networking.k8s.io/v1
Expand Down
2 changes: 1 addition & 1 deletion examples/python-sdk/http-request-headers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import ngrok

listener = ngrok.forward("localhost:8080", authtoken_from_env=True,
request_header_add=["is-ngrok:1", "country:${.ngrok.geo.country_code}"],
request_header_add=["is-ngrok:1", "country:${conn.geo.country_code}"],
request_header_remove="referrer")

print(f"Ingress established at: {listener.url()}");
Expand Down
2 changes: 1 addition & 1 deletion examples/rust-sdk/http-request-headers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async fn listen_ngrok() -> anyhow::Result<impl Tunnel> {
let tun = sess
.http_endpoint()
.request_header("is-ngrok", "1")
.request_header("country", "${.ngrok.geo.country_code}")
.request_header("country", "${conn.geo.country_code}")
.remove_request_header("referrer")
.listen()
.await?;
Expand Down
2 changes: 1 addition & 1 deletion examples/ssh/http-request-headers.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
```bash
ssh -R 443:localhost:80 [email protected] http \
--request-header-add='is-ngrok: 1' \
--request-header-add='country: ${.ngrok.geo.country_code}' \
--request-header-add='country: ${conn.geo.country_code}' \
--request-header-remove='referrer'
```
2 changes: 1 addition & 1 deletion src/components/VariableInterpolation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ConfigExample from "../../src/components/ConfigExample.tsx";

export const config = {
headers: {
country: "${.ngrok.geo.country_code}",
country: "${conn.geo.country_code}",
},
};

Expand Down

0 comments on commit 33076ca

Please sign in to comment.