How to return the http code and print the message at the same time?

25 views
Skip to first unread message

Kane You

unread,
Jul 5, 2022, 5:16:17 AM7/5/22
to openresty-en
Hi,

Hello everyone, How to return the HTTP code and print the message at the same time?

eg:

...
content_by_lua_block {
              ngx.print('{"code":202,"status":"Accepted","server":"openresty","info":"Current IP already exists, no operation."}')
             ngx.exit(202)
}
...

thanks.

Luis Gasca

unread,
Jul 5, 2022, 6:04:52 AM7/5/22
to openre...@googlegroups.com
Try this

ngx.status = 202
ngx.print("response text")
ngx.exit(202)
--
You received this message because you are subscribed to the Google Groups "openresty-en" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openresty-en...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openresty-en/18720b1e-0169-4762-821c-efcc1162fec5n%40googlegroups.com.

Kane You

unread,
Jul 5, 2022, 9:57:32 PM7/5/22
to openre...@googlegroups.com
It works well, thank you.

Reply all
Reply to author
Forward
0 new messages