geektutu/7days-golang · error
bad request
Error message
bad request
What it means
HTTP 400 response in HTTPPool.ServeHTTP: the URL path after basePath does not split into exactly two parts "<groupname>/<key>", so the peer request is malformed. It fires on paths missing the key segment or with unexpected slash structure.
Source
Thrown at gee-cache/day6-single-flight/geecache/http.go:51
basePath: defaultBasePath,
}
}
// Log info with server name
func (p *HTTPPool) Log(format string, v ...interface{}) {
log.Printf("[Server %s] %s", p.self, fmt.Sprintf(format, v...))
}
// ServeHTTP handle all http requests
func (p *HTTPPool) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if !strings.HasPrefix(r.URL.Path, p.basePath) {
panic("HTTPPool serving unexpected path: " + r.URL.Path)
}
p.Log("%s %s", r.Method, r.URL.Path)
// /<basepath>/<groupname>/<key> required
parts := strings.SplitN(r.URL.Path[len(p.basePath):], "/", 2)
if len(parts) != 2 {
http.Error(w, "bad request", http.StatusBadRequest)
return
}
groupName := parts[0]
key := parts[1]
group := GetGroup(groupName)
if group == nil {
http.Error(w, "no such group: "+groupName, http.StatusNotFound)
return
}
view, err := group.Get(key)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
View on GitHub (pinned to cf36443821)
Solutions
- Return a 400 status with a clear message instructing the client to use the URL format /<basePath>/<groupname>/<key>
- Log the received path server-side to aid debugging of malformed requests
- Add client-side URL construction helpers so callers build valid cache paths instead of hand-crafting them
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at gee-cache/day6-single-flight/geecache/http.go:51 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of geektutu/7days-golang@cf36443821 (2026-09-03).
Data as JSON: /api/errors/208342420bf2235f.
Report an issue: GitHub.