MCPcopy Create free account
hub / github.com/syncthing/syncthing / ServeHTTP

Method ServeHTTP

lib/api/api_auth.go:145–177  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

143}
144
145func (m *basicAuthAndSessionMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request) {
146 if hasValidAPIKeyHeader(r, m.guiCfg) {
147 m.next.ServeHTTP(w, r)
148 return
149 }
150
151 if m.tokenCookieManager.hasValidSession(r) {
152 m.next.ServeHTTP(w, r)
153 return
154 }
155
156 // Fall back to Basic auth if provided
157 if username, ok := attemptBasicAuth(r, m.guiCfg, m.ldapCfg, m.evLogger); ok {
158 m.tokenCookieManager.createSession(username, false, w, r)
159 m.next.ServeHTTP(w, r)
160 return
161 }
162
163 // Exception for static assets and REST calls that don't require authentication.
164 if isNoAuthPath(r.URL.Path, m.guiCfg.MetricsWithoutAuth) {
165 m.next.ServeHTTP(w, r)
166 return
167 }
168
169 // Some browsers don't send the Authorization request header unless prompted by a 401 response.
170 // This enables https://user:pass@localhost style URLs to keep working.
171 if m.guiCfg.SendBasicAuthPrompt {
172 unauthorized(w, m.tokenCookieManager.shortID)
173 return
174 }
175
176 forbidden(w)
177}
178
179func (m *basicAuthAndSessionMiddleware) passwordAuthHandler(w http.ResponseWriter, r *http.Request) {
180 var req struct {

Callers

nothing calls this directly

Calls 7

hasValidAPIKeyHeaderFunction · 0.85
attemptBasicAuthFunction · 0.85
isNoAuthPathFunction · 0.85
unauthorizedFunction · 0.85
forbiddenFunction · 0.85
hasValidSessionMethod · 0.80
createSessionMethod · 0.80

Tested by

no test coverage detected