How to redirect HTTP to HTTPS

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How to redirect HTTP to HTTPS

Joe Lin
Hi,

I'm running Grizzily 2.3.7. My question is how can I redirect all normal HTTP at 80 traffic to HTTPS at 443?

Thanks.
Joe
Reply | Threaded
Open this post in threaded view
|

Re: How to redirect HTTP to HTTPS

oleksiys
Administrator
Hi Joe,

IMO the easiest way to solve this is to register HttpHandler on port 80 and make it return HTTP response with status 301, and Location header redirecting the client to port 443.

new HttpHandler() {

            @Override
            public void service(Request request, Response response) throws Exception {
                response.setStatus(HttpStatus.MOVED_PERMANENTLY_301);
                response.setHeader(Header.Location, "https://...");
            }
}

Hope that helps.

WBR,
Alexey.

On 24.01.14 21:24, Joe Lin wrote:
Hi,

I'm running Grizzily 2.3.7. My question is how can I redirect all normal HTTP at 80 traffic to HTTPS at 443?

Thanks.
Joe

Reply | Threaded
Open this post in threaded view
|

Re: How to redirect HTTP to HTTPS

Joe Lin
Thanks for the reply

You mention to register a regular HttpHandler on port 80. According to Grizzly API, it seems that we can only register a handler based on request path?

Regards,
Joe


On Fri, Jan 24, 2014 at 10:35 PM, Oleksiy Stashok <[hidden email]> wrote:
Hi Joe,

IMO the easiest way to solve this is to register HttpHandler on port 80 and make it return HTTP response with status 301, and Location header redirecting the client to port 443.

new HttpHandler() {

            @Override
            public void service(Request request, Response response) throws Exception {
                response.setStatus(HttpStatus.MOVED_PERMANENTLY_301);
                response.setHeader(Header.Location, "https://...");
            }
}

Hope that helps.

WBR,
Alexey.


On 24.01.14 21:24, Joe Lin wrote:
Hi,

I'm running Grizzily 2.3.7. My question is how can I redirect all normal HTTP at 80 traffic to HTTPS at 443?

Thanks.
Joe


Reply | Threaded
Open this post in threaded view
|

Re: How to redirect HTTP to HTTPS

oleksiys
Administrator

On 27.01.14 17:24, Joe Lin wrote:
Thanks for the reply

You mention to register a regular HttpHandler on port 80. According to Grizzly API, it seems that we can only register a handler based on request path?
It could be "" (default) path and if you don't register other HttpHandlers on this HttpServer - the default HttpHandler will be invoked for all requests.

WBR,
Alexey.


Regards,
Joe


On Fri, Jan 24, 2014 at 10:35 PM, Oleksiy Stashok <[hidden email]> wrote:
Hi Joe,

IMO the easiest way to solve this is to register HttpHandler on port 80 and make it return HTTP response with status 301, and Location header redirecting the client to port 443.

new HttpHandler() {

            @Override
            public void service(Request request, Response response) throws Exception {
                response.setStatus(HttpStatus.MOVED_PERMANENTLY_301);
                response.setHeader(Header.Location, "https://...");
            }
}

Hope that helps.

WBR,
Alexey.


On 24.01.14 21:24, Joe Lin wrote:
Hi,

I'm running Grizzily 2.3.7. My question is how can I redirect all normal HTTP at 80 traffic to HTTPS at 443?

Thanks.
Joe