NGINX Modern Apps > Class 3 - NGINX Dataplane Scripting Source | Edit on
Injecting HTTP header using stream proxy [stream/inject_header]¶
In this example we will use the stream module to inject a new header into an HTTP request in flight.
Step 1: Use the following commands to start your NGINX container with this lab’s files:
Step 2: Now let’s use curl to test our NGINX server:
Code Snippets¶
Instead of an http block, this config uses a stream block so we can use the js_filter directive to call our njs code.
This njs code uses a callback to read data from an incoming request until it sees the end of a line. It then inserts the new “Foo” header at that point in the data stream before removing the callback.