Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Middleware to redirect http traffic to https #2966

Closed
wants to merge 5 commits into from

Conversation

@tovbinm
Copy link
Contributor

tovbinm commented Nov 6, 2019

Inspects X-Forwarded-Proto header and if it is set to http, redirects to Host with same URL with https schema; otherwise does nothing. This middleware is useful when a service is deployed behind a load balancer which does not support such redirect feature, e.g. Heroku.

tovbinm added 4 commits Nov 6, 2019
Kleisli { req =>
(req.headers.get(`X-Forwarded-Proto`), req.headers.get(Host)) match {

case (Some(proto), Some(host)) if Scheme.fromString(proto.value).contains(Scheme.http) =>

This comment was marked as resolved.

Copy link
@kevinmeredith

kevinmeredith Nov 10, 2019

Contributor

I admit to not having heard of X-Forwarded-Proto before. However, could that header's value ever be https, such that if Scheme.fromString(proto.value).contains(Scheme.http) would, as I understand, wrongly evaluate to true, since https contains http?

This comment was marked as resolved.

Copy link
@kevinmeredith

kevinmeredith Nov 10, 2019

Contributor

Nevermind, I see that Scheme.fromString(proto.value) will return a Either[ParseFailure, A].

Copy link
Member

rossabaker left a comment

👍 I'm going to backport it for 0.20 users.

@tovbinm

This comment has been minimized.

Copy link
Contributor Author

tovbinm commented Nov 26, 2019

Thanks. It seems that I need to fix the code style before it can be merged.

@tovbinm

This comment has been minimized.

Copy link
Contributor Author

tovbinm commented Nov 26, 2019

Done.

@rossabaker

This comment has been minimized.

Copy link
Member

rossabaker commented Nov 26, 2019

Backported into #2992, to be released in 0.20.15.

@rossabaker rossabaker closed this Nov 26, 2019
@tovbinm tovbinm mentioned this pull request Nov 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.