Skip to content

Commit add2e4a

Browse files
authored
Update README::HTTP headers and status
* use `ngx.req.read_body()` + `ngx.req.get_body_data()` instead of `lua_need_request_body on;`, which does not work for me * make /tnt_proxy location internal * hide `{"params": [...]}` from a user
1 parent 4b65baf commit add2e4a

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

README.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -313,12 +313,13 @@ Example
313313

314314
```Lua
315315
-- Tarantool, stored procedure
316-
function foo(req)
317-
return {
318-
200, -- set status HTTP 200
319-
{ ["X-Tarantool"] = "FROM_TNT" } -- set headers
316+
function foo(req, ...)
317+
local status = 200
318+
local headers = {
319+
["X-Tarantool"] = "FROM_TNT",
320320
}
321-
321+
local body = 'It works!'
322+
return status, headers, body
322323
end
323324
```
324325

@@ -331,6 +332,7 @@ Example
331332
}
332333
333334
location /tnt_proxy {
335+
internal;
334336
tnt_method tnt_proxy;
335337
tnt_buffer_size 100k;
336338
tnt_pass_http_request on parse_args;
@@ -339,8 +341,6 @@ Example
339341
340342
location /api {
341343
342-
lua_need_request_body on;
343-
344344
rewrite_by_lua '
345345
346346
local cjson = require("cjson")
@@ -351,11 +351,16 @@ Example
351351
PUT = ngx.HTTP_PUT,
352352
-- ...
353353
}
354-
354+
-- hide `{"params": [...]}` from a user
355+
ngx.req.read_body()
356+
local body = ngx.req.get_body_data()
357+
if body then
358+
body = "{\\"params\\": [" .. body .. "]}"
359+
end
355360
local res = ngx.location.capture("/tnt_proxy", {
356361
args = ngx.var.args,
357362
method = map[ngx.var.request_method],
358-
body = ngx.body
363+
body = body
359364
})
360365
361366
if res.status == ngx.HTTP_OK then

0 commit comments

Comments
 (0)