openresty / openresty/lua-nginx-module

Read proxied server response before sending the headers to the client

Open
#891 6 comments 7 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

I am reopening this because I did not get a clear answer on my previous issue raised
https://github.com/openresty/lua-nginx-module/issues/888

I am using openresty as a reverse proxy between a client and a service provider through the following steps

I am changing the headers coming from the client
I convert the GET method to POST and create a body to be passed to the proxied server.
The response coming back from the proxied server is then altered and sent to the client

The problem

As the final response sent back to the client is altered, I need to change the Content-Length to match the new content. I am able to read the response from the proxied server only in the body_filter_by_lua_file but at that stage, the headers are already sent.

In the header_filter_by_lua_file phase, I don't have access on the response ngx.args[1]

Currently, I am removing the Content-Length header making the response chunked which is causing a problem the client.

How can I send the correct content length back to the client?

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 by reading the header_filter_by_lua_file and body_filter_by_lua_file phases, then review the linked issue #888 for prior context. Determine how a proxied response can be fully read before its headers are sent, or whether the requested Content-Length behavior is supported, and verify the documented approach with a reverse-proxy response test.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, nginx
Domain
api, backend, networking
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.