lua-nginx-module icon indicating copy to clipboard operation
lua-nginx-module copied to clipboard

Added ngx.resp.set_status_reason function to set a custom reason phrase

Open jdesgats opened this issue 8 years ago • 6 comments

I hereby granted the copyright of the changes in this pull request to the authors of this lua-nginx-module project.

Allows to set the reason for HTTP status codes unknown from the nginx core. Given the current implementation of nginx, it is safer and more convenient to set the status at the same time.

Currently setting the status to an unknown response code causes the reason to be empty:

content_by_lua '
    ngx.status = 876
    ngx.say("custom response")
';

Causes the response to be:

< HTTP/1.1 876
< Date: Fri, 16 Sep 2016 20:06:33 GMT
< Content-Type: text/plain
< Transfer-Encoding: chunked
< Connection: keep-alive
<
custom response

The use cases can be to implement some of the error codes unknown from nignx (e.g. RFC6585) or completely custom HTTP response codes.

There is still two open questions in my mind:

  • Should we add an optional parameter in ngx.exit too?
  • Do we add the resty.core wrapper now or in another PR?

jdesgats avatar Sep 16 '16 20:09 jdesgats

This pull request is now in conflict :(

mergify[bot] avatar Jun 26 '20 00:06 mergify[bot]