Skip to content

Instantly share code, notes, and snippets.

@ademar
Last active October 19, 2019 12:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ademar/f4ddb788162dbdd9e104574e2accf07f to your computer and use it in GitHub Desktop.
Save ademar/f4ddb788162dbdd9e104574e2accf07f to your computer and use it in GitHub Desktop.
suave redirect to https webpart
let redirectToSsl : WebPart =
context(fun c ->
if not c.runtime.matchedBinding.scheme.secure
then
let uriBuilder = new UriBuilder(c.request.url)
uriBuilder.Scheme <- Uri.UriSchemeHttps
Redirection.redirect (uriBuilder.Uri.ToString())
else never)
@mydogisbox
Copy link

mydogisbox commented Jun 6, 2017

To make this work on heroku you can use:

    let redirectToSsl : WebPart =
          context(fun c ->
           match c.request.header "x-forwarded-proto" with
            | Choice1Of2 "http" ->
                  let uriBuilder = new UriBuilder(
                                          Scheme = Uri.UriSchemeHttps,
                                          Path = c.request.path,
                                          Host = c.request.host)
                  Redirection.redirect (uriBuilder.Uri.ToString())
            | _ -> fun _ ->async { return None })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment