如何让NGX LUA模块的POST返回不是Chunk模式,而GET必须是Chunk模式的修改

针对中兴设备不支持HTTP1.0 Content-Length特性的问题,本文介绍了一种通过修改NGINX源码来支持Chunked传输模式的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

为了应对中兴的垃圾程序不支持 HTTP 1.0 的Content-Length 标签, 反而支持HTTP 1.1的 Chunk模式, 做了如下修改 :

修改的文件名    ngx_lua-0.7.5\src\ngx_http_lua_util.c      第500行左右

修改的函数名

ngx_int_t   ngx_http_lua_send_chain_link(ngx_http_request_t *r, ngx_http_lua_ctx_t *ctx, ngx_chain_t *in)
修改的内容

    llcf = ngx_http_get_module_loc_conf(r, ngx_http_lua_module);

    if (llcf->http10_buffering
        && !ctx->buffering
        && !ctx->headers_sent
        && r->http_version < NGX_HTTP_VERSION_11
        && r->headers_out.content_length_n < 0)
    {
        ctx->buffering = 1;
    }

    if (llcf->http10_buffering
        && !ctx->buffering
        && !ctx->headers_sent
        && r->method & NGX_HTTP_POST
        && r->headers_out.content_length_n < 0)
    {
        ctx->buffering = 1;
    }

    if (llcf->http10_buffering
        && !ctx->buffering
        && !ctx->headers_sent
        && r->method & NGX_HTTP_GET)
        //&& r->headers_out.content_length_n < 0)
    {
        ctx->buffering = 0;
    }


下来在修改NGINX的源码 

nginx-1.1.4\src\http\modules\ngx_http_chunked_filter_module.c    第69行的函数

函数名为 

static ngx_int_t  ngx_http_chunked_header_filter(ngx_http_request_t *r)

修改的内容如下:

static ngx_int_t
ngx_http_chunked_header_filter(ngx_http_request_t *r)
{
    ngx_http_core_loc_conf_t       *clcf;
    ngx_http_chunked_filter_ctx_t  *ctx;

    if (r->headers_out.status == NGX_HTTP_NOT_MODIFIED
        || r->headers_out.status == NGX_HTTP_NO_CONTENT
        || r != r->main
        || (r->method & NGX_HTTP_HEAD))
    {
        return ngx_http_next_header_filter(r);
    }

    clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
    if (r->headers_out.content_length_n == -1 || (r->method & NGX_HTTP_GET && clcf->chunked_transfer_encoding))
    {
        if (r->http_version < NGX_HTTP_VERSION_11) {
            r->keepalive = 0;

        } else {
            clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

langeldep

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值