Skip to content

Commit

Permalink
Add test for matsumotory#282
Browse files Browse the repository at this point in the history
  • Loading branch information
yyamano committed Nov 7, 2018
1 parent 8b73427 commit 3755310
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/conf/nginx.conf
Expand Up @@ -928,6 +928,33 @@ http {
end
';
}

location /issue-282 {
mruby_enable_read_request_body on;
mruby_set_code $body '
Nginx.log Nginx::LOG_ERR, "reading body..."
body = "Boo!"
req = Nginx::Request.new
begin
rc = req.read_body
body = req.get_body
Nginx.log Nginx::LOG_ERR, "path=#{req.uri}, method=#{req.method}, rc=#{rc}, body=#{body}"
rescue => e
Nginx.log Nginx::LOG_ERR, "Failed to read a request body: #{e.class}: #{e.message}"
end
body
';
mruby_content_handler_code '
begin
body = Nginx::Request.new.var.body
raise "body is nil or empty" if body.nil? || body.empty?
Nginx.rputs body
rescue => e
Nginx.log Nginx::LOG_ERR, "Failed to get a request body: #{e.class}: #{e.message}"
Nginx.rputs "Failed to get a request body"
end
';
}
}

server {
Expand Down
5 changes: 5 additions & 0 deletions test/t/ngx_mruby.rb
Expand Up @@ -612,6 +612,11 @@ def is_async_supported?
t.assert_equal 204, res["code"]
end

t.assert('ngx_mruby - BUG: request_body issue 282', 'location /issue-282') do
res = `./test/t/issue-282-test.rb`.split("\r\n\r\n")[1]
t.assert_equal %({\"hello\": \"ngx_mruby\"}\n), res
end

if nginx_features.is_stream_supported?

base1 = "http://127.0.0.1:12345"
Expand Down

0 comments on commit 3755310

Please sign in to comment.