rack

Multipart response in Ruby/Rack

淺唱寂寞╮ 提交于 2019-12-09 01:23:50
问题 I want my server to send a multipart response (multipart/x-mixed-replace). I'd prefer some kind of solution using the Sinatra framework or a generic Rack app, but any example in ruby would be nice. Here's the equivalent of what I'm trying to do, in PHP: <?php header('Content-type: multipart/x-mixed-replace;boundary="rn9012"'); print "--rn9012\n"; print "Content-type: application/xml\n\n"; print "<?xml version='1.0'?>\n"; print "<content>First Part</content>\n"; print "--rn9012\n"; flush();

Where should I set HTTP headers, such as Expires?

爷,独闯天下 提交于 2019-12-08 09:50:25
问题 I want to deploy an app using Sinatra on Phusion Passenger w/ nginx. If I want to set the Expires header on my static content - stylesheets, say - there are appear to be three places where I could accomplish this. In my Sinatra app, using the API With Rack middleware In the server config for my deployment Which of these methods is the best place for setting HTTP headers? 回答1: After talking though and answering this question and seeing the comment above, I think I have figured out the answer

How to harden rails+webrick+https with insecure ciphers removed on Ruby 2.2

↘锁芯ラ 提交于 2019-12-08 06:30:03
问题 Updated: At first, my test code didn't adequately show ruby 2.4 sees the :SSLCiphers option whereas ruby 2.2 does not. I have edited the example code below to make that clear. Updated: Since my question failed to elicit any help from the community, I forged on ahead and two days later found the solution, which I have included below. I have a small Rails 3 application on Ruby 2.2 and Webrick that handles small loads and therefore does not need the complexity of a "real" web server. It has been

Rack::ResponseHeaders in rackup for Sinatra

血红的双手。 提交于 2019-12-08 03:52:34
问题 I think this is a very easy one, but I can't seem to get it right. Basically, I'm trying to use Rack middleware to set a default Cache-Control header into all responses served by my Sinatra app. It looks like Rack::ResponseHeaders should be able to do exactly what I need, but I get an error when attempting to use the syntax demonstrated here in my rackup file: use Rack::ResponseHeaders do |headers| headers['X-Foo'] = 'bar' headers.delete('X-Baz') end I was able to get Rack::Cache to work

Anyone using JRuby-Rack with Rails 3?

三世轮回 提交于 2019-12-08 02:18:34
问题 Is anyone else out there running Rails 3 and JRuby-Rack, or Jetty and Rails 3? Any trick to it? I'm going insane with some debugging, and at this point I just want to know that it's possible. 回答1: These instructions work for me: http://mathias-biilmann.net/2010/2/jruby-and-rails-3-beta-step-by-step 回答2: i am using jetty-rails + rails3 for a couple of projects. jetty-rails need to be fixed , require "activesupport" need to be changed to require "active_support" (for activesupport 3.0.3) and

Adaptive images for ruby based servers

蹲街弑〆低调 提交于 2019-12-08 01:30:23
问题 I'd like to deliver images to client based on the size of the user screen, as in If I have High resolution image, and the user want to view it on a mobile I don't want to send the full HD image, instead I'd like to send the image shrinked to the user's device dimension which will increase the loading speed on low bandwidth devices There is a solution for this here Adaptive Images detects your visitor's screen size and automatically creates, caches, and delivers device appropriate re-scaled

大规模机器集群-故障自动处理(二)

我们两清 提交于 2019-12-07 19:25:31
本篇开始介绍具体的实现过程,为表述方便,先定义一些名词, _AutoRepairSystem: _ 故障自动维修系统, 缩写为ARS 原子操作: 任务的最小操作,机器任务通常是指重启、重装 运维人员:运维工程师= SRE = OP,系统工程师 = sys 远程管理工具: 远程控制操作物理机器的工具,如ipmi、ilo 先来看ARS的整体视图和流程图, ARS的工作流程, 故障检测: 每5分钟发起一次故障检测,获取当前时刻整个集群的故障机器列表,推送到工作流子系统 安全策略: 遍历故障机器列表,依次执行安全策略,过滤不符合要求的机器,得到一个可安全执行重启、重装的机器列表 服务离线: 遍历可安全操作的机器列表,执行服务离线 故障维修: 服务离线后,发起重启、维修操作,轮询机器状态,直至重启成功或维修完成 环境初始化: 执行环境初始化,保证机器环境符合业务需求 服务上线: 恢复服务,检查服务达到可服务状态,流程结束 接下来将介绍工作流子系统,这是所有具体操作任务执行的基础; 再依次介绍上述流程中的关键环节: 服务上下线,故障检测,安全策略,维修工具及SLA; 然后通过一个线上例子,说明整体的工作流程; 最后分享系统上线后的运行数据。 2.1 工作流子系统 工作流最基本的功能,是驱动一系列预定义任务顺序执行,达到明确的结束状态;在机器故障自动处理这个问题域里,对工作流还有闭环

Rails: losing quotes in post parameters

一笑奈何 提交于 2019-12-07 15:55:39
问题 I'm adding full-text search to my Rails site and allowing users to enter double quotes in the search input box. The problem is that the double quotes seem to get filtered out by Mongrel and so I never receive those quotes in the values of the params hash. How do I prevent this from happening? I'm running Rails 2.3.8. [Edit: added analysis data] In Firebug I see the post parameter being posted correctly with quotes: search_criteria "great post" In the development log, however, the quotes are

rack-timeout: turn off info/active logging

一笑奈何 提交于 2019-12-07 13:56:20
问题 With the rack-timeout gem installed how is it possible to display ERROR only related logs? For example I would like to avoid having the below in my logs: source=rack-timeout id=8a11a8ac3dadb59a4f347d8e365faddf timeout=20000ms service=0ms state=active source=rack-timeout id=8a11a8ac3dadb59a4f347d8e365faddf timeout=20000ms service=49ms state=completed source=rack-timeout id=ee947d4a291d02821ab108c4c127f555 timeout=20000ms state=ready The following did not work: Rack::Timeout.unregister_state

How to harden rails+webrick+https with insecure ciphers removed on Ruby 2.2

你。 提交于 2019-12-07 13:44:31
Updated: At first, my test code didn't adequately show ruby 2.4 sees the :SSLCiphers option whereas ruby 2.2 does not. I have edited the example code below to make that clear. Updated: Since my question failed to elicit any help from the community, I forged on ahead and two days later found the solution, which I have included below. I have a small Rails 3 application on Ruby 2.2 and Webrick that handles small loads and therefore does not need the complexity of a "real" web server. It has been patched to support https connections for secure logins, but by default, it accepts many old weak