Search code examples
scalasslhttp-redirectscalatraaws-elb

What is the most succinct way to redirect HTTP requests to HTTPS in Scalatra?


I have a service written in Scala with Scalatra and running on AWS ECS listening through an AWS ELB. I have ELB configured as a TLS terminator: HTTPS traffic on port 443 and HTTP traffic on port 80 are routed to the service listening on port 8080 on the ECS task.

I want to redirect all HTTP traffic to HTTPS. I understand that ELB sets the header X-Forwarded-Proto to either http or https according to the original request.

What's the best way to handle a redirect?


Solution

  • If you have a reverse proxy at the front of your Scalatra application, you can redirect http to https at there: https://aws.amazon.com/premiumsupport/knowledge-center/redirect-http-https-elb/

    If you don't have a reverse proxy, you have to do same stuff in your Scalatra application. I think the easiest way is creating a servlet filter which redirects http to https by checking X-Forwarded-Proto header.