Jruby-rack redirect problem

I haven’t gotten a chance to drill down into this yet, but I’m going
to throw it out in case it brings something obvious to anyone’s mind.
We have some JRuby/Rails apps which were previously deployed into
Tomcat with Goldspike/Warbler-0.9.3. When I switched them over to
Warbler-0.9.9/jruby-rack-0.9 we’re all of a sudden seeing problems
with redirects incorrectly switching from https to http.

For example, a controller action that was reached through https://
ourdomain.com/controller_a/action_a does a redirect_to url_for
(:controller=>‘controller_a,’ :action => ‘action_b’). The actual
redirect location sent to the browser winds up as http://
ourdomain.com/controller_a/action_b with the wrong protocol.

Sorry for the generic example. I’ll try to isolate this down to
something more concrete in a few days.

-lenny

JRuby-1.2.2
Rails-2.0.2


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Tue, Jun 10, 2008 at 3:12 PM, Lenny M. [email protected] wrote:

redirect location sent to the browser winds up as
http://ourdomain.com/controller_a/action_b with the wrong protocol.

Sorry for the generic example. I’ll try to isolate this down to something
more concrete in a few days.

Could be something broken in URL scheme detection. Which of these
environment variables headers are you expecting to fire?

# Is this an SSL request?
def ssl?
  @env['HTTPS'] == 'on' || @env['HTTP_X_FORWARDED_PROTO'] == 'https'
end

JRuby-Rack fetches servletRequest.getScheme and stores it in
env[‘rack.url_scheme’] only:

  def add_input_errors_scheme(servlet_env, env)
    ...
    env['rack.url_scheme'] = servlet_env.getScheme
    ...
  end

Could that be the difference?

/Nick


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Jun 10, 2008, at 7:10 PM, Nick S. wrote:

Could be something broken in URL scheme detection. Which of these
environment variables headers are you expecting to fire?

# Is this an SSL request?
def ssl?
  @env['HTTPS'] == 'on' || @env['HTTP_X_FORWARDED_PROTO'] ==  

‘https’
end

Could that be the difference?

/Nick

Yes I guess Goldspike must have handled extending the rails Request
to respond correctly based on the ServletRequest.

I put the following debug statements in my app:


logger.debug “ssl: #{request.ssl?}”
logger.debug “url_for: #{url_for(:controller => ‘default’, :action =>
‘logout’)}”
if servlet_request
logger.debug “request scheme: #{servlet_request.getScheme}”
end

which output this:

ssl: false
url_for: http://prism.alpha.aps.org/OutCorr/default/logout
request scheme: https

Looking at the source for AbstractRequest#protocol I can see how the
URL is put together incorrectly.

def protocol
ssl? ? ‘https://’ : ‘http://’
end

With Goldspike:

logger.debug “ssl: #{request.ssl?}”
logger.debug “url_for: #{url_for(:controller => ‘default’, :action =>
‘logout’)}”
if $java_servlet_request
logger.debug “request scheme: #{$java_servlet_request.getScheme}”
end

outputs:

ssl: true
url_for: https://prism.alpha.aps.org/RefereeSelect/default/logout
request scheme: https

-lenny


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Jun 10, 2008, at 10:42 PM, Lenny M. wrote:

which output this:

ssl: false
url_for: http://prism.alpha.aps.org/OutCorr/default/logout
request scheme: https

Thanks for the debugging info. I’ve updated JRuby-Rack trunk to set
the ‘HTTPS’ variable for Rails if the servlet request scheme is https.

Until I make a new release, you might consider monkey-patching the
ActionController request method like so:

class ActionController::AbstractRequest
def ssl?
@env[‘HTTPS’] == ‘on’ || @env[‘HTTP_X_FORWARDED_PROTO’] ==
‘https’ || @env[‘rack.url_scheme’] == ‘https’
end
end

Cheers,
/Nick


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email