NGINX Modern Apps > Class 3 - NGINX Dataplane Scripting Source | Edit on
Modifying or deleting cookies sent by the upstream server [http/response/modify_set_cookie]¶
NGINX Javascript uses the js_header_filter directive to modify headers sent by the upstream server before they are proxied back to the client. In this example, we remove any cookie that is shorter than the minimum length specified in a len argument on the query string.
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¶
The upstream server listens on port 8080 and returns three Set-Cookie headers. In the server block listening on port 80, we proxy requests to the upstream, but call the main.cookies_filter method to inspect the headers returned.
This njs code copies the response headers to a “cookies” variable and then creates a new set of headers that includes only the cookies that are longer than the length specified in the len argument.