Skip to content

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

@gencer

Description

@gencer

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions