Skip to content

Instantly share code, notes, and snippets.

@john-auld
Created March 28, 2019 14:16
Show Gist options
  • Save john-auld/7069e50efc4a64ee1a1f37e880d4c678 to your computer and use it in GitHub Desktop.
Save john-auld/7069e50efc4a64ee1a1f37e880d4c678 to your computer and use it in GitHub Desktop.
nxinx-lua dump request headers

Basic example of lua code to dump request headers

This code will dump the request headers into the response body of an nginx location. It is intended for degugging development and not for production. The code has been tested on OpenResty.

nginx location

location /status {
   default_type text/html;
   lua_code_cache off; #enables livereload for development
   content_by_lua_file lua/status_page.lua;
}

lua file

ngx.say('<pre>' .. ngx.req.raw_header() .. '</pre>')

Sample output

GET /status HTTP/1.1
X-Forwarded-For: 192.168.1.10
X-Forwarded-Proto: https
X-Forwarded-Port: 443
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment