Puma: HTTP Parse Error

Created on 6 Jan 2012  路  29Comments  路  Source: puma/puma

=> Booting Puma
=> Rails 3.1.3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Puma 0.9.2 starting...
* Min threads: 0, max threads: 16
* Listening on tcp://0.0.0.0:3000
2012-01-06 08:55:26 -0800: HTTP parse error, malformed request (): #<Puma::HttpParserError: HTTP element FIELD_VALUE is longer than the 80 * 1024 allowed length.>
2012-01-06 08:55:26 -0800: ENV: {"rack.version"=>[1, 1], "rack.errors"=>#\>, "rack.multithread"=>true, "rack.multiprocess"=>false, "rack.run_once"=>true, "SCRIPT_NAME"=>"", "CONTENT_TYPE"=>"", "QUERY_STRING"=>"", "SERVER_PROTOCOL"=>"HTTP/1.1", "SERVER_SOFTWARE"=>"0.9.2", "GATEWAY_INTERFACE"=>"CGI/1.2"}

---
2012-01-06 08:55:29 -0800: HTTP parse error, malformed request (): #<Puma::HttpParserError: HTTP element FIELD_VALUE is longer than the 80 * 1024 allowed length.>
2012-01-06 08:55:29 -0800: ENV: {"rack.version"=>[1, 1], "rack.errors"=>#>, "rack.multithread"=>true, "rack.multiprocess"=>false, "rack.run_once"=>true, "SCRIPT_NAME"=>"", "CONTENT_TYPE"=>"", "QUERY_STRING"=>"", "SERVER_PROTOCOL"=>"HTTP/1.1", "SERVER_SOFTWARE"=>"0.9.2", "GATEWAY_INTERFACE"=>"CGI/1.2"}

---
2012-01-06 08:55:47 -0800: HTTP parse error, malformed request (): #<Puma::HttpParserError: HTTP element FIELD_VALUE is longer than the 80 * 1024 allowed length.>
2012-01-06 08:55:47 -0800: ENV: {"rack.version"=>[1, 1], "rack.errors"=>#>, "rack.multithread"=>true, "rack.multiprocess"=>false, "rack.run_once"=>true, "SCRIPT_NAME"=>"", "CONTENT_TYPE"=>"", "QUERY_STRING"=>"", "SERVER_PROTOCOL"=>"HTTP/1.1", "SERVER_SOFTWARE"=>"0.9.2", "GATEWAY_INTERFACE"=>"CGI/1.2"}

---

Most helpful comment

For what it's worth, I got this error when I mistakenly made requests to localhost/127.0.0.1 with HTTPS (I hadn't set this up) instead of HTTP. I was using Puma.

All 29 comments

What was the request? The parser failed because there was a field that was 80k, which is the expected behavior.

@wxmn I need more information about this issue to be able to act on it.

Got same error today:

2012-10-11 14:54:32 +0200: HTTP parse error, malformed request (): #<Puma::HttpParserError: HTTP element FIELD_VALUE is longer than the 80 * 1024 allowed length.>
2012-10-11 14:54:32 +0200: ENV: {"rack.version"=>[1, 1], "rack.errors"=>#<IO:<STDERR>>, "rack.multithread"=>true, "rack.multiprocess"=>false, "rack.run_once"=>false, "SCRIPT_NAME"=>"", "CONTENT_TYPE"=>"text/plain", "QUERY_STRING"=>"", "SERVER_PROTOCOL"=>"HTTP/1.1", "SERVER_SOFTWARE"=>"1.6.3", "GATEWAY_INTERFACE"=>"CGI/1.2"}
---
2012-10-11 14:54:32 +0200: HTTP parse error, malformed request (): #<Puma::HttpParserError: HTTP element FIELD_VALUE is longer than the 80 * 1024 allowed length.>
2012-10-11 14:54:32 +0200: ENV: {"rack.version"=>[1, 1], "rack.errors"=>#<IO:<STDERR>>, "rack.multithread"=>true, "rack.multiprocess"=>false, "rack.run_once"=>false, "SCRIPT_NAME"=>"", "CONTENT_TYPE"=>"text/plain", "QUERY_STRING"=>"", "SERVER_PROTOCOL"=>"HTTP/1.1", "SERVER_SOFTWARE"=>"1.6.3", "GATEWAY_INTERFACE"=>"CGI/1.2"}
---
2012-10-11 14:54:48 +0200: HTTP parse error, malformed request (): #<Puma::HttpParserError: HTTP element FIELD_VALUE is longer than the 80 * 1024 allowed length.>
2012-10-11 14:54:48 +0200: ENV: {"rack.version"=>[1, 1], "rack.errors"=>#<IO:<STDERR>>, "rack.multithread"=>true, "rack.multiprocess"=>false, "rack.run_once"=>false, "SCRIPT_NAME"=>"", "CONTENT_TYPE"=>"text/plain", "QUERY_STRING"=>"", "SERVER_PROTOCOL"=>"HTTP/1.1", "SERVER_SOFTWARE"=>"1.6.3", "GATEWAY_INTERFACE"=>"CGI/1.2"}
---

Switched from Unicorn to Puma. On Unicorn the app runs without problems. I got there nothing special. Only using ActiveAdmin for apps administration interface. The app is also connected to Solr server through Sunspot gem. Any ideas? If you think I can provide you with more information, please, tell me where to look or what you need. Thanks!

What were the HTTP requests? I don't have any ability to replicate the bug right now.

The output indicates that puma thinks there is an 80k header value, is that possible in your application?

Can you please tell me how to find it out? I am sure I don't modify headers anywhere in the app (not sure about gems).

The easiest way is to use dev tools in your browser to look at the request and then paste it to me.

Google Chrome gives me "No data received" and Firefox "The connection was reset". I can get any information from both Chrome's developers tools and Firebug. If I try curl my localhost:port, it raises "Empty reply from server". Any other ideas?

This only happens when config.threadsafe! is uncommented AND connecting via SSL. From the other logs it seems like that to be the case as rack.multithread is true in both cases. Not sure if they are using SSL though.

Actually, I got this error with config.threadsafe! commented out and was running puma in development mode. Never tried connecting to it using SSL.

I had the same experience as @DaveTsunami, I got this error running in development mode. I had config.threadsafe! defined in my production.rb file only, and it wasn't until I also added it to development.rb did the error go away.

I'm getting this error and it's todo with characters it doesn't like passed in the url. Add % to your url and you'll be able to reproduce this error.

I am getting this error in my Rails 4/Ruby 2 app with a DELETE request and a very basic query:

http://my-app.dev/api/widgets/3362107/claim

Log:

13:34:46 web.1       | Started DELETE "/api/widgets/3362107/claim" for 127.0.0.1 at 2013-10-11 13:34:46 -0400
13:34:46 web.1       | Processing by Api::ClaimsController#destroy as */*
13:34:46 web.1       |   Parameters: {"widget_id"=>"3362107"}
13:34:46 web.1       | Completed 200 OK in 86ms (Views: 78.0ms | ActiveRecord: 0.6ms)
13:34:46 web.1       | 2013-10-11 13:34:46 -0400: HTTP parse error, malformed request (): #<Puma::HttpParserError: Invalid HTTP format, parsing fails.>
13:34:46 web.1       | 2013-10-11 13:34:46 -0400: ENV: {"rack.version"=>[1, 2], "rack.errors"=>#<IO:<STDERR>>, "rack.multithread"=>true, "rack.multiprocess"=>false, "rack.run_once"=>false, "SCRIPT_NAME"=>"", "CONTENT_TYPE"=>"text/plain", "QUERY_STRING"=>"", "SERVER_PROTOCOL"=>"HTTP/1.1", "SERVER_SOFTWARE"=>"2.5.1", "GATEWAY_INTERFACE"=>"CGI/1.2"}
13:34:46 web.1       | ---

It is possible to log the error's requests (by modifying puma)? I'm also experiencing a similar issue in Rails 4.0.1, Ruby 2.1.0-preview1 but I can't reproduce through a browser, as I have no clue which path the client is trying to hit.

I only get this:

HTTP parse error, malformed request (): #<Puma::HttpParserError: Invalid HTTP format, parsing fails.>
ENV: {"rack.version"=>[1, 2], "rack.errors"=>#<IO:<STDERR>>, "rack.multithread"=>true, "rack.multiprocess"=>false, "rack.run_once"=>false, "SCRIPT_NAME"=>"", "CONTENT_TYPE"=>"text/plain", "QUERY_STRING"=>"", "SERVER_PROTOCOL"=>"HTTP/1.1", "SERVER_SOFTWARE"=>"2.6.0", "GATEWAY_INTERFACE"=>"CGI/1.2"}

Same happens to me while issuing DELETE requests via ajax. Riding Ruby 2 with Rails 3.2.15.

01:34:14 web.1       | Started DELETE "/signout" for 127.0.0.1 at 2013-11-20 01:34:14 +0000
01:34:14 web.1       | Processing by SessionsController#destroy as */*
01:34:14 web.1       | WARNING: Can't verify CSRF token authenticity
01:34:14 web.1       |   User Load (0.5ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 5 LIMIT 1
01:34:14 web.1       |    (0.1ms)  BEGIN
01:34:14 web.1       |    (0.1ms)  COMMIT
01:34:14 web.1       | Completed 204 No Content in 8.4ms (ActiveRecord: 0.7ms)
01:34:14 web.1       | 2013-11-20 01:34:14 +0000: HTTP parse error, malformed request (): #<Puma::HttpParserError: Invalid HTTP format, parsing fails.>
01:34:14 web.1       | 2013-11-20 01:34:14 +0000: ENV: {"rack.version"=>[1, 1], "rack.errors"=>#<IO:<STDERR>>, "rack.multithread"=>true, "rack.multiprocess"=>false, "rack.run_once"=>false, "SCRIPT_NAME"=>"", "CONTENT_TYPE"=>"text/plain", "QUERY_STRING"=>"", "SERVER_PROTOCOL"=>"HTTP/1.1", "SERVER_SOFTWARE"=>"2.6.0", "GATEWAY_INTERFACE"=>"CGI/1.2"}
01:34:14 web.1       | ---

Is there a flag we can use to have Puma dump the request to stdout/stderr? If there was, I suspect it would make resolving these issues simpler.

For what it's worth, I got this error when I mistakenly made requests to localhost/127.0.0.1 with HTTPS (I hadn't set this up) instead of HTTP. I was using Puma.

Also discovered that I got the error with an https url - where ssl isn't set up locally.

I got the same "HTTP parse error, malformed request" errors. I wanted Sinatra, Puma, and SSL for a test server. The following code gave me the errors.

Rack::Handler::Puma.run(SinatraApp, rack_opts) do |server|
  ctx             = Puma::MiniSSL::Context.new
  ctx.key         = ENV['SSL_KEY']
  ctx.cert        = ENV['SSL_CERT']
  ctx.verify_mode = Puma::MiniSSL::VERIFY_NONE

  server.add_ssl_listener(rack_opts[:Host], rack_opts[:Port], ctx)
end

The Puma Rack Handler had the follow lines:

server.add_tcp_listener options[:Host], options[:Port]
server.min_threads = min
server.max_threads = max
yield server if block_given?

Because the yield came after the add_tcp_listener, the code called server.add_ssl_listener too late. The add_tcp_listener had already bound to the port, I think.

To fix it, I just changed the port for the ssl listener.

@lloydmeta you saved my day, Thanks! I was calling localhost over https

I'm using ruby 2.1.2p95, rails 4.1.8, puma 2.9.2. For the following plain GET request
http://localhost:3000/download/files/%D7%A4%D7%A8%D7%95%D7%99%D7%A7%D7%98%2020132%20personal%20ECG%20% I'm getting

2015-02-05 17:36:30 +0200: HTTP parse error, malformed request (): #<Puma::HttpParserError: Invalid HTTP format, parsing fails.>
2015-02-05 17:36:30 +0200: ENV: {"rack.version"=>[1, 2], "rack.errors"=>#<IO:<STDERR>>, "rack.multithread"=>true, "rack.multiprocess"=>false, "rack.run_once"=>false, "SCRIPT_NAME"=>"", "CONTENT_TYPE"=>"text/plain", "QUERY_STRING"=>"", "SERVER_PROTOCOL"=>"HTTP/1.1", "SERVER_SOFTWARE"=>"2.9.2", "GATEWAY_INTERFACE"=>"CGI/1.2", "REQUEST_METHOD"=>"GET"}
---

Nothing fancy, just simple GET

@gshilin please open a new issue with the information about how you made the request.

For others hitting this page as a result of a https error. You are more than likely specifying tcp:// instead of ssl:// as the binding address:

e.g.
bundle exec puma config.ru -b 'tcp://0.0.0.0:3456?key=/path/to/key.key&cert=/path/to/cert.crt'
instead of
bundle exec puma config.ru -b 'ssl://0.0.0.0:3456?key=/path/to/key.key&cert=/path/to/cert.crt'

Thanks for the help about changing the binding address to ssl! However, when I configure with ssl://... I receive this error when my client tries to connect...

Rack app error: #<TypeError: no implicit conversion of Puma::MiniSSL::Socket into Integer> /rails_apps/helphub/vendor/bundle/ruby/2.1.0/gems/eventmachine-1.0.8/lib/eventmachine.rb:762:inattach_fd'`

I am using the private .key file I generated when applying for my certificate, and the .crt file that was given to me by Comodo. Thanks!

@vanboom
I solved this problem by replacing puma on thin server

Hi i'm facing this issue with puma gem, Can anyone help out me to fix this issue
=> Booting Puma
=> Rails 4.2.5 application starting in development on http://localhost:3000
=> Run rails server -h for more startup options
=> Ctrl-C to shutdown server
Puma starting in single mode...

  • Version 3.4.0 (ruby 2.3.1-p112), codename: Owl Bowl Brawl
  • Min threads: 0, max threads: 16
  • Environment: development
  • Listening on tcp://localhost:3000
    Use Ctrl-C to stop
2016-11-08 11:03:34 +0530: HTTP parse error, malformed request (): #<Puma::HttpParserError: Invalid HTTP format, parsing fails.>
2016-11-08 11:03:34 +0530: ENV: {"rack.version"=>[1, 3], "rack.errors"=>#<IO:<STDERR>>, "rack.multithread"=>true, "rack.multiprocess"=>false, "rack.run_once"=>false, "SCRIPT_NAME"=>"", "QUERY_STRING"=>"", "SERVER_PROTOCOL"=>"HTTP/1.1", "SERVER_SOFTWARE"=>"puma 3.4.0 Owl Bowl Brawl", "GATEWAY_INTERFACE"=>"CGI/1.2"}
---
2016-11-08 11:03:34 +0530: HTTP parse error, malformed request (): #<Puma::HttpParserError: Invalid HTTP format, parsing fails.>
2016-11-08 11:03:34 +0530: ENV: {"rack.version"=>[1, 3], "rack.errors"=>#<IO:<STDERR>>, "rack.multithread"=>true, "rack.multiprocess"=>false, "rack.run_once"=>false, "SCRIPT_NAME"=>"", "QUERY_STRING"=>"", "SERVER_PROTOCOL"=>"HTTP/1.1", "SERVER_SOFTWARE"=>"puma 3.4.0 Owl Bowl Brawl", "GATEWAY_INTERFACE"=>"CGI/1.2"}
---
2016-11-08 11:03:34 +0530: HTTP parse error, malformed request (): #<Puma::HttpParserError: Invalid HTTP format, parsing fails.>
2016-11-08 11:03:34 +0530: ENV: {"rack.version"=>[1, 3], "rack.errors"=>#<IO:<STDERR>>, "rack.multithread"=>true, "rack.multiprocess"=>false, "rack.run_once"=>false, "SCRIPT_NAME"=>"", "QUERY_STRING"=>"", "SERVER_PROTOCOL"=>"HTTP/1.1", "SERVER_SOFTWARE"=>"puma 3.4.0 Owl Bowl Brawl", "GATEWAY_INTERFACE"=>"CGI/1.2"}
---
2016-11-08 11:03:34 +0530: HTTP parse error, malformed request (): #<Puma::HttpParserError: Invalid HTTP format, parsing fails.>
2016-11-08 11:03:34 +0530: ENV: {"rack.version"=>[1, 3], "rack.errors"=>#<IO:<STDERR>>, "rack.multithread"=>true, "rack.multiprocess"=>false, "rack.run_once"=>false, "SCRIPT_NAME"=>"", "QUERY_STRING"=>"", "SERVER_PROTOCOL"=>"HTTP/1.1", "SERVER_SOFTWARE"=>"puma 3.4.0 Owl Bowl Brawl", "GATEWAY_INTERFACE"=>"CGI/1.2"}
---
2016-11-08 11:03:34 +0530: HTTP parse error, malformed request (): #<Puma::HttpParserError: Invalid HTTP format, parsing fails.>
2016-11-08 11:03:34 +0530: ENV: {"rack.version"=>[1, 3], "rack.errors"=>#<IO:<STDERR>>, "rack.multithread"=>true, "rack.multiprocess"=>false, "rack.run_once"=>false, "SCRIPT_NAME"=>"", "QUERY_STRING"=>"", "SERVER_PROTOCOL"=>"HTTP/1.1", "SERVER_SOFTWARE"=>"puma 3.4.0 Owl Bowl Brawl", "GATEWAY_INTERFACE"=>"CGI/1.2"}
---
2016-11-08 11:03:34 +0530: HTTP parse error, malformed request (): #<Puma::HttpParserError: Invalid HTTP format, parsing fails.>
2016-11-08 11:03:34 +0530: ENV: {"rack.version"=>[1, 3], "rack.errors"=>#<IO:<STDERR>>, "rack.multithread"=>true, "rack.multiprocess"=>false, "rack.run_once"=>false, "SCRIPT_NAME"=>"", "QUERY_STRING"=>"", "SERVER_PROTOCOL"=>"HTTP/1.1", "SERVER_SOFTWARE"=>"puma 3.4.0 Owl Bowl Brawl", "GATEWAY_INTERFACE"=>"CGI/1.2"}
---

@pavan461 make sure not to use https:// in development, or if you do configure it appropriately.

I had this happening for a health check, because the the rails app was configured with config.force_ssl = true, but the check was bypassing the load balancer terminating ssl, so the check received a redirect to something like https://localhost:5000/ping causing the error.

I had to do some low-level debugging with wireshark to find the issue, so maybe this helps others.

The solution in this case was to add a request header X-Forwarded-Proto: https to the health checks.

When i use http://localhost:3142/api/v1/users got the same error HTTP parse error, malformed request (): #<Puma::HttpParserError: Invalid HTTP format, parsing fails.>, but access 127.0.0.1:3142/api/v1/users is ok.

Was this page helpful?
0 / 5 - 0 ratings