nginx http处理(write_filter响应数据发送过滤器)

        作为处理相应数据过滤器,ngx_http_write_filter_module起到了收集响应数据(包含buffer缓冲数据及本地文件 本地文件包含实际的静态文件及缓存文件)、使用定时器设置响应限速延时的功能。

        ngx_http_write_filter_module也是使用top_body_filter来挂载在body_filter链来处理的,不过write_filter通常位于处理链的最后一个,如下图的堆栈结构也能看到,write_filter是作为最后一个来处理并发送响应数据的过滤器。如下图是处理处理包体数据在经过write_filter处理时的堆栈结构。

            

        通过write_filter处理之后的buffer链中的数据(包括内存及文件)会被预先设置的send_chain函数通过网络处理来发送到请求端。write_filter处理的代码流程如下:

ngx_int_t
ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
{
  ...
    /*取得请求的连接*/
    c = r->connection;

    if (c->error) {  /*发现连接存在错误 直接返回错误*/
        return NGX_ERROR;
    }

    size = 0;
    flush = 0;
    sync = 0;
    last = 0;
    ll = &r->out;

    /* find the size, the flush point and the last link of the saved chain */

    for (cl = r->out; cl; cl = cl->next) {  /*响应的out链*/
        ll = &cl->next;

        ngx_log_debug7(NGX_LOG_DEBUG_EVENT, c->log, 0,
                       "write old buf t:%d f:%d %p, pos %p, size: %z "
                       "file: %O, size: %O",
                       cl->buf->temporary, cl->buf->in_file,
                       cl->buf->start, cl->buf->pos,
                       cl->buf->last - cl->buf->pos,
                       cl->buf->file_pos,
                       cl->buf->file_last - cl->buf->file_pos);

#if 1   /*检查out链中的buffer chain中保存的buffer数据 */
        if (ngx_buf_size(cl->buf) == 0 && !ngx_buf_special(cl->buf)) {
            ngx_log_error(NGX_LOG_ALERT, c->log, 0,
                          "zero size buf in writer "
                          "t:%d r:%d f:%d %p %p-%p %p %O-%O",
                          cl-&
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值