|
|
@ -226,14 +226,10 @@ func (s *Service) Close() {
|
|
|
|
// ServeHTTP allows Service to serve HTTP requests.
|
|
|
|
// ServeHTTP allows Service to serve HTTP requests.
|
|
|
|
func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
|
s.addBuildVersion(w)
|
|
|
|
s.addBuildVersion(w)
|
|
|
|
|
|
|
|
if !s.checkCredentials(r) {
|
|
|
|
if s.credentialStore != nil {
|
|
|
|
|
|
|
|
username, password, ok := r.BasicAuth()
|
|
|
|
|
|
|
|
if !ok || !s.credentialStore.Check(username, password) {
|
|
|
|
|
|
|
|
w.WriteHeader(http.StatusUnauthorized)
|
|
|
|
w.WriteHeader(http.StatusUnauthorized)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch {
|
|
|
|
switch {
|
|
|
|
case strings.HasPrefix(r.URL.Path, "/db/execute"):
|
|
|
|
case strings.HasPrefix(r.URL.Path, "/db/execute"):
|
|
|
@ -781,6 +777,17 @@ func (s *Service) addBuildVersion(w http.ResponseWriter) {
|
|
|
|
w.Header().Add(VersionHTTPHeader, version)
|
|
|
|
w.Header().Add(VersionHTTPHeader, version)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// checkCredentials returns if any authentication requirements
|
|
|
|
|
|
|
|
// have been successfully met.
|
|
|
|
|
|
|
|
func (s *Service) checkCredentials(r *http.Request) bool {
|
|
|
|
|
|
|
|
if s.credentialStore == nil {
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
username, password, ok := r.BasicAuth()
|
|
|
|
|
|
|
|
return ok && s.credentialStore.Check(username, password)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func requestQueries(r *http.Request) ([]string, error) {
|
|
|
|
func requestQueries(r *http.Request) ([]string, error) {
|
|
|
|
if r.Method == "GET" {
|
|
|
|
if r.Method == "GET" {
|
|
|
|
query, err := stmtParam(r)
|
|
|
|
query, err := stmtParam(r)
|
|
|
|