Search code examples
httpnginxluaopenrestyhttp-1.1

Lua Socket Send 200 OK close connection


What is minimal HTTP 200 OK Connection close response for Nginx/lua/openresty. I have:

local sock, err = ngx.req.socket(true)
sock:send("HTTP/1.1 200 OK\\r\\nConnection: close\\r\\n\\r\\n")

and curl says:

curl: (52) Empty reply from server

Solution

  • In a case of no response body, you should probably use 204 No Content response code; "201 Created" may be an option as well for requests that create resources.

    Also: replace each double slash with a single one, as you don't need to escape slash to generate CR LF sequence.