chaoslawful/lua-nginx-module — pull request #318 by aviramc (2013-12-19 05:53:38+00:00)
Title: Subrequest headers copying

When ngx_lua creates a subrequest, it performs the following line:

`sr->headers_in = r->headers_in;`

Where `sr` is the subrequest object and `r` is the parent request object.

This performs a shallow copy of the headers_in structure, copying the built-in headers and the list of headers.
Later on, the subrequest's list of headers is re-initiated with a deep copy of the headers (this happens either in ` ngx_http_lua_copy_request_headers` or in `ngx_http_lua_set_content_length_header`).
However, the fields of the built-in headers still point to the list of headers of the main request.

This causes two main issues:

- The built-in headers aren't really changeable in the context of the subrequest.
- When changing the built-in headers in the context of the subrequest, it may change the values of the built-in headers of the main request.

Therefore, I'm offering the following patch, that would perform a real deep-copy of the main request's headers_in structure to the one of the subrequest.