Hello!
On Tue, Nov 25, 2014 at 2:00 PM, tripledot wrote:
> So I am trying to set the response body to a specific JSON content when I
> return 401 Unauthorized, with no luck (the status code returned is what I
> expect, but the response body is empty). I have also tried using ngx.print.
I tried the following minimal example on my side with the latest
OpenResty (1.7.7.1 RC1):
location = /t {
rewrite_by_lua '
ngx.status = ngx.HTTP_UNAUTHORIZED
ngx.say("hello world")
ngx.exit(ngx.HTTP_UNAUTHORIZED)
';
}
And it works as expected:
$ curl -i localhost:8080/t
HTTP/1.1 401 Unauthorized
Server: openresty/1.7.7.1rc1
Date: Tue, 25 Nov 2014 23:03:05 GMT
Content-Type: text/plain
Transfer-Encoding: chunked
Connection: keep-alive
hello world
If you still believe there is a bug, please try constructing a
standalone and minimal example that can reproduce the problem on
others' boxes.
BTW, your complicated code example does not call ngx.status = 401 and
ngx.print/ngx.say on *every* code path calling ngx.exit(401).
Regards,
-agentzh