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 Apr 14, 2017
1 parent 99bf850 commit 02698f4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/conf/nginx.conf
Expand Up @@ -764,6 +764,32 @@ http {
Nginx.rputs Userdata.new.req_body
';
}
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 @@ -549,6 +549,11 @@ def base_ssl(port)
t.assert_equal %({\"hello\": \"ngx_mruby\"}\n), res
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

#
# nginx stream test verison 1.9.6 later
#
Expand Down

0 comments on commit 02698f4

Please sign in to comment.