Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a link that takes you back from https to http?

I have this link on my page (page1):

<a href="@{Controller.action1().secure()}">Link1</a> 

that takes me to a page (page2) over https. How to make a link on page2 that takes me back from https to http? I thought @@ notation would do the trick:

<a href="@@{Controller.action2()}">Link2</a>

but it doesn't, action2 also gets called via https.

like image 358
stojke Avatar asked Feb 27 '12 01:02

stojke


People also ask

How do I stop HTTP redirect to HTTPS in Chrome?

Go to chrome://net-internals/#hsts . Enter example.com under Delete domain security policies and press the Delete button. Now go to chrome://settings/clearBrowserData , tick the box Cached images and files and press click the button Clear data.

Is it possible to redirect HTTPS to HTTP in modern browsers?

No. Modern browsers don't downgrade to plain HTTP autonomously. If a certificate is invalid, the user will simply see a certificate warning (and eventually an option to add an exception).


1 Answers

Play doesn't have a method that would be opposite to secure(), but you can implement it yourself with custom JavaExtension:

import play.templates.JavaExtensions;
import play.mvc.Router.ActionDefinition;

public class MyExtensions extends play.templates.JavaExtensions {

    public static String unsecure(ActionDefinition action) {
            if (!action.url.contains("http://") && !action.url.contains("https://")) {
                action.absolute();
            }
            action.url = action.url.replace("https:", "http:");
            return action.url;
        } 

Custom extension methods should return String, and the parameter will hold the enhanced object, as the documentation suggests. The code is almost identical to the secure method's code.

With this method you can now use:

href="@{Controller.action2().unsecure()}"
like image 166
Alexander Ponomarenko Avatar answered Sep 28 '22 07:09

Alexander Ponomarenko