redirect not working for https

2 views
Skip to first unread message

360R8

unread,
Sep 7, 2008, 2:49:57 AM9/7/08
to Ramaze
hi all,

I am working on a secure site where I rewrite any http to https. I use
redirect and call extensively, and it is not working for SSL enabled
site. This is what happen:

request /mycontroller/
Redirect to 'http://mydomain/mycontroller' #ramaze redirect to http://
despite working in https://
request / #nginx rewrite http to https, returning the root

I looked into redirect.rb and found raw_redirect, and it works. I
think the https check in redirect is not functioning as it should.
Unfortunately I have no idea what %r!^https?://! means, let alone
fixing it...

Michael Fellinger

unread,
Sep 7, 2008, 5:28:01 AM9/7/08
to ram...@googlegroups.com

It means: /^https?:\/\//
Which means a match for any string that starts with either:
'https://' or 'http://', the %r!! syntax is one of many ways to define
a regular expression.
This, however is only to make sure that URIs that start with one of
these are not modified but directly passed to raw_redirect.
So if you do a:
redirect('https://localhost:7000/foo') it will redirect using https.
That's a bit awkward of course but i just wanted to point out that
this code in itself doesn't do any kind of detection of which protocol
you are using.
That would be done by asking Request#scheme

So, in order to have redirects working with https we have to change
following line:
http://github.com/manveru/ramaze/tree/master/lib/ramaze/helper/redirect.rb#L50

The way would be to ask Current.request.scheme about the prefix we
need and replace the static 'http' with that.
I would appreciate your help on this, as i don't have an https setup right now.

^ manveru

360R8

unread,
Sep 11, 2008, 1:53:36 AM9/11/08
to Ramaze
Hi Michael,

I created a helper call redirect in my app to override the default
redirect. Using your recommendation, it is still not working.

target[0,0] = "#{Current.request.scheme}://#{host}"

Actually all of the following returns the value http, despite the fact
that I'm using a https connection:

Current.request.scheme
Current.request.env['rack.url_scheme']
request.env['rack.url_scheme']

Please advice...
> following line:http://github.com/manveru/ramaze/tree/master/lib/ramaze/helper/redire...

360R8

unread,
Sep 11, 2008, 12:33:56 PM9/11/08
to Ramaze
OK, I have a fix. The problem was that rack lost track of the protocol
when there's a proxy in front.

Now... I need to learn git and how to submit a patch...

man, it feels good to be able to contribute something!

Michael Fellinger

unread,
Sep 11, 2008, 2:34:41 PM9/11/08
to ram...@googlegroups.com
On Fri, Sep 12, 2008 at 1:33 AM, 360R8 <sea...@gmail.com> wrote:
>
> OK, I have a fix. The problem was that rack lost track of the protocol
> when there's a proxy in front.
>
> Now... I need to learn git and how to submit a patch...
>
> man, it feels good to be able to contribute something!

Thanks a lot for your effort, contributing a patch may be done this way:
git clone git://github.com/manveru/ramaze
cd ramaze # do your modifications
git add -p # choose what to submit
git commit # enter a title
git format-patch
for patch in *.patch; do
curl -F "text=<$patch;type=text/plain" -F "syntax=diff"
http://p.ramaze.net/save
done

And send us a mail with the URLs of the patches... or use 'git
send-email' to m.fel...@gmail.com
you may also use the procedure from github...

^ manveru

Reply all
Reply to author
Forward
0 new messages