Coder Social home page Coder Social logo

HTTP Parse Error about puma HOT 29 CLOSED

puma avatar puma commented on April 28, 2024
HTTP Parse Error

from puma.

Comments (29)

lloydmeta avatar lloydmeta commented on April 28, 2024 37

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.

from puma.

felixbuenemann avatar felixbuenemann commented on April 28, 2024 4

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.

from puma.

rda1902 avatar rda1902 commented on April 28, 2024 2

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

from puma.

beitaz avatar beitaz commented on April 28, 2024 2

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.

from puma.

evanphx avatar evanphx commented on April 28, 2024

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

from puma.

evanphx avatar evanphx commented on April 28, 2024

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

from puma.

davidhorsak avatar davidhorsak commented on April 28, 2024

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!

from puma.

evanphx avatar evanphx commented on April 28, 2024

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

from puma.

evanphx avatar evanphx commented on April 28, 2024

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

from puma.

davidhorsak avatar davidhorsak commented on April 28, 2024

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).

from puma.

evanphx avatar evanphx commented on April 28, 2024

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

from puma.

davidhorsak avatar davidhorsak commented on April 28, 2024

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?

from puma.

kenips avatar kenips commented on April 28, 2024

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.

from puma.

davidhorsak avatar davidhorsak commented on April 28, 2024

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

from puma.

stantona avatar stantona commented on April 28, 2024

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.

from puma.

cj avatar cj commented on April 28, 2024

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.

from puma.

dlindahl avatar dlindahl commented on April 28, 2024

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       | ---

from puma.

masterkain avatar masterkain commented on April 28, 2024

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"}

from puma.

Sija avatar Sija commented on April 28, 2024

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       | ---

from puma.

ryandotsmith avatar ryandotsmith commented on April 28, 2024

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.

from puma.

LouisSayers avatar LouisSayers commented on April 28, 2024

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

from puma.

michaelvobrien avatar michaelvobrien commented on April 28, 2024

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.

from puma.

mgharbik avatar mgharbik commented on April 28, 2024

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

from puma.

gshilin avatar gshilin commented on April 28, 2024

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

from puma.

evanphx avatar evanphx commented on April 28, 2024

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

from puma.

gerrywastaken avatar gerrywastaken commented on April 28, 2024

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'

from puma.

vanboom avatar vanboom commented on April 28, 2024

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!

from puma.

rpavankumar avatar rpavankumar commented on April 28, 2024

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"}
---

from puma.

rainerborene avatar rainerborene commented on April 28, 2024

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

from puma.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.