MCPcopy
hub / github.com/perkeep/perkeep / makeCamliHandler

Function makeCamliHandler

pkg/serverinit/serverinit.go:163–194  ·  view source on GitHub ↗

where prefix is like "/" or "/s3/" for e.g. "/camli/" or "/s3/camli/*"

(prefix, baseURL string, storage blobserver.Storage, hf blobserver.FindHandlerByTyper)

Source from the content-addressed store, hash-verified

161
162// where prefix is like "/" or "/s3/" for e.g. "/camli/" or "/s3/camli/*"
163func makeCamliHandler(prefix, baseURL string, storage blobserver.Storage, hf blobserver.FindHandlerByTyper) http.Handler {
164 if !strings.HasSuffix(prefix, "/") {
165 panic("expected prefix to end in slash")
166 }
167 baseURL = strings.TrimRight(baseURL, "/")
168
169 canLongPoll := true
170 // TODO(bradfitz): set to false if this is App Engine, or provide some way to disable
171
172 storageConfig := &storageAndConfig{
173 storage,
174 &blobserver.Config{
175 Writable: true,
176 Readable: true,
177 Deletable: false,
178 URLBase: baseURL + prefix[:len(prefix)-1],
179 CanLongPoll: canLongPoll,
180 HandlerFinder: hf,
181 },
182 }
183 return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
184 action, err := parseCamliPath(req.URL.Path[len(prefix)-1:])
185 if err != nil {
186 log.Printf("Invalid request for method %q, path %q",
187 req.Method, req.URL.Path)
188 unsupportedHandler(rw, req)
189 return
190 }
191 handler := auth.RequireAuth(camliHandlerUsingStorage(req, action, storageConfig))
192 handler.ServeHTTP(rw, req)
193 })
194}
195
196func (hl *handlerLoader) FindHandlerByType(htype string) (prefix string, handler interface{}, err error) {
197 nFound := 0

Callers 1

setupHandlerMethod · 0.85

Calls 6

RequireAuthFunction · 0.92
parseCamliPathFunction · 0.85
unsupportedHandlerFunction · 0.85
camliHandlerUsingStorageFunction · 0.85
PrintfMethod · 0.80
ServeHTTPMethod · 0.45

Tested by

no test coverage detected