Nginx lua module + SPDY = no request body

KiberGus kibergus at
Thu Dec 11 13:58:28 UTC 2014

Hello. I'm experiencing problems with combination of nginx lua module
and SPDI. I use "access_by_lua_file" directive to validate requests.
In the script request checksumm is validated, so I need to get body of
the POST requests. "ngx.var.request_body" variable is used for this
purpose. This code works when client uses HTTP protocol, but when we
move to SPDY request body is always nil.

What I've tried:
    I do call ngx.req.read_body() from lua script. Beside taht I've
added "lua_need_request_body on" directive to the nginx config (at
location and at server levels).
    I've tried using "ngx.req.get_body_data()" instead of
    I've checked that "ngx.req.get_body_file" returns nil. So request
is not written to file.
    I've used wireshark to check, that request body is not empty.

If "access_by_lua_file" directive is removed, then backend receives
request body. So the problem occurs only within lua. We've tested
nginx=1.4.0 and nginx=1.6.2. So in case of 1.4 we use SPDY v2 and in
case SPDY v3.1.

Here is a test config:

server {
    listen [::]:80;
    listen [::]:6121 spdy;
    spdy_headers_comp 9;

    client_body_buffer_size 100k;
    client_max_body_size 100k;
    lua_need_request_body on;

    server_name *;

    location /test {
        access_by_lua '
            if not ngx.req.get_body_data() then
                return ngx.exit(403)

        content_by_lua '
            ngx.header["Content-Type"] = "text/plain"
            ngx.say("hello world")

If you request it without body you get 403. Otherwice you get 200:

$ curl --data "TEST" http://localhost/test
hello world
$ curl http://localhost/test
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>

But if SPDY protocol is used, than it always returns 403. Any help is
appreciated. Thank you.

More information about the nginx mailing list