openresty / openresty/lua-nginx-module

ngx.location.capture + proxy_pass return value is empty

Open
#1,839 0 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

When I try to use ngx.location.capture + proxy_pass to make a subrequest,
I find that no matter how I configure it, the return value is empty.
How can I configure it to achieve the correct return of the subrequest?

ps: I have confirmed that the sub-request has been successful, and the server returns 200

nginx version: nginx/1.14.0

lua-nginx-module-0.10.13

nginx config

...
    upstream authserver {
        server 192.168.31.152:5001;
    }
...

location /lua {
            # default_type 'text/plain';
            # content_by_lua 'ngx.say("/lua")';
            content_by_lua_file /lua/content.lua;
        }
        location /api/post/ {
            # internal;
            proxy_pass http://authserver/api/access/auth?source=;
            # health_check;
            # content_by_lua 'ngx.say("/api/post")';
            # proxy_read_timeout 3600;
        }

content.lua

local res = ngx.location.capture("/api/post/",{method=ngx.HTTP_POST,always_forward_body=true,body='',args= { arg='auth'}})
        ngx.say("request successed")
        -- ngx.say(res)
        if not res then
            for key, value in pairs(res) do
                ngx.say(key+":"+value)
            end
             -- ngx.say(res);
            ngx.say(res.state)
            ngx.say(res.body)
            -- ngx.say(res)
        else
            ngx.say("result is null")
        end

result

request successed
result is null

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

Start with the nginx locations and upstream configuration in the issue, then inspect content.lua and the ngx.location.capture entry point. Reproduce the request with the stated nginx and lua-nginx-module versions; done means the captured subrequest result is returned with a documented, reproducible configuration.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.