MCPcopy
hub / github.com/perkeep/perkeep / ServeHTTP

Method ServeHTTP

pkg/search/handler.go:252–276  ·  view source on GitHub ↗
(rw http.ResponseWriter, req *http.Request)

Source from the content-addressed store, hash-verified

250}
251
252func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
253 suffix := httputil.PathSuffix(req)
254
255 handlers := getHandler
256 switch {
257 case httputil.IsGet(req):
258 // use default from above
259 case req.Method == "POST":
260 handlers = postHandler
261 default:
262 handlers = nil
263 }
264 fn := handlers[strings.TrimPrefix(suffix, "camli/search/")]
265 if fn != nil {
266 fn(h, rw, req)
267 return
268 }
269
270 // TODO: discovery for the endpoints & better error message with link to discovery info
271 ret := camtypes.SearchErrorResponse{
272 Error: "Unsupported search path or method",
273 ErrorType: "input",
274 }
275 httputil.ReturnJSON(rw, &ret)
276}
277
278// sanitizeNumResults takes n as a requested number of search results and sanitizes it.
279func sanitizeNumResults(n int) int {

Callers 1

testMethod · 0.95

Calls 3

PathSuffixFunction · 0.92
IsGetFunction · 0.92
ReturnJSONFunction · 0.92

Tested by 1

testMethod · 0.76