Access_by_lua error

Hi, not sure if I’m doing this the right way round but getting this
error:

[error] 11346#0: *1 content_by_lua aborted: runtime error: [string
“access_by_lua”]:22: attempt to call ngx.exit after sending out the
headers while sending to client

On the lua code:
elseif (res.status == ngx.HTTP_OK) then
ngx.print(res.body)
ngx.exit(res.status)

I’m sure it’s something simple im doing wrong?

Thanks

On Mon, Apr 18, 2011 at 6:27 AM, Richard K.
[email protected] wrote:

Hi, not sure if I’m doing this the right way round but getting this error:

[error] 11346#0: *1 content_by_lua aborted: runtime error: [string
“access_by_lua”]:22: attempt to call ngx.exit after sending out the headers while
sending to client

On the lua code:
elseif (res.status == ngx.HTTP_OK) then
ngx.print(res.body)
ngx.exit(res.status)

I’m sure it’s something simple im doing wrong?

The error message explains all. Please use ngx.exit(ngx.OK) or
ngx.exit(0) instead of ngx.exit(res.status) here.

Your response headers have already been sent once you call
ngx.print(res.body) and it’s too late to do ngx.exit(200) on the next
line to attempt to change the http status code in the headers that
have already been sent to the client.

Unlike PHP, ngx_lua emits response headers and bodies in unbuffered
mode, i.e., streamingly, by default.

Cheers,
-agentzh

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs