前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >nginx子请求与addtion filter模块分析

nginx子请求与addtion filter模块分析

原创
作者头像
stan1ey
修改2021-08-11 14:47:41
7440
修改2021-08-11 14:47:41
举报
文章被收录于专栏:安全开发记录安全开发记录

配置示例:

server {

root /var/www/html;

index main.html main.htm;

listen 127.0.0.1:999;

location / {

add_before_body /before.html;

add_after_body /after.html;

}

}

返回:

curl 127.0.0.1:999

before

main

after

流程分析:

主请求:在ngx_http_addition_body_filter中,调用ngx_http_subrequest,创建第一子请求。

主请求:ngx_http_postpone_filter中,将主请求的返回in,加入r→postponed。

主请求:在ngx_http_addition_body_filter中,调用ngx_http_subrequest,创建第二子请求。

主请求:ngx_http_finalize_request,因为主请求下有postponed,set_writer_handler设置write_event_handler。

主请求:ngx_http_run_posted_requests,开始处理子请求,此时里面有第一子请求,第二子请求。

第一子请求:ngx_http_postpone_filter中因为它没有子请求,in直接加到r→main的chain中,等待发送。

第一子请求:ngx_http_finalize_request,c→data指针移交给主请求,同时将主请求加入到posted_requests,等到被调用时,posted_requests中为第二子请求和主请求。

第二子请求:ngx_http_postpone_filter中,因为c→data不指向第二子请求,不具备发送能力,将生成的返回加入第二子请求的postponed中。

第二子请求:ngx_http_finalize_request,第二子请求下有postponed,调用set_writer_handler设置write_event_handler回调,ngx_http_run_posted_requests开始遍历到主请求,此时为posted_requests仅为主请求。

主请求:ngx_http_postpone_filter中,遍历自己的postponed,将自己生成的返回加入chain,将c→data设置为第二子请求,将第二子请求加入posted_requests。

主请求:ngx_http_finalize_request,set_writer_handler设置write_event_handler,继续遍历到第二子请求。

第二子请求:ngx_http_postpone_filter中,发送它自己postponed下的返回。

第二子请求:ngx_http_finalize_request,c→data此时等于它本身,顺利结束,最后不忘将主请求加回posted_requests。

主请求:ngx_http_postpone_filter,ngx_http_finalize_request,发送数据ngx_http_post_action。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 配置示例:
  • 流程分析:
相关产品与服务
应用安全开发
应用安全开发(Application Security Development,下文中也叫 Xcheck)为您提供优质的代码分析服务。Xcheck 凭借优秀的算法和工程实现,能在极低的误报率和漏报率前提下,以极快的速度发现代码中存在的安全漏洞。Xcheck 采用私有化部署的模式,所以产品使用的整个生命周期,源码都不会流出公司网络,杜绝源码泄露风险。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档