# Jruby-rack redirect problem

**URL:** <https://www.ruby-forum.com/t/jruby-rack-redirect-problem/140102>\
**Category:** JRuby\
**Created:** [June 10, 2008, 10:13pm UTC](https://www.ruby-forum.com/t/jruby-rack-redirect-problem/140102 "2008-06-10T22:13:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lennylmiller](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/7cd45c/32.png) [@lennylmiller](https://www.ruby-forum.com/u/lennylmiller)\
**Post date:** [June 10, 2008, 10:13pm UTC](https://www.ruby-forum.com/t/jruby-rack-redirect-problem/140102/1 "2008-06-10T22:13:16Z")

</div>

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](http://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](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

```

---

<div class="post-metadata">

**Author:** ![lennylmiller](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/7cd45c/32.png) [@lennylmiller](https://www.ruby-forum.com/u/lennylmiller)\
**Post date:** [June 11, 2008, 1:11am UTC](https://www.ruby-forum.com/t/jruby-rack-redirect-problem/140102/2 "2008-06-11T01:11:13Z")

</div>

On Tue, Jun 10, 2008 at 3:12 PM, Lenny M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> redirect location sent to the browser winds up as  
> [http://ourdomain.com/controller\_a/action\_b](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

```

---

<div class="post-metadata">

**Author:** ![lennylmiller](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/7cd45c/32.png) [@lennylmiller](https://www.ruby-forum.com/u/lennylmiller)\
**Post date:** [June 11, 2008, 5:42am UTC](https://www.ruby-forum.com/t/jruby-rack-redirect-problem/140102/3 "2008-06-11T05:42:39Z")

</div>

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](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](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

```

---

<div class="post-metadata">

**Author:** ![lennylmiller](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/7cd45c/32.png) [@lennylmiller](https://www.ruby-forum.com/u/lennylmiller)\
**Post date:** [June 11, 2008, 6:11am UTC](https://www.ruby-forum.com/t/jruby-rack-redirect-problem/140102/4 "2008-06-11T06:11:18Z")

</div>

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](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

```
