litespeed+rails "request_uri" incorrect

#1
I suspect this is a litespeed bug. Take the following Ruby on Rails code in my view:

Code:
[FONT="Courier New"][COLOR="Blue"]Request: <%= @controller.request.request_uri  %><br/>
Current?: <%= CGI.escapeHTML(url_for({ :controller => '/status', :action => 'main' })) %>[/COLOR][/FONT]
In Windows/Webrick, when on the /status/main page, this returns the expected:

Request: /status/main
Current?: /status/main


But on my Redhat (ES 3) server, running Litespeed 2.2 Std, that same code produces:

Request: status/main
Current?: /status/main


note the missing slash returned by request_uri

Since this works on other web servers, I suspect its a mistake in how Litespeed is responding to Rails. This crucially needs to be fixed, as it causes various Rails functions to fail, such as current_page? and, more importantly, link_to_unless_current

I'm currently evaluating this for a corporate product and I've been very impressed with Litespeed 2.2's Rails support. Performance blows away other Rails servers so far... good job!

thanks
 
Last edited:

mistwang

LiteSpeed Staff
#2
That's strange, we could not reproduce it in our lab.
What's your Rails release? How is the rails application configured? Any rewrite rule involved?

What is the value of 'ENV[REQUEST_URI]'?
 
#3
Rails 1.1.6. no special configuration except one mapping change in routes.rb:

map.connect '', :controller => "status"

ENV['REQUEST_URI'] comes up as:

status/main

Same value as request.request_uri

I fixed the bug for my app by overriding request_uri method in the ActionController::AbstractRequest module in my app's environment.rb (my changes in red):

Code:
[FONT="Courier New"][COLOR="Blue"]module ActionController
  class AbstractRequest
    def request_uri
      if uri = @env['REQUEST_URI']
        [COLOR="Red"]uri = [/COLOR](%r{^\w+\://[^/]+(/.*|$)$} =~ uri) ? $1 : uri # Remove domain, which webrick puts into the request_uri.
        [COLOR="Red"]uri = (%r{^/.*} =~ uri) ? uri : uri.insert(0,'/') # adds a preceding / if necessary[/COLOR]
      else  # REQUEST_URI is blank under IIS - get this from PATH_INFO and SCRIPT_NAME
       script_filename = @env['SCRIPT_NAME'].to_s.match(%r{[^/]+$})
       uri = @env['PATH_INFO']
       uri = uri.sub(/#{script_filename}\//, '') unless script_filename.nil?
       unless (env_qs = @env['QUERY_STRING']).nil? || env_qs.empty?
         uri << '?' << env_qs
       end
       uri
      end
    end
  end
end[/COLOR][/FONT]
...but this is clearly a sub-optimal solution since now I'm essentially 'freezing' that Rails method even if the Rails developers change it in later releases.
 

mistwang

LiteSpeed Staff
#4
Are you using our esay rails configuration? any customization on configuration at LSWS side?
It does looks like the leading '/' is missing for some reason, but I simply cannot reproduce it here, I made the routing change. Can you create a simple testapp on that server to verify the problem?

Is that a 64bit server? Do you have another server to try it out?
I need to figure out what exactly cause the problem, OS? LSWS configuration? Rails configuration?
 
#5
Unfortunately, it's an internal company server, so I can't expose it for you to test, but here's all the specs I can give you:

  • HP Proliant DL380
  • Redhat ES 3 (32-bit)
  • Ruby 1.8.5 + Rails 1.1.6
  • Using easy rails config; created a 'RubyVHost'
  • Enable Rewrite = no; Rewrite Rules N/A
  • under Context tab: Type = "Rails", URI = "/", Sequence = "1 + / -"

Other than that, it's a pretty normal Rails app. Nothing really special.
 
Top