openresty / openresty/lua-nginx-module

Appending keys to ngx.req and ngx.resp

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

Is it a bad idea to append new keys to ngx.req/resp? For example, would the following be considered bad?

if ngx.var.request_method == 'POST' then
  ngx.req.read_body()
  ngx.req.rawBody = ngx.req.get_body_data()
  if ngx.headers['content-type'] == 'application/json' then
    local ok, payload = pcall(cjson.decode, ngx.req.get_body_data())
    if ok then
      ngx.req.body = payload
    end
  end
end

So that I can automatically parse the post body in the instantiation of my app, and then just pass around ngx.req and ngx.resp to all my controllers?

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

No file or test is identified; begin with the ngx.req and ngx.resp API entry points named in the issue. A complete outcome would need a maintainer decision on whether these extensions are supported and a specified code or documentation target.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, nginx
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.