实际工作中,经常需要在响应头中添加某种信息,
这里提供一种在nginx响应头中添加信息的方法,供参考。
size_t w = 0;
size_t l = 0;
ngx_table_elt_t *h;
char *str = NULL;
l = header_value;
while(l > 0 )
{
l=l/10;
w++;
}
str = ngx_palloc(r->pool, w);
sprintf(str,"%ld", header_value);
ngx_str_t name = ngx_string("X-Original-Lvdy");
h = ngx_list_push(&r->headers_out.headers );
if(h == NULL){return 0;}
h->hash = 1;
h->key.len = name.len;
h->key.data = name.data;
h->value.len = w;
h->value.data = (u_char*)str;
实际工作中,经常需要在响应头中添加某种信息,
这里提供一种在nginx响应头中添加信息的方法,供参考。
size_t w = 0;
size_t l = 0;
ngx_table_elt_t *h;
char *str = NULL;
l = header_value;
while(l > 0 )
{
l=l/10;
w++;
}
str = ngx_palloc(r->pool, w);
sprintf(str,"%ld", header_value);
ngx_str_t name = ngx_string("X-Original-Lvdy");
h = ngx_list_push(&r->headers_out.headers );
if(h == NULL){return 0;}
h->hash = 1;
h->key.len = name.len;
h->key.data = name.data;
h->value.len = w;
h->value.data = (u_char*)str;