我们有一个通过 SSL 连接到 Rails 服务器的 Cordova 应用程序。我们最近从 Unicorn 到 Puma 的更改似乎导致了一个问题,即 Android 应用程序在向服务器发送图像文件时出现 500 错误。
一些注意事项:
我正在努力思考问题可能是什么,甚至不知道去哪里寻找解决方案。我对 Puma 很陌生,所以我不知道我的配置中是否遗漏了一些重要的东西来处理这个问题。任何想法将不胜感激。
iOS 请求(工作正常)
POST /api/v2/attachments HTTP/1.1
Host: <omitted for security>
Accept: */*
Proxy-Connection: keep-alive
X-Requested-With: XMLHttpRequest
Accept-Encoding: gzip, deflate
If-None-Match: "2146f2b315668b29682ec01973ae4155"
Accept-Language: en-us
Content-Type: multipart/form-data; boundary=+++++org.apache.cordova.formBoundary
Content-Length: 13794
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13B143 (4954749952)
Connection: keep-alive
Cookie: XSRF-TOKEN=<omitted for security>; _session_id=<omitted for security>
--+++++org.apache.cordova.formBoundary
Content-Disposition: form-data; name="type"
Image
--+++++org.apache.cordova.formBoundary
Content-Disposition: form-data; name="attachment[attachment]"; filename="cdv_photo_003.jpg"
Content-Type: image/jpeg
Content-Length: 13466
iُ B~,"
#BR$3br
%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz
B #3Rbr
$4%&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz
""""""''''',,,,,,,,,,
...................................................(<a$GW_ЬUպi&dA+x=R
?)uHv"ԊdcpIސW̚<<Kx~E1xEN]M%>r{Y_Yc<jʥYH_2r[P['6 d#wS+5Bfu
<more Binary data omitted for brevity>
--+++++org.apache.cordova.formBoundary--
等效的 Android 请求(导致错误)
POST /api/v2/attachments HTTP/1.1
Content-Type: multipart/form-data; boundary=+++++
Cookie: _session_id=<omitted for security>; XSRF-TOKEN=<omitted for security>
Transfer-Encoding: chunked
User-Agent: Dalvik/2.1.0 (Linux; U; Android 5.0; SM-G900F Build/LRX21T)
Host: <omitted for security>
Connection: Keep-Alive
Accept-Encoding: gzip
--+++++
Content-Disposition: form-data; name="type"
Image
--+++++
Content-Disposition: form-data; name="attachment[attachment]"; filename="modified.jpg?1446611766814"
Content-Type: image/jpeg
Exif
(1#%(:3=<9387@H\N@DWE78PmQW_bghg>Mqypdx\egc"
#BR$3br
<more Binary data omitted for brevity>
--+++++--
这些请求之间存在一些明显的差异,虽然我不会称自己为 HTTP 协议(protocol)专家,但在我看来这些差异都不会导致 Puma 崩溃。
机架错误跟踪:
2015-11-04T04:36:07.041124+00:00 app[web.1]: 2015-11-04 04:36:07 +0000: Rack app error: #<EOFError: bad content body>
2015-11-04T04:36:07.041131+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/multipart/parser.rb:74:in `block in fast_forward_to_first_boundary'
2015-11-04T04:36:07.041133+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/multipart/parser.rb:72:in `loop'
2015-11-04T04:36:07.041134+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/multipart/parser.rb:72:in `fast_forward_to_first_boundary'
2015-11-04T04:36:07.041152+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/multipart/parser.rb:15:in `parse'
2015-11-04T04:36:07.041153+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/multipart.rb:25:in `parse_multipart'
2015-11-04T04:36:07.041154+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/request.rb:377:in `parse_multipart'
2015-11-04T04:36:07.041154+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/request.rb:203:in `POST'
2015-11-04T04:36:07.041155+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/methodoverride.rb:26:in `method_override'
2015-11-04T04:36:07.041156+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/methodoverride.rb:14:in `call'
2015-11-04T04:36:07.041157+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.13.2.302/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
2015-11-04T04:36:07.041157+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call'
2015-11-04T04:36:07.041158+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.13.2.302/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
2015-11-04T04:36:07.041158+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/rack-rewrite-1.5.0/lib/rack/rewrite.rb:24:in `call'
2015-11-04T04:36:07.041159+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.13.2.302/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
2015-11-04T04:36:07.041159+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.5/lib/active_support/cache/strategy/local_cache.rb:83:in `call'
2015-11-04T04:36:07.041160+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.13.2.302/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
2015-11-04T04:36:07.041160+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/actionpack-4.0.5/lib/action_dispatch/middleware/static.rb:64:in `call'
2015-11-04T04:36:07.041161+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.13.2.302/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
2015-11-04T04:36:07.041161+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/sendfile.rb:112:in `call'
2015-11-04T04:36:07.041161+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.13.2.302/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
2015-11-04T04:36:07.041162+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/railties-4.0.5/lib/rails/engine.rb:511:in `call'
2015-11-04T04:36:07.041162+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/railties-4.0.5/lib/rails/application.rb:97:in `call'
2015-11-04T04:36:07.041163+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/railties-4.0.5/lib/rails/railtie/configurable.rb:30:in `method_missing'
2015-11-04T04:36:07.041163+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.13.2.302/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
2015-11-04T04:36:07.041163+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/puma-2.14.0/lib/puma/configuration.rb:78:in `call'
2015-11-04T04:36:07.041164+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/puma-2.14.0/lib/puma/server.rb:541:in `handle_request'
2015-11-04T04:36:07.041164+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/puma-2.14.0/lib/puma/server.rb:388:in `process_client'
2015-11-04T04:36:07.041165+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/puma-2.14.0/lib/puma/server.rb:270:in `block in run'
2015-11-04T04:36:07.041165+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/puma-2.14.0/lib/puma/thread_pool.rb:106:in `call'
2015-11-04T04:36:07.041165+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/puma-2.14.0/lib/puma/thread_pool.rb:106:in `block in spawn_thread'
2015-11-04T04:36:07.523877+00:00 heroku[router]: sock=backend at=error code=H18 desc="Server Request Interrupted" method=POST path="/api/v2/attachments" host=<omitted for security> request_id=a5958dab-8c7c-4121-acc3-54d28be9ad4c fwd="<omitted for security>" dyno=web.1 connect=2ms service=484ms status=503 bytes=154
最佳答案
你应该修补 Rack::Multipart::Parser.fast_forward_to_first_boundary 以添加日志跟踪并确认传递给解析器的内容在到达该函数时为空(即 StringIO 在多部分解析期间被 @env['rack.input'] 引用不返回任何数据)。
关于android - Android 上的 Cordova 应用程序使用 SSL 发送多部分/表单数据导致机架应用程序错误 : #<EOFError: bad content body>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33533618/
我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0
对于具有离线功能的智能手机应用程序,我正在为Xml文件创建单向文本同步。我希望我的服务器将增量/差异(例如GNU差异补丁)发送到目标设备。这是计划:Time=0Server:hasversion_1ofXmlfile(~800kiB)Client:hasversion_1ofXmlfile(~800kiB)Time=1Server:hasversion_1andversion_2ofXmlfile(each~800kiB)computesdeltaoftheseversions(=patch)(~10kiB)sendspatchtoClient(~10kiBtransferred)Cl
我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格:Editingkategori{:action=>'update',:id=>@konkurrancer.id})do|f|%>'Trackingurl',:style=>'width:500;'%>'Editkonkurrence'%>|我的konkurrencer模型:has_one:link我的链接模型:classLink我的konkurrancer编辑操作:defedit@konkurrancer=Konkurrancer.find(params[:id])@konkurrancer.link_attrib
大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
Rackup通过Rack的默认处理程序成功运行任何Rack应用程序。例如:classRackAppdefcall(environment)['200',{'Content-Type'=>'text/html'},["Helloworld"]]endendrunRackApp.new但是当最后一行更改为使用Rack的内置CGI处理程序时,rackup给出“NoMethodErrorat/undefinedmethod`call'fornil:NilClass”:Rack::Handler::CGI.runRackApp.newRack的其他内置处理程序也提出了同样的反对意见。例如Rack
我想用ruby编写一个小的命令行实用程序并将其作为gem分发。我知道安装后,Guard、Sass和Thor等某些gem可以从命令行自行运行。为了让gem像二进制文件一样可用,我需要在我的gemspec中指定什么。 最佳答案 Gem::Specification.newdo|s|...s.executable='name_of_executable'...endhttp://docs.rubygems.org/read/chapter/20 关于ruby-在Ruby中编写命令行实用程序
我构建了两个需要相互通信和发送文件的Rails应用程序。例如,一个Rails应用程序会发送请求以查看其他应用程序数据库中的表。然后另一个应用程序将呈现该表的json并将其发回。我还希望一个应用程序将存储在其公共(public)目录中的文本文件发送到另一个应用程序的公共(public)目录。我从来没有做过这样的事情,所以我什至不知道从哪里开始。任何帮助,将不胜感激。谢谢! 最佳答案 无论Rails是什么,几乎所有Web应用程序都有您的要求,大多数现代Web应用程序都需要相互通信。但是有一个小小的理解需要你坚持下去,网站不应直接访问彼此
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
刚入门rails,开始慢慢理解。有人可以解释或给我一些关于在application_controller中编码的好处或时间和原因的想法吗?有哪些用例。您如何为Rails应用程序使用应用程序Controller?我不想在那里放太多代码,因为据我了解,每个请求都会调用此Controller。这是真的? 最佳答案 ApplicationController实际上是您应用程序中的每个其他Controller都将从中继承的类(尽管这不是强制性的)。我同意不要用太多代码弄乱它并保持干净整洁的态度,尽管在某些情况下ApplicationContr