fix allowhost

Signed-off-by: yangshukui <yangshukui@huawei.com>
pull/85/head
yangshukui 8 years ago
parent 0979b01a44
commit 6915f6c5c1

@ -22,6 +22,7 @@ import (
"flag" "flag"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net"
"net/http" "net/http"
"os" "os"
"os/exec" "os/exec"
@ -257,7 +258,8 @@ func listenHTTP(path, allowedHost string) {
restrictedFileServer := func(path, allowedHost string) http.Handler { restrictedFileServer := func(path, allowedHost string) http.Handler {
fc := func(w http.ResponseWriter, r *http.Request) { fc := func(w http.ResponseWriter, r *http.Request) {
if r.Host == allowedHost { host, _, err := net.SplitHostPort(r.RemoteAddr)
if err == nil && strings.EqualFold(host, allowedHost) {
http.FileServer(http.Dir(path)).ServeHTTP(w, r) http.FileServer(http.Dir(path)).ServeHTTP(w, r)
return return
} }

Loading…
Cancel
Save