nginx采用遍历ngx_list_t获取源码列表中没有的http头部变量的方法
来源:互联网 发布:高效程序员的狂暴之路 编辑:程序博客网 时间:2024/06/07 07:22
nginx源码中,已解析好的字段存在如下结构体中
typedef struct { ngx_list_t headers; ngx_table_elt_t *host; ngx_table_elt_t *connection; ngx_table_elt_t *if_modified_since; ngx_table_elt_t *if_unmodified_since; ngx_table_elt_t *if_match; ngx_table_elt_t *if_none_match; ngx_table_elt_t *user_agent; ngx_table_elt_t *referer; ngx_table_elt_t *content_length; ngx_table_elt_t *content_type; ngx_table_elt_t *range; ngx_table_elt_t *if_range; ngx_table_elt_t *transfer_encoding; ngx_table_elt_t *expect; ngx_table_elt_t *upgrade;#if (NGX_HTTP_GZIP) ngx_table_elt_t *accept_encoding; ngx_table_elt_t *via;#endif ngx_table_elt_t *authorization; ngx_table_elt_t *keep_alive;#if (NGX_HTTP_X_FORWARDED_FOR) ngx_array_t x_forwarded_for;#endif#if (NGX_HTTP_REALIP) ngx_table_elt_t *x_real_ip;#endif#if (NGX_HTTP_HEADERS) ngx_table_elt_t *accept; ngx_table_elt_t *accept_language;#endif#if (NGX_HTTP_DAV) ngx_table_elt_t *depth; ngx_table_elt_t *destination; ngx_table_elt_t *overwrite; ngx_table_elt_t *date;#endif ngx_str_t user; ngx_str_t passwd; ngx_array_t cookies; ngx_str_t server; off_t content_length_n; time_t keep_alive_n; unsigned connection_type:2; unsigned chunked:1; unsigned msie:1; unsigned msie6:1; unsigned opera:1; unsigned gecko:1; unsigned chrome:1; unsigned safari:1; unsigned konqueror:1;} ngx_http_headers_in_t;
对于http头中没有解析的字段,nginx将其存放在了ngx_list_t类型变量headers中,只要对该list进行遍历,即可找到相应字段
相应代码如下:
ngx_list_part_t *part = &r->headers_in.headers.part;ngx_table_elt_t *header = part->elts;//开始遍历链表for(i = 0;/*void*/;i++){//判断是否到达链表中当前数组结尾if(i>=part->nelts){//是否还有下一个链表数组元素if(part->next == NULL){break;}//part设置为next来访问下一个链表数组;header也指向下一个链表数组的首地址,设置i为0,表示从头开始遍历新的链表数组。part = part->next;header = part->elts;i=0;}//hash为0表示不是合法的头部if(header[i].hash == 0){continue;}//判断当前头部是否是“XXX-key”,如果想要忽略大小写,则应先用header[i].lowcase_key代替header[i].key.data,然后比较字符串。if(0 == ngx_strncasecmp(header[i].key.data,(u_char*) "XXX-key",header[i].key.len)){//判断头部的值是否是“XXX-value”if(0 == ngx_strncmp(header[i].key.data,"XXX-value",header[i].value.len)){//找到之后继续处理}}}
0 0
- nginx采用遍历ngx_list_t获取源码列表中没有的http头部变量的方法
- nginx的单链表--ngx_list_t
- AS3获取http头部的方法
- nginx源码分析之ngx_list_t
- Nginx源码阅读(ngx_list_t)
- Nginx获取自定义头部header的值
- 遍历perl中匹配变量的方法
- Nginx源码分析---链表结构ngx_list_t
- 文章3:Nginx源码分析-ngx_list_t单链表
- nginx 源码学习(五) 基本数据结构 ngx_list_t
- 8.nginx源码分析之数据结构:ngx_list_t
- 在Insert Into...中采用变量的方法
- HTTP状态码,http头部获取的Status
- nginx处理post请求(http响应头部的收发)
- Nginx变量的源码分析
- Post请求鉴权中获取头部的方法
- DIV标签中列表的获取方法
- 从列表中获取文件名称的方法
- 微信小程序例子——获取手机网络状态
- 乱搞
- [React-native]第一行代码Helloworld及集成已有项目的方案
- [暴力 乱搞] 51Nod 1616 算法马拉松19 B 最小集合
- IE兼容问题解决方案——指定文件兼容性为content="IE=Edge,chrome=1"(可以解决很多的问题)
- nginx采用遍历ngx_list_t获取源码列表中没有的http头部变量的方法
- 【深度学习】笔记5_caffe数据层参数的详解
- 用JAVA刷OJ万年超时?今天解决它~
- 课堂整理(四)-----端口号整理
- 自定义View为view添加选中边框
- [数学] 51Nod 1622 算法马拉松19 C 集合对
- sizeof关键字
- Building the main Guest Additions module
- ThreadLocal用法和实现原理