Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't return content with status code other than 200 #484

Open
gencer opened this issue Dec 3, 2020 · 1 comment
Open

Can't return content with status code other than 200 #484

gencer opened this issue Dec 3, 2020 · 1 comment

Comments

@gencer
Copy link

gencer commented Dec 3, 2020

When I return a status code other than 200, Nginx intercepts the request and show static nginx error file instead of my custom content generated in Ruby.

For example;

nginx.conf:

server {
  location / {
    mruby_content_handler "path/to/test.rb"; # or access_handler
  }
}

test.rb:

class InvalidResponse
  def call(env)
    status = 404 # 404 File not Found.
	hash = { success: false }

    headers = {"Content-Type" => "application/json"}
	body = [hash.to_json]
    [status, headers, body]
  end
end

run InvalidResponse.new

If I give 200 as a status then {success: false} shown on browser.

Isn't ngx_mruby capable of returning custom status codes with content?

P.S.: I also tried Nginx.return and Nginx.status_code. Neither worked.

@yyamano
Copy link
Collaborator

yyamano commented Jul 14, 2022

If my memory serves me right, it's a limitation (and specification) of nginx, not nginx_mruby.

You might want to use an error_page directive with a named location.
See http://nginx.org/en/docs/http/ngx_http_core_module.html#error_page for more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants