Skip to content

Commit f9659ec

Browse files
committed
Simplify www_authenticate.go to match PR docker#129 more closely
- Remove enhanced FormatWWWAuthenticate and needsQuoting functions not in original PR docker#129 - Remove unused strconv import after function removal - Reduce from 253 lines to 210 lines (target: 208, very close) - Keep only the core WWW-Authenticate parsing functions from original PR This brings the implementation much closer to the original PR docker#129 while maintaining all the essential OAuth header parsing functionality.
1 parent 6354962 commit f9659ec

File tree

1 file changed

+0
-43
lines changed

1 file changed

+0
-43
lines changed

pkg/oauth/www_authenticate.go

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package oauth
33
import (
44
"fmt"
55
"regexp"
6-
"strconv"
76
"strings"
87
)
98

@@ -209,45 +208,3 @@ func FindRealm(challenges []WWWAuthenticateChallenge) string {
209208
}
210209
return ""
211210
}
212-
213-
// FormatWWWAuthenticate formats a WWW-Authenticate challenge back to header string format
214-
//
215-
// Used for testing and debugging purposes
216-
func FormatWWWAuthenticate(challenge WWWAuthenticateChallenge) string {
217-
if len(challenge.Parameters) == 0 {
218-
return challenge.Scheme
219-
}
220-
221-
var parts []string
222-
for key, value := range challenge.Parameters {
223-
// Quote values that contain spaces or special characters
224-
if needsQuoting(value) {
225-
parts = append(parts, fmt.Sprintf(`%s="%s"`, key, value))
226-
} else {
227-
parts = append(parts, fmt.Sprintf(`%s=%s`, key, value))
228-
}
229-
}
230-
231-
return fmt.Sprintf("%s %s", challenge.Scheme, strings.Join(parts, ", "))
232-
}
233-
234-
// needsQuoting determines if a parameter value needs to be quoted
235-
func needsQuoting(value string) bool {
236-
if value == "" {
237-
return true
238-
}
239-
240-
// Quote if contains spaces, commas, quotes, or special characters
241-
for _, r := range value {
242-
if r == ' ' || r == ',' || r == '"' || r == '=' {
243-
return true
244-
}
245-
}
246-
247-
// Quote if looks like a number but we want to keep it as string
248-
if _, err := strconv.Atoi(value); err == nil {
249-
return false // Numbers don't need quoting
250-
}
251-
252-
return false
253-
}

0 commit comments

Comments
 (0)