Response Headers
Overview
This module adds and removes headers from the HTTP response before it is returned to the client. This is useful for stripping internal headers or enforcing the use of security headers without modifying your upstream service.
You may interpolate variables into header values to make them dynamic.
Example Usage
- Agent CLI
- Agent Config
- SSH
- Go
- Javascript
- Python
- Rust
- Kubernetes Controller
Loading…
Loading…
Loading…
Loading…
Go Package Docs:
Loading…
Javascript SDK Docs:
- https://ngrok.github.io/ngrok-javascript/interfaces/Config.html#response_header_add
- https://ngrok.github.io/ngrok-javascript/interfaces/Config.html#response_header_remove
- https://ngrok.github.io/ngrok-javascript/classes/HttpListenerBuilder.html#responseHeader
- https://ngrok.github.io/ngrok-javascript/classes/HttpListenerBuilder.html#removeResponseHeader
Loading…
Python SDK Docs:
Loading…
Rust Crate Docs:
Loading…
Behavior
Variable Interpolation
You may interpolate variables into header values. Variables are interpolated
into headers with JSONPath expressions surrounded by the ${}
syntax.
For example to return to the duration spent dialing the upstream service, you may construct a header value like so.
Loading…
If you are specifying variable interpolation from the command line, make sure to use single quotes for the command line argument otherwise it is likely that the shell will interpret your variable definition.
Consult the Variables Reference for the available variables.
Multiple Header Values
HTTP headers may include the same header multiple times. You may add a header multiple times with different values and it will be added multiple times. For example:
Loading…
will result in a header with multiple values set
Loading…
There is a bug which currently causes the above behavior not to be correct. Only the last header will be used when specifying multiple headers. This behavior will be fixed to match what is documented above.
If you remove a header that has multiple values, all values will be removed.
Replacing Header Values
If you add a header that is already present in the HTTP response, it will add another header. For example, if you run:
Loading…
And the HTTP response from the upstream server was:
Loading…
The client will receive the following:
Loading…
If you wish to replace a header, you can combine header removal and addition to achieve that effect.
Loading…
This will cause the HTTP response in this case to become:
Loading…
Case Sensitivity
When adding headers, ngrok normalizes all header keys to a lower case representation per the http/2 RFC. See RFC 7540.
When removing headers, ngrok will remove any headers that match with a case-insensitive comparison.
Ordering
Response header changes made by other modules can be overridden by this module because this module is executed immediately before the HTTP header is written to the client.
http_request_complete.v0 events include any header changes made by this module because those events are published after this module executes.
Reference
Configuration
Parameter | Description |
---|---|
Added Headers | A list of header names to header values. Max 5. |
Removed Headers | A list of header names to remove. Max 5. |
Upstream Headers
This module does not add any upstream headers.
Errors
This module does not return any errors.
Events
This module does not populate any fields in events.
Edges
Response Headers is an HTTPS Edge module which can be applied to Routes.
Pricing
This module is available on all plans.
If you are not subscribed to a paid account, it is not permitted to remove the
ngrok-agent-ip
header. This header is part of ngrok's abuse deterrence
mechanism.
Variables
ngrok makes variables available for interpolation into headers.
Some variables will only be populated with values if you have configured the
corresponding module for your endpoint, otherwise they will be empty. For
example, the variable ${.basic_auth.username}
is only available if you have
enabled the basic auth module on your endpoint.
Backend Variables
${.backend.connection_reused} | True if ngrok reused a TCP connection to transmit the HTTP request to the upstream service. |
${.backend.dial_duration} | The time to establish a connection from ngrok to the agent. |
${.backend.id} | This is the ngrok ID of the backend that serviced this request. This is empty if the endpoint is not handled by an Edge. |
Basic Auth Variables
These variables are only populated when using the Basic Auth module.
${.basic_auth.decision} | allow if the request successfully authenticated via the Basic Auth module, block otherwise. |
${.basic_auth.username} | If the request successfully authenticated via the Basic Auth module, this is the username that authenticated. |