github.com/blend/go-sdk@v1.20220411.3/webutil/https_redirect.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package webutil 9 10 import ( 11 "net/http" 12 ) 13 14 var ( 15 _ http.HandlerFunc = HTTPSRedirectFunc 16 ) 17 18 // HTTPSRedirectFunc redirects HTTP to HTTPS as an http.HandlerFunc. 19 func HTTPSRedirectFunc(rw http.ResponseWriter, req *http.Request) { 20 req.URL.Scheme = SchemeHTTPS 21 if req.URL.Host == "" { 22 req.URL.Host = req.Host 23 } 24 http.Redirect(rw, req, req.URL.String(), http.StatusMovedPermanently) 25 }