Refactor disallowed domains in HTTP service

This commit is contained in:
Thomas Buckley-Houston 2018-07-09 19:22:51 +08:00
parent 90078ff6c0
commit c457210c72

View file

@ -8,6 +8,7 @@ import (
"crypto/rand" "crypto/rand"
"io" "io"
"time" "time"
"regexp"
"github.com/ulule/limiter" "github.com/ulule/limiter"
"github.com/ulule/limiter/drivers/store/memory" "github.com/ulule/limiter/drivers/store/memory"
@ -83,7 +84,7 @@ func handleHTTPServerRequest(w http.ResponseWriter, r *http.Request) {
return return
} }
w.Header().Set("Cache-Control", "public, max-age=600") w.Header().Set("Cache-Control", "public, max-age=600")
if (strings.Contains(urlForBrowsh, "mail.google.com")) { if (isDisallowedURL(urlForBrowsh)) {
http.Redirect(w, r, "/", 301) http.Redirect(w, r, "/", 301)
return return
} }
@ -111,6 +112,11 @@ func handleHTTPServerRequest(w http.ResponseWriter, r *http.Request) {
waitForResponse(rawTextRequestID, w) waitForResponse(rawTextRequestID, w)
} }
func isDisallowedURL(urlForBrowsh string) bool {
r, _ := regexp.Compile("[mail|accounts].google.com")
return r.MatchString(urlForBrowsh)
}
func isProductionHTTP(r *http.Request) bool { func isProductionHTTP(r *http.Request) bool {
if (strings.Contains(r.Host, "brow.sh")) { if (strings.Contains(r.Host, "brow.sh")) {
return r.Header.Get("X-Forwarded-Proto") == "http" return r.Header.Get("X-Forwarded-Proto") == "http"