Don't route request that we shouldn't!

Oh man, I really hope that's fixed now... What a nightmare.
This commit is contained in:
Brian Buller 2016-06-07 17:50:18 -05:00
parent 59e7ae16d4
commit deda2ebfb9

View File

@ -53,20 +53,29 @@ func main() {
go SignalHandler() go SignalHandler()
fmt.Println(http.ListenAndServe(*bindAddr, &httputil.ReverseProxy{ r := new(revProx)
Director: func(r *http.Request) { fmt.Println(http.ListenAndServe(*bindAddr, r))
if i, ok := routedHostnames[string(r.Host)]; ok { }
r.Header.Set("X-Hostsplitter-Secret", Sites[i].Secret)
r.Header.Set("Host", r.Host) type revProx struct{}
r.URL.Scheme = "http"
r.URL.Host = Sites[i].GetBackend() func (p *revProx) ServeHTTP(w http.ResponseWriter, r *http.Request) {
r.RequestURI = "" if i, ok := routedHostnames[string(r.Host)]; ok {
HTTPLogger(r, http.StatusOK) reverseProxy := new(httputil.ReverseProxy)
} else { reverseProxy.Director = func(r *http.Request) {
HTTPLogger(r, http.StatusBadRequest) r.Header.Set("X-Hostsplitter-Secret", Sites[i].Secret)
} r.Header.Set("Host", r.Host)
}, r.URL.Scheme = "http"
})) r.URL.Host = Sites[i].GetBackend()
r.RequestURI = ""
HTTPLogger(r, http.StatusOK)
}
reverseProxy.ServeHTTP(w, r)
} else {
HTTPLogger(r, http.StatusBadRequest)
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte("Bad Request"))
}
} }
const apacheFormatPattern = "%s - - [%s] \"%s %s %s\" %d %d \"%s\" \"%s\" %.4f\n" const apacheFormatPattern = "%s - - [%s] \"%s %s %s\" %d %d \"%s\" \"%s\" %.4f\n"