1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-01-01 06:55:25 -05:00

basic auth in http server

This commit is contained in:
Darien Raymond
2017-10-26 21:44:13 +02:00
parent 12a0d6e0b9
commit 1d3c8098e9
5 changed files with 128 additions and 12 deletions

View File

@@ -83,6 +83,15 @@ Start:
}
return trace
}
if len(s.config.Accounts) > 0 {
user, pass, ok := request.BasicAuth()
if !ok || !s.config.HasAccount(user, pass) {
_, err := conn.Write([]byte("HTTP/1.1 401 UNAUTHORIZED\r\n\r\n"))
return err
}
}
log.Trace(newError("request to Method [", request.Method, "] Host [", request.Host, "] with URL [", request.URL, "]"))
conn.SetReadDeadline(time.Time{})