Taru Karttunen avatar Taru Karttunen committed e42fb2f

refactor parseAuthHeader

Comments (0)

Files changed (1)

 	return s
 }
 
-// Authenticates
-func (s *Server)Auth(w http.ResponseWriter, r *http.Request) bool {
-	var additionalResp string
+func parseAuthHeader(r *http.Request) map[string]string {
 	// Check whether we are digest authenticating
 	ad := strings.Split(r.Header["Authorization"]," ", 2)
-	if len(ad)!=2 || ad[0]!="Digest" { goto NeedAuth }
+	if len(ad)!=2 || ad[0]!="Digest" { return nil }
 	// Split values
 	kv := map[string]string{}
 	for _,kvr := range strings.Split(ad[1],",",-1) {
 		pair := strings.Split(kvr, "=", 2)
-		if len(pair)!=2 { goto NeedAuth }
+		if len(pair)!=2 { return nil }
 		kv[strings.Trim(pair[0], " \"")] = strings.Trim(pair[1], " \"")
 	}
+	return kv
+}
+
+// Authenticates
+func (s *Server)Auth(w http.ResponseWriter, r *http.Request) bool {
+	var additionalResp string
+	kv := parseAuthHeader(r)
+	if kv==nil { goto NeedAuth }
 	// Check opaque
 	if s.opaque!=kv["opaque"] { goto NeedAuth }
 	// Get nreq
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.