HTTP parse error, malformed request - Ruby on Rails

Nick April picture Nick April · Mar 12, 2017 · Viewed 17.6k times · Source

I see the following error in Terminal when attempting to run a Ruby on Rails app.

HTTP parse error, malformed request (): #<Puma::HttpParserError: Invalid HTTP format, parsing fails.>
2017-03-12 13:10:02 -0400: 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"}

The browser error:

This site can’t provide a secure connection. localhost sent an invalid response. ERR_SSL_PROTOCOL_ERROR*

I have tried the following

  • Clearing browser cache and restarting
  • Reverting back to an old commit in GIT that was working at the time
  • Restarting terminal
  • Running a different rails app that was functional

Answer

Toma Nistor picture Toma Nistor · May 11, 2017

Here are some possible solutions.

  1. Make sure you are connecting through http://localhost:3000 and not https://localhost:3000.

  2. If the browser redirects to HTTPS and it's Google Chrome, try this solution that addresses an HSTS problem: https://stackoverflow.com/a/28586593

  3. Make sure you do not have the production environment (if that's what you're serving) forcing HTTPS. If that's the problem, comment this out or change true to false:

    config/environments/production.rb

    # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
    config.force_ssl = true