geektutu/7days-golang · warning
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>", meaning the request path is malformed for the peer protocol. It fires on requests missing the key segment or containing extra slashes.
Source
Thrown at gee-cache/day5-multi-nodes/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
- Request the full /<basePath>/<group>/<key> URL.
- Use a dedicated health endpoint instead of the geecache pool for probes.
- Audit proxy/ingress rewrite rules.
- Encode '/' inside keys so SplitN produces exactly two parts.
Example fix
// before GET /_geecache/users // after GET /_geecache/users/42
Defensive patterns
Strategy: validation
Validate before calling
// day5: enforce URL shape client-side
func buildCacheURL(base, group, key string) (string, error) {
if group == "" || key == "" || strings.Contains(key, "/") {
return "", fmt.Errorf("invalid cache path: group=%q key=%q", group, key)
}
return base + "/" + group + "/" + url.PathEscape(key), nil
} Prevention
- Always send /basePath/group/key — never bare group paths.
- Route health probes to a non-cache endpoint.
- Escape keys; reject empty group/key before building the URL.
- Add a smoke test hitting one full cache path in deployment pipelines.
When it happens
Trigger: Requests like GET /_geecache/ or GET /_geecache/group without a key segment.
Common situations: Health probes against the cache route; clients forgetting the key; proxies stripping part of the URL; ad-hoc curl testing with incomplete paths.
Related errors
AI-assisted analysis of geektutu/7days-golang@cf36443821 (2026-09-03).
Data as JSON: /api/errors/655590e0667f01c3.
Report an issue: GitHub.