Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config flag to disable reading request body #162

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lapis/config.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
local insert
insert = table.insert
do
local _obj_0 = table
insert = _obj_0.insert
end
local config_cache, configs, default_config, merge_set, set, scope_meta, config, reset, run_with_scope, get_env, get
config_cache = { }
configs = { }
Expand All @@ -9,6 +12,7 @@ default_config = {
session_name = "lapis_session",
code_cache = "off",
num_workers = "1",
allow_read_body = true,
logging = {
queries = true,
requests = true
Expand Down
1 change: 1 addition & 0 deletions lapis/config.moon
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ default_config = {
session_name: "lapis_session"
code_cache: "off"
num_workers: "1"
allow_read_body: true -- set to false if you don't want lapis to ready request body (ideal for proxying)

logging: {
queries: true
Expand Down
18 changes: 13 additions & 5 deletions lapis/nginx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ do
escape_pattern, parse_content_disposition, build_url = _obj_0.escape_pattern, _obj_0.parse_content_disposition, _obj_0.build_url
end
local run_after_dispatch
run_after_dispatch = require("lapis.nginx.context").run_after_dispatch
do
local _obj_0 = require("lapis.nginx.context")
run_after_dispatch = _obj_0.run_after_dispatch
end
local config = require("lapis.config").get()
local flatten_params
flatten_params = function(t)
local _tbl_0 = { }
Expand Down Expand Up @@ -109,11 +113,15 @@ local ngx_req = {
return build_url(t.parsed_url)
end,
params_post = function(t)
if (t.headers["content-type"] or ""):match(escape_pattern("multipart/form-data")) then
return parse_multipart() or { }
if config.allow_read_body then
if (t.headers["content-type"] or ""):match(escape_pattern("multipart/form-data")) then
return parse_multipart() or { }
else
ngx.req.read_body()
return flatten_params(ngx.req.get_post_args())
end
else
ngx.req.read_body()
return flatten_params(ngx.req.get_post_args())
return { }
end
end,
params_get = function()
Expand Down
15 changes: 10 additions & 5 deletions lapis/nginx.moon
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import escape_pattern, parse_content_disposition, build_url from require "lapis.util"
import run_after_dispatch from require "lapis.nginx.context"

config = require"lapis.config".get!

flatten_params = (t) ->
{k, type(v) == "table" and v[#v] or v for k,v in pairs t}

Expand Down Expand Up @@ -72,12 +74,15 @@ ngx_req = {
build_url t.parsed_url

params_post: (t) ->
-- parse multipart if required
if (t.headers["content-type"] or "")\match escape_pattern "multipart/form-data"
parse_multipart! or {}
if config.allow_read_body
-- parse multipart if required
if (t.headers["content-type"] or "")\match escape_pattern "multipart/form-data"
parse_multipart! or {}
else
ngx.req.read_body!
flatten_params ngx.req.get_post_args!
else
ngx.req.read_body!
flatten_params ngx.req.get_post_args!
{}

params_get: ->
flatten_params ngx.req.get_uri_args!
Expand Down