openresty / openresty/lua-nginx-module

in body_filter_by_lua get all resopnse send Third party services

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

openResty 1.1.1c
Here is my code snippet
nginx.conf
server {
listen 7788;

	location /kk {
		access_by_lu_file  access.lua;
                     header_filter_by_lua_file   header.lua;
                     body_filter_by_lua_file   header.lua;
                     proxy_pass http://127.0.0.1/uri;
	}
}

body.lua

local socket = require"resty.handler"
if ngx.arg[1] ~= "" then
socket:body_filter()
socket:sendBody()
end

if ngx.ctx.encrypt then
local chunk, eof = ngx.arg[1], ngx.arg[2]
local buffered = ngx.ctx.buffered
if not buffered then
buffered = {}
end

if chunk ~= "" then
	buffered[#buffered + 1] = chunk
	ngx.arg[1] = nil
end

if eof then
	local whole = table.concat(buffered)
	
	ngx.arg[1] = ngx.encode_base64(whole)
end

end

handler.lua

     local M = {_VERSION = '0.0.1'}

    function _M.body_filter()

-- body
local chunk, eof = ngx.arg[1], ngx.arg[2]
local buffered = ngx.ctx.buffered
if not buffered then
	buffered = {}
end

if chunk ~= "" then
	buffered[#buffered + 1] = chunk
	ngx.arg[1] = nil
end

if eof then
	local whole = table.concat(buffered)
	
	ngx.ctx.response_body = whole
end

end

function _M.sendBody()

-- body
--lua tcp send response_body
socket.send(ngx.ctx.response_body)

end
return _M

when ngx.ctx.encrypt == true I can get ngx.ctx.respnse_body and send response

but else ngx.ctx.encrypt == false I can not get ngx.ctx.respnse_body and ngx.ctx.response_body = ""

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.conf configuration and compare the body_filter_by_lua_file flow in body.lua with handler.lua. Reproduce the encrypt=false case and trace when ngx.ctx.response_body is assigned and read. Done means the cause of the empty value is identified and the response body is reliably available in the intended 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
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.