openresty / openresty/lua-nginx-module

Problem with post request reading in balancer_by_lua_block

Open
#2,289 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
11.8k
Forks
2.1k
Avg merge
6h 1m
Merged PRs (30d)
6

Description

hi
the openresty version of mine is 1.13

I encountered a problem. When I am in the balance_by_lua stage, without ngx.req.read_body(), I can use the get_post_args function to read the parameters of the post; but in the access_by_lua stage, an error will appear; Why is get_post_args() can be used normally in the balance_by_lua stage without ngx.req.read_body()? 

tips:
	1、It has been confirmed that lua_need_request_body is not turned on

	2、ngx.req.read_body() is not read in other stages.

reproduction on the case:

upstream hash-forward {
    server 0.0.0.1;  

    balancer_by_lua_block {
        local ngx = require "ngx"
        local cjson = require "cjson.safe"
        local method = ngx.var.request_method

        if method == "POST" then
            local post_args, err = ngx.req.get_post_args()
            if not post_args then
                ngx.log(ngx.ERR, "failed to get post args: ", err)
                return ngx.exit(500)
            end
            local post_str = cjson.encode(post_args)
            
            ngx.log(ngx.ERR, "post params: " .. post_str)
        end

        local balancer = require "ngx.balancer"
        local ok, err = balancer.set_current_peer("127.0.0.1", 8088)
        if not ok then
            ngx.log(ngx.ERR, "failed to set the current peer: ", err)
            return ngx.exit(500)
        end
    }

    keepalive 500;  # connection pool
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the supplied upstream configuration on OpenResty 1.13, comparing ngx.req.get_post_args() in balancer_by_lua_block and access_by_lua with ngx.req.read_body() and lua_need_request_body disabled. Start with the request-body handling entry points for these phases; done means identifying the cause of the differing behavior and documenting or fixing the affected path.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, nginx
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.