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

"Nginx::Request#headers_out" empties the assigned array, contrary to expectations #155

Closed
lamanotrama opened this issue Feb 4, 2016 · 3 comments

Comments

@lamanotrama
Copy link

I guess it is not the intended behavior.

Reproduction code is as follows.

# nginx

server {
  listen 127.0.0.1:8888;

  location / {
    mruby_rewrite_handler_code '
      headers = %w(abc=123 foo=bar)
      Nginx::Request.new.headers_out["Set-Cookies"] = headers
      Nginx.errlogger Nginx::LOG_ERR, headers
      Nginx::return headers.empty? ? Nginx::HTTP_INTERNAL_SERVER_ERROR : Nginx::OK
    ';
  }
}

Request to the above server as below.

$ curl http://127.0.0.1:8888 -sv > /dev/null
* Rebuilt URL to: http://127.0.0.1:8888/
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 8888 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.35.0
> Host: 127.0.0.1:8888
> Accept: */*
>
< HTTP/1.1 500 Internal Server Error
* Server nginx is not blacklisted
< Server: nginx
< Date: Thu, 04 Feb 2016 11:40:12 GMT
< Content-Type: text/html
< Content-Length: 186
< Connection: close
< Set-Cookies: foo=bar
< Set-Cookies: abc=123
<
{ [data not shown]
* Closing connection 0
root@node1:~#

and log

$ tail -1 /var/log/nginx/error.log
2016/02/04 11:40:12 [error] 11130#11130: *9 [], client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1:8888"

I expected status 200, and the array with two item in the log, but the results are not.

Environment

  • Ubuntu 14.04.3
  • Nginx 1.9.9
  • nginx_mruby 1.15.0

For more details of nginx please refer https://gist.github.com/lamanotrama/638e97202cf54bfd9196

@matsumotory
Copy link
Owner

Thank you for your report. I'll investigate it.

matsumotory added a commit that referenced this issue Feb 4, 2016
Fix bug; pop array object when adding into headers #155
@matsumotory
Copy link
Owner

Fixed via #156

@lamanotrama
Copy link
Author

💯
Thank you!!

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