Empty headers_out in log phase

Hello,

I’m writing an nginx module but I’ve got a problem for getting
response headers. It’s using an NGX_HTTP_LOG_PHASE handler and I want
to have access to response headers sent to client. (with or without
proxy_pass)

And, in fact, the headers_out variable of request isn’t really
completed. When debugging module using gdb, in the log phase handler,
the headers_out variable is always like that:

headers_out = {
headers = {
last = 0x1ed5530,
part = {
elts = 0x1ec6250,
nelts = 1,
next = 0x0
},
size = 48,
nalloc = 20,
pool = 0x1ec6200
},
status = 304,
status_line = {
len = 0,
data = 0x0
},
server = 0x0,
date = 0x0,
content_length = 0x0,
content_encoding = 0x0,
location = 0x0,
refresh = 0x0,
last_modified = 0x0,
content_range = 0x0,
accept_ranges = 0x0,
www_authenticate = 0x0,
expires = 0x0,
etag = 0x0,
override_charset = 0x0,
content_type_len = 9,
content_type = {
len = 0,
data = 0x1ed1248 “text/html”
},
charset = {
len = 0,
data = 0x0
},
content_type_lowcase = 0x0,
content_type_hash = 0,
cache_control = {
elts = 0x0,
nelts = 0,
size = 0,
nalloc = 0,
pool = 0x0
},
content_length_n = -1,
date_time = 0,
last_modified_time = 1334219772
},

The headers_out array is containing the only request that I added
using “add_header” in location, and the “server”, “date”, etc…
variables are empty.

Do you know why there isn’t any value in headers_out structure? And do
you know how can I get these headers?

Thanks you very much in advance!
Samuel.

Hello!

On Fri, Apr 13, 2012 at 09:58:14PM +0200, Samuel ROZE wrote:

  pool = 0x1ec6200
location = 0x0,
  len = 0,
  nelts = 0,

using “add_header” in location, and the “server”, “date”, etc…
variables are empty.

Do you know why there isn’t any value in headers_out structure? And do
you know how can I get these headers?

The “Server”, “Date”, “Content-Length”, “Last-Modified” and other
standard headers aren’t normally exists in r->headers_out for
nginx’s own responses, they are instead constructed on the fly in
ngx_http_header_filter.c.

The r->headers_out structure either hold needed data (as
last_modified_time for the “Last-Modified” header) or just nothing
(as for the “Date” header, as it just uses current time).

Maxim D.