postrank-labs / goliath

Goliath is a non-blocking Ruby web server framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rack.url_scheme not set causing errors for Rack::Request's scheme method

LouisStAmour opened this issue · comments

Just a short note that I'm not the only one having to write env['rack.url_scheme'] ||= 'http' in my Goliath::API response to fix this bug -- I've also seen it at https://gist.github.com/1299631/c6a1698af73ec5876b5a85e6d057dd7f6395f1f6 with the comment "weird" ;-)

I also had odd behaviour with Rack::Request's path method returning double -- it combines @env["SCRIPT_NAME"] and @env["PATH_INFO"] which were both set to /resource/method, so instead of /resource/method I got /resource/method/resource/method. We need to follow http://rack.rubyforge.org/doc/files/SPEC.html which clearly states the purpose of these variables and on these it says quite clearly:

  • rack.url_scheme must either be http or https.
  • The SCRIPT_NAME, if non-empty, must start with /
  • The PATH_INFO, if non-empty, must start with /
  • One of SCRIPT_NAME or PATH_INFO must be set. PATH_INFO should be / if SCRIPT_NAME is empty. SCRIPT_NAME never should be /, but instead be empty.

This exact issue is plaguing us as well. Our Goliath server is interested in the Rack::Request.new(env).fullpath but the path segment is duplicated.

Steps to reproduce. https://gist.github.com/4237585

Wow! Finally I found related issue and this is it :-)

+100. Having same problems in my Goliath + Grape app

I just ran into those problems. Here is what I do for now :

class App < Goliath::API
  use Rack::Config do |env|
    env['rack.url_scheme'] ||= 'http'
    env['SCRIPT_NAME'] = nil
  end

   def response(env)
     Api.call(env) # Calling the grape API
   end
end

Running into this need to set SCRIPT_NAME to nil while building an updated instrumentation for New RElic 3.6.x (I have something much simpler than the previous method working and am working on an example) and wondered why I was getting duplicate URIs in my instrumentation.

Does Goliath use the SCRIPT_NAME header for any of its under-the-hood purposes, or is it safe to set SCRIPT_NAME to nil if the app itself isn't making use of it?

@impact11 I believe the answer is "no"... quick grep doesn't turn up anything interesting.