rack

How to dump an HTTP request from within Sinatra?

大城市里の小女人 提交于 2019-11-29 20:28:27
Is there a way to dump all incoming requests to a Sinatra application in the exact way the application receives the data? Maybe some sort of Rack middleware? include I run thin with the -D and -V flags when I want to debug 'things': $ thin start -p 3000 -R config.ru -D -V -D, --debug Set debbuging on -V, --trace Set tracing on (log raw request/response) If you are trying to get the raw output from a request, use the request method like: # app running on http://example.com/example get '/foo' do request.body # request body sent by the client (see below) request.scheme # "http" request.script

What's the difference between request.remote_ip and request.ip in Rails?

核能气质少年 提交于 2019-11-29 20:23:13
As the title goes, you can get the client's ip with both methods. I wonder if there is any differences. Thank you. in the source code there goes "/usr/local/rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.3/lib/action _dispatch/http/request.rb" 257L, 8741C def ip @ip ||= super end # Originating IP address, usually set by the RemoteIp middleware. def remote_ip @remote_ip ||= (@env["action_dispatch.remote_ip"] || ip).to_s end but I really don't know the implications. From source: module ActionDispatch class Request < Rack::Request # ... def ip @ip ||= super end def remote_ip @remote_ip ||= (@env[

Instance_eval block not supplied? [duplicate]

独自空忆成欢 提交于 2019-11-29 17:21:52
This question already has an answer here: Code block passed to each works with brackets but not with 'do'-'end' (ruby) 3 answers Does anybody know what's causing this error? I'm trying to make a basic rack application. App.rb => class Cherry class << self def app &block Cherry::Application.new &block end end class Application def initialize &block instance_eval &block end def print_start_message puts "Starting server" end def call env [200, {"Content-type" => "text/plain"}, "Hello World"] end end end Config.ru => require 'app' run Cherry.app do print_start_message end EDIT: Apparently I forgot

How to force rack to work around the usual “You have already activated rack…” bug?

时光毁灭记忆、已成空白 提交于 2019-11-29 16:49:57
问题 This is a common question, but none of the answers seem to solve the issue. I get the usual: You have already activated rack 1.4.1, but your Gemfile requires rack 1.3.6. Using bundle exec may solve this. Clearing the Gemlock file did nothing and running bundle install again did nothing...running bundle install --binstubs did not solve the issue as "run ./bin/{rake|rails|etc} from your app root" just caused more errors. Is there a way to get rack around this apparently common problem? 回答1: The

How to decode a cookie from the header of a websocket connection handshake? (Ruby)

我们两清 提交于 2019-11-29 11:21:29
I am running a Sinatra app within an EventMachine.run loop and in my ws.onopen method I wish to check the handshake header's cookie to ensure that the incoming request is coming from a registered user of my webapp. My Sinatra app includes the following: use Rack::Session::Cookie, :key => COOKIE_KEY, :path => '/', :expire_after => 2592000, #30 days :secret => COOKIE_SECRET and my ws.onopen method looks like this (trimmed) ws.onopen { |handshake| cookie, bakesale = handshake.headers['Cookie'].split('=') rack_cookie = Rack::Session::Cookie.new(MyApp, { :key => COOKIE_KEY, :path => '/', :expire

How can I pass SSL options into “rails server” in Rails 3.0?

不想你离开。 提交于 2019-11-29 07:16:27
Is there a way to pass SSL options into "rails server" (on Rails 3.0.0), using a custom Rack config or something similar? I'm trying to do two things: enable Cucumber to run tests that involve both secure and non-secure URL's, and make things simple for new developers, so they don't have to set up Apache and configure all the SSL/cert stuff before they can even write a line of code. On 2.3.8 we had a forked script/server that would start up a special WEBrick on a second port with all the appropriate SSL options. Of course that blew up when I tried upgrading to Rails 3, so I'm trying to figure

Trigger Rack middleware on specific Rails routes

扶醉桌前 提交于 2019-11-29 06:17:46
Is it possible to trigger Rack middleware only on specific Rails routes? For example, let's say I wanted to run a rate limiter middleware only on the api namespace. namespace :api do resources :users end I've had good success with Rack::Throttle for rate limiting. Subclass one of the built-in throttle classes and overload the allowed? method. Your custom logic can check which controller is being accessed and apply the rate limit as needed. class ApiThrottle < Rack::Throttle::Hourly ## # Returns `false` if the rate limit has been exceeded for the given # `request`, or `true` otherwise. # # Rate

Sinatra and Rack Protection setting

感情迁移 提交于 2019-11-29 03:31:15
I am using Sinatra and CORS to accept a file upload on domain A (hefty.burger.com). Domain B (fizzbuzz.com) has a form that uploads a file to a route on A. I have an options route and a post route, both named '/uploader'. options '/uploader' do headers 'Access-Control-Allow-Origin' => 'http://fizz.buzz.com', 'Access-Control-Allow-Methods' => 'POST' 200 end post '/uploader' do ... content_type :json [{:mary => 'little lamb'}].to_json end The options gets hit first... and it works.. then the post gets hit and returns a 403. If I disable protection, the post works... what kind of protection do I

UnderReplicatedBlocks处理流程

£可爱£侵袭症+ 提交于 2019-11-29 03:18:03
hdfs处理block副本不足、分布不合理的流程如下: 优先级解释: QUEUE_HIGHEST_PRIORITY: the blocks that must be replicated first. That is blocks with only one copy, or blocks with zero live copies but a copy in a node being decommissioned. These blocks are at risk of loss if the disk or server on which they remain fails. QUEUE_VERY_UNDER_REPLICATED: blocks that are very under-replicated compared to their expected values. Currently that means the ratio of the ratio of actual:expected means that there is less than 1:3.These blocks may not be at risk, but they are clearly considered "important". QUEUE_UNDER_REPLICATED:

How to parse JSON request body in Sinatra just once and expose it to all routes?

穿精又带淫゛_ 提交于 2019-11-29 02:51:46
I am writing an API and it receives a JSON payload as the request body. To get at it currently, I am doing something like this: post '/doSomething' do request.body.rewind request_payload = JSON.parse request.body.read #do something with request_payload body request_payload['someKey'] end What's a good way to abstract this away so that I don't need to do it for each route? Some of my routes are more complicated than this, and as a result the request.body would get reread and reparsed several times per route with this approach, which I want to avoid. Is there some way to make the request_payload