rack

Rack rack.input variable getting truncated?

北城余情 提交于 2019-12-12 08:47:36
问题 I wrote a piece of Rack Middleware to automatically unzip compressed request bodies. The code seems to be working just fine, but when I plug it into my rails app, I get a failure "Invalid JSON" from ActionController::ParamsParser. As a debugging mechanism, I'm writing both the zipped content, and the unzipped content to a file (to make sure that code is working properly) and I do receive my original JSON document (before the client zips it up). The data I'm posting is JSON data, and the

Rack Session Cookie and Sinatra - setting and accessing data

こ雲淡風輕ζ 提交于 2019-12-12 08:35:37
问题 I was using Rack Session Pool, however my users would get kicked off one webserver thread onto another making the session data expire. I started toying around with just enable :sessions in Sinatra, however I am unable to use that because I have mutliple apps using Sinatra (same key it appears to be using - not sure if this is because its the same host or not) So since my apps would break each other, I now am trying Rack Session Cookie and setting the variables (same thing as enable :sessions,

return json from ruby using rack

Deadly 提交于 2019-12-12 04:17:34
问题 i'm still fairly new to server side scripts and try myself a little bit on ruby to write me little helpers and to learn some new things. I currently try to write a small ruby app which sends a json file of all images within a specific folder to my page where i can use those to handle them further in js. I read quite a few introductions to ruby and rails and got a recommendation to look into rack as a lightweight communicator between server and app. While the ruby part works fine, i have

RackEnv not respected when using route helpers from model

落花浮王杯 提交于 2019-12-12 01:35:26
问题 Running Rails 3.2.13 on Passenger for Apache. My vhost: <VirtualHost *:80> ServerName server DocumentRoot /srv/http <Directory /> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> RackEnv test RackBaseURI /rails_app <Directory /srv/http/rails_app> Options -MultiViews </Directory> </VirtualHost> Works great. Only problem is that I'm using the route url helpers in a model, like so: # egg.rb def to_exhibit return { :edit_path => Rails

Modify Rack App

回眸只為那壹抹淺笑 提交于 2019-12-11 15:36:31
问题 For one of my ruby applications i need the server to route requests based on the subdomain. There are ways to do this using other gems but i decided to make my own "middleware". This code runs applications based on where the request is going to. config.ru require './subdomain' require './www' run Rack::Subdomain.new([ { :subdomain => "test", :application => Sinatra::Application } ]); subdomain.rb module Rack class Subdomain def initialize(app) @app = app end def call(env) @app.each do |app|

In Sinatra, is there a way to forward a request to another app?

霸气de小男生 提交于 2019-12-11 15:36:25
问题 I'm trying to do something like this: class Dispatcher < Sinatra::Base def initialize @foo = Foo.new end get '/foo/*' do @foo.call(params[:splat]) end end So that URL /foo/abc/def?xxx=yyy would be like calling the Foo app with /abc/def?xxx=yyy. This seems like it should be easy, but I haven't seen any example of it. 回答1: I ended up doing this in a Rack config.ru file: map "/abc" do run Foo.new('abc') end map "/def" do run Foo.new('def') end Not exactly what I wanted, but saves me from

Post request parameters getting truncated in Rails 4.2.2 with content type as “Application/xml”

Deadly 提交于 2019-12-11 12:47:57
问题 I have this below observation: I deployed a sample Rails 4.2.2 application with a controller and action to receive a POST request. Now If I send a POST request to this application with some POST body say a hash like {"1"=>"hello","2"=>"bye"} and if the content type of the request is "application/xml" , I don't receive any parameters in my Rails app. If I change content type of the same request to some thing else , I will get the parameters properly. Can some one please tell my why this

OCRA missing submodules of libraries if rack/grape api endpoints aren't called

六眼飞鱼酱① 提交于 2019-12-11 09:52:09
问题 I'm trying to pack my REST app into into an executable with OCRA. I have a few gems required in my script: require 'rack' require 'rack/server' require 'grape' require 'grape-entity' require 'rubygems' I skip starting the server with this: if not defined?(Ocra) Rack::Server.start options end When I try to run my server.exe: Temp/../server.rb:221:in `default_middleware_by_environment': cannot load such file -- rack/content_length (LoadError) Which means that it doesn't detect submodules of

Calling Sinatra from Sinatra produces results different from external request

∥☆過路亽.° 提交于 2019-12-11 08:27:33
问题 Following my question here. So I am trying to do a smart redirect using this: get "/category/:id/merge" do #... setting @catalog_id and category call env.merge("PATH_INFO" => "/catalog/#{@catalog_id}/category/#{category.id}", "REQUEST_METHOD"=>"PATCH","QUERY_STRING"=>"merge=1") status 200 end But when I look in logs, I see something that is not only frustrating but also completely absurd: # this one is from internal call I, [2013-03-21T15:55:54.382153 #29569] INFO -- : Processing GET /catalog

What's the Rails.root equivalent in a Rack application?

陌路散爱 提交于 2019-12-11 04:14:59
问题 I'm familiar with the Rails.root in Rails which tells you the directory of your current application. This is quite handy sometimes. Now I'm developing a Rack application (on which Rails is based). How do I find out the Rails.root equivalent for a Rack application? Thank you. 回答1: This returns the root directory in a string. Rack::Directory.new('').root Not sure if there's a better, shorter syntax. 回答2: What worked for me is a simple File.expand_path : File.expand_path(File.join("log", "some