Skip to content
This repository was archived by the owner on Jan 16, 2021. It is now read-only.

enforce HTTPS #322

Merged
merged 1 commit into from
Sep 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions gddo-server/https.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package main

import "net/http"

type httpsEnforcerHandler struct {
h http.Handler
}

func (h httpsEnforcerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.Host == "godoc.org" {
w.Header().Add("Strict-Transport-Security", "max-age=631138519; includeSubdomains; preload")
if r.Header.Get("X-Scheme") != "https" {
r.URL.Scheme = "https"
http.Redirect(w, r, r.URL.String(), http.StatusFound)
return
}
}
h.h.ServeHTTP(w, r)
}
6 changes: 5 additions & 1 deletion gddo-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,11 @@ func main() {

cacheBusters.Handler = mux

if err := http.ListenAndServe(*httpAddr, hostMux{{"api.", apiMux}, {"", mux}}); err != nil {
allMux := httpsEnforcerHandler{
hostMux{{"api.", apiMux}, {"", mux}},
}

if err := http.ListenAndServe(*httpAddr, allMux); err != nil {
log.Fatal(err)
}
}