Refactor disallowed domains in HTTP service

pull/99/head
Thomas Buckley-Houston 2018-07-09 19:22:51 +08:00
rodzic 90078ff6c0
commit c457210c72
1 zmienionych plików z 7 dodań i 1 usunięć

Wyświetl plik

@ -8,6 +8,7 @@ import (
"crypto/rand"
"io"
"time"
"regexp"
"github.com/ulule/limiter"
"github.com/ulule/limiter/drivers/store/memory"
@ -83,7 +84,7 @@ func handleHTTPServerRequest(w http.ResponseWriter, r *http.Request) {
return
}
w.Header().Set("Cache-Control", "public, max-age=600")
if (strings.Contains(urlForBrowsh, "mail.google.com")) {
if (isDisallowedURL(urlForBrowsh)) {
http.Redirect(w, r, "/", 301)
return
}
@ -111,6 +112,11 @@ func handleHTTPServerRequest(w http.ResponseWriter, r *http.Request) {
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 {
if (strings.Contains(r.Host, "brow.sh")) {
return r.Header.Get("X-Forwarded-Proto") == "http"