MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / RegisterFilePrefixHandler

Method RegisterFilePrefixHandler

pkg/waveapp/waveapp.go:451–466  ·  view source on GitHub ↗
(prefix string, optionProvider func(path string) (*FileHandlerOption, error))

Source from the content-addressed store, hash-verified

449}
450
451func (c *Client) RegisterFilePrefixHandler(prefix string, optionProvider func(path string) (*FileHandlerOption, error)) {
452 c.UrlHandlerMux.PathPrefix(prefix).HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
453 option, err := optionProvider(r.URL.Path)
454 if err != nil {
455 http.Error(w, err.Error(), http.StatusInternalServerError)
456 return
457 }
458 if option == nil {
459 http.Error(w, "no content available", http.StatusNotFound)
460 return
461 }
462 if err := ServeFileOption(w, r, *option); err != nil {
463 http.Error(w, fmt.Sprintf("Failed to serve content: %v", err), http.StatusInternalServerError)
464 }
465 })
466}
467
468func (c *Client) RegisterFileHandler(path string, option FileHandlerOption) {
469 c.UrlHandlerMux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Implementers 1

WshRouterpkg/wshutil/wshrouter.go

Calls 2

ServeFileOptionFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected