mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-10-23 22:59:10 -04:00
Redirect http-requests to https (#29)
This commit is contained in:
1 parent
e3bcc0d5aa
commit
976c13cf62
3 files changed
+26
No files matched your search
@@ -0,0 +1,4 @@
|
||||
Change: Insecure http-requests are now redirected to https
|
||||
|
||||
https://github.com/owncloud/ocis-proxy/pull/29
|
||||
|
||||
@@ -236,6 +236,9 @@ func Server(cfg *config.Config) *cli.Command {
|
||||
|
||||
func loadMiddlewares(cfg *config.Config, l log.Logger) []func(handler http.Handler) http.Handler {
|
||||
var configuredMiddlewares = make([]func(handler http.Handler) http.Handler, 0)
|
||||
|
||||
configuredMiddlewares = append(configuredMiddlewares, middleware.RedirectToHTTPS)
|
||||
|
||||
if cfg.OIDC != nil {
|
||||
l.Info().Msg("Loading OIDC-Middleware")
|
||||
l.Debug().Interface("oidc_config", cfg.OIDC).Msg("OIDC-Config")
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// RedirectToHTTPS redirects insecure requests to https
|
||||
func RedirectToHTTPS(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
||||
proto := req.Header.Get("x-forwarded-proto")
|
||||
if proto == "http" || proto == "HTTP" {
|
||||
http.Redirect(res, req, fmt.Sprintf("https://%s%s", req.Host, req.URL), http.StatusPermanentRedirect)
|
||||
return
|
||||
}
|
||||
|
||||
next.ServeHTTP(res, req)
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user