请求无效:HTTP格式无效,解析失败

时间:2014-09-02 00:50:44

标签: ruby-on-rails

我经常在rails服务器日志中收到此错误:

Invalid request: Invalid HTTP format, parsing fails.
    /home/budkin/gamestown/vendor/cache/ruby/2.0.0/gems/thin-1.6.1/lib/thin/request.rb:84:in `execute'
    /home/budkin/gamestown/vendor/cache/ruby/2.0.0/gems/thin-1.6.1/lib/thin/request.rb:84:in `parse'
    /home/budkin/gamestown/vendor/cache/ruby/2.0.0/gems/thin-1.6.1/lib/thin/connection.rb:41:in `receive_data'
    /home/budkin/gamestown/vendor/cache/ruby/2.0.0/gems/faye-websocket-0.7.2/lib/faye/adapters/thin.rb:44:in `receive_data'
    /home/budkin/gamestown/vendor/cache/ruby/2.0.0/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run_machine'
    /home/budkin/gamestown/vendor/cache/ruby/2.0.0/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run'
    /home/budkin/gamestown/vendor/cache/ruby/2.0.0/gems/thin-1.6.1/lib/thin/backends/base.rb:73:in `start'
    /home/budkin/gamestown/vendor/cache/ruby/2.0.0/gems/thin-1.6.1/lib/thin/server.rb:162:in `start'
    /home/budkin/gamestown/vendor/cache/ruby/2.0.0/gems/rack-1.5.2/lib/rack/handler/thin.rb:16:in `run'
    /home/budkin/gamestown/vendor/cache/ruby/2.0.0/gems/rack-1.5.2/lib/rack/server.rb:264:in `start'
    /home/budkin/gamestown/vendor/cache/ruby/2.0.0/gems/railties-4.0.1/lib/rails/commands/server.rb:84:in `start'
    /home/budkin/gamestown/vendor/cache/ruby/2.0.0/gems/railties-4.0.1/lib/rails/commands.rb:76:in `block in <top (required)>'
    /home/budkin/gamestown/vendor/cache/ruby/2.0.0/gems/railties-4.0.1/lib/rails/commands.rb:71:in `tap'
    /home/budkin/gamestown/vendor/cache/ruby/2.0.0/gems/railties-4.0.1/lib/rails/commands.rb:71:in `<top (required)>'
    bin/rails:4:in `require'
    bin/rails:4:in `<main>'

一切正常,但错误很烦人

是的,这是thin

8 个答案:

答案 0 :(得分:12)

我有与上面完全相同的错误。在我的情况下,它是一个(.net)客户端尝试使用HTTPS而不是HTTP连接到我的(瘦)服务器。一旦我将协议更改回基本http,错误就消失了。

答案 1 :(得分:7)

瘦服务器存在同样的问题。

我在thin的request.rb文件中抛出了binding.pry,发现以下请求导致了错误: “GET / info?txtAirPlay&amp; txtRAOP RTSP / 1.0 \ r \ n \ r \ n”

事实证明,这可能是Yosemite(我正在运行10.10.3)和您正在运行的localhost端口的问题。我在端口5000上运行,如果你查看下面的堆栈溢出帖子,你会看到Apple AirTunes在端口5000上运行: AirPlay messes up localhost

尝试更改rails服务器端口以消除错误(我只是随机选择了5212):

rails s -p 5212

答案 2 :(得分:6)

我在rails s -e production的调试会话期间访问了https://localhost:3000,其中config.force_ssl = true。

即使我专门输入https://localhost:3000.com,这也迫使最新版本的Chrome只尝试访问http://localhost:3000

如果您的应用程序在隐身模式或其他浏览器中工作。我建议您清除浏览历史记录。

在瘦服务器中绑定.pry之后。我收到了@data加密:

0\tlocalhost\x00\x17\x00\x00\x00#\x00\x00\x00\r\x00\x12\x00\x10\x06\x01\x06\x03\x05\x01\x05\x03\x04\x01\x04\x03\x02\x01\x02\x03\x00\x05\x00\x05\x01\x00\x00\x00\x00\x00\x12\x00\x00\x00\x10\x00\x0E\x00\f\x02h2\bhttp/1.1uP\x00\x00\x00\v\x00\x02\x01\x00\x00\n\x00\b\x00\x06\x00\x1D\x00\x17\x00\x18

答案 3 :(得分:3)

  1. 您使用的是gem thin
  2. 吗?
  3. 如果是这样,请确保它位于Gemfile gem 'thin', group: :development
  4. 中的正确环境中
  5. 其他:尝试在其他浏览器上打开http://localhost:3000 ....或者如果您只有一个浏览器......您可以打开“隐身”或“隐私”窗口
  6. 如果它在其他浏览器上运行,那么您需要rake tmp:clear并清除浏览器的缓存

答案 4 :(得分:1)

如果您对其进行评论config.force_ssl = true并且错误仍然存​​在 - 请在浏览器中检查您是否仍然是http s

答案 5 :(得分:1)

在我的情况下,这与Chrome在localhost上强制执行HSTS有关。我使用this answer来修复:

  1. 冲浪到chrome:// net-internals / #hsts
  2. 在删除部分中,输入&#34; localhost&#34;并从Chrome中删除记录。

答案 6 :(得分:1)

您可以使用Ngrok 首先,使用ENV作为production运行开发服务器,然后执行以下命令./ngrok http -bind-tls=true localhost:3000

答案 7 :(得分:0)

对于Chrome用户:

Chrome正在强制使用HTTPS而非HTTP,这会导致此问题。单击url旁边的info icon,然后将Pop-ups and redirects更改为Block,即可使其正常工作。

enter image description here

相关问题