about the Guide to Nginx Module Development

Evan Miller emmiller at gmail.com
Mon Aug 20 11:40:18 MSD 2007


Evan Miller wrote:
> To set a header, I think you'd use functions in the Headers module, 
> something like (making it up here):
> 
> ngx_http_headers_conf_t *hcf = ngx_http_get_module_loc_conf(r, 
> ngx_http_headers_module);
> 
> ngx_http_header_val_t *h = ngx_array_push(hcf->headers);
> 
> if (h == NULL) { return NGX_ERROR; }
> 
> h->value.hash = 1;
> h->value.key = ngx_string("X-My-Header");
> h->value.value = ngx_string("Some value");

Actually, I think you can get away with:

ngx_table_elt_t *out;

if ((out = ngx_list_push(&r->headers_out.headers)) == NULL) {
   return NGX_ERROR;
}

out->hash = 1;
out->key = ngx_string("X-My-Header");
out->value = ngx_string("Some value");

...

No need to mess with the Header module.






More information about the nginx mailing list