[1.4.2] Problem HTTPS redirection

14 views
Skip to first unread message

Xavier NOPRE

unread,
Oct 13, 2016, 5:42:10 AM10/13/16
to playone
Hi,

In my controller, in some cases, I need to do a redirection to another action in the controller. In my Java code, calling a "static public" other method in the controller is handled by Play! that respond with an HTTP redirection 301 with the new URL.

My problem is that I am using HTTPS protocol, but the redirection is done with an HTTP url. 

How can I do that Play! do a correct HTTPS redirection ?

Thanks for your help !

Best regards,

Xavier

green

unread,
Oct 13, 2016, 5:47:35 AM10/13/16
to playone
Usually I setup an nginx instance to redirect all HTTP request automatcially to HTTPS and have nginx handle the SSL connection:

server {
  listen 80 ;
  server_name     *.myapp.org;
  return 301 https://$host$request_uri;
}


--
You received this message because you are subscribed to the Google Groups "playone" group.
To unsubscribe from this group and stop receiving emails from it, send an email to playone+u...@googlegroups.com.
To post to this group, send email to pla...@googlegroups.com.
Visit this group at https://groups.google.com/group/playone.
For more options, visit https://groups.google.com/d/optout.

Xavier NOPRE

unread,
Oct 13, 2016, 8:16:52 AM10/13/16
to playone
Hi,

Thank you for your answer.

I use too a nginx in front of my application. This is not the problem. The user car access to my application in HTTPS protocol. In some cases, I have to do redirection to other actions (in same controller), and Play! handles this by an HTTP redirection 302, but providing the new location but with http://... instead of https://... 

My question is : how to do with Play! so that all redirection are providing new location URLs with HTTPS protocol ?

Thanks,

Regards,

Xavier










2016-10-13 11:47 GMT+02:00 green <green...@gmail.com>:
Usually I setup an nginx instance to redirect all HTTP request automatcially to HTTPS and have nginx handle the SSL connection:

server {
  listen 80 ;
  server_name     *.myapp.org;
  return 301 https://$host$request_uri;
}


On Thu, Oct 13, 2016 at 8:42 PM Xavier NOPRE <xno...@gmail.com> wrote:
Hi,

In my controller, in some cases, I need to do a redirection to another action in the controller. In my Java code, calling a "static public" other method in the controller is handled by Play! that respond with an HTTP redirection 301 with the new URL.

My problem is that I am using HTTPS protocol, but the redirection is done with an HTTP url. 

How can I do that Play! do a correct HTTPS redirection ?

Thanks for your help !

Best regards,

Xavier

--
You received this message because you are subscribed to the Google Groups "playone" group.
To unsubscribe from this group and stop receiving emails from it, send an email to playone+unsubscribe@googlegroups.com.

To post to this group, send email to pla...@googlegroups.com.
Visit this group at https://groups.google.com/group/playone.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "playone" group.
To unsubscribe from this group and stop receiving emails from it, send an email to playone+unsubscribe@googlegroups.com.

Israel Tsadok

unread,
Oct 13, 2016, 8:24:25 AM10/13/16
to pla...@googlegroups.com
Hey Xavier,
Check out my plugin for fixing the issue: https://github.com/itsadok/play-https-redirect-fixer

(The plugin is really just for very lazy people. The fix is tiny, and you can read the linked article for more information).

Xavier NOPRE

unread,
Oct 14, 2016, 10:17:09 AM10/14/16
to playone
Hi Israel !

Many thanks for your answer, and especially for the link to the article.

For me, the solution was to add special header in my Nginx conf : 

proxy_set_header x-forwarded-proto https;


And then, in my controller, in a @Before method, to get this header, if it exists, and to change 'request' properties if necessary :

@Before
public static void setSecuredAndPortInRequestIfNecessary() {
final Header xForwardedProtoHeader = request.headers.get("x-forwarded-proto");
if (xForwardedProtoHeader != null && "https".equals(xForwardedProtoHeader.value())) {
request.secure = true;
request.port = 443;
}
}

Thanks Israel !!

Regards,

Xavier




Reply all
Reply to author
Forward
0 new messages