MCPcopy
hub / github.com/wavetermdev/waveterm / handleLocalStreamFile

Function handleLocalStreamFile

pkg/web/web.go:219–245  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request, path string, no404 bool)

Source from the content-addressed store, hash-verified

217}
218
219func handleLocalStreamFile(w http.ResponseWriter, r *http.Request, path string, no404 bool) {
220 http.NewResponseController(w).SetWriteDeadline(time.Time{})
221 if no404 {
222 log.Printf("streaming file w/no404: %q\n", path)
223 // use the custom response writer
224 rw := &notFoundBlockingResponseWriter{w: w, headers: http.Header{}}
225
226 // Serve the file using http.ServeFile
227 path, err := wavebase.ExpandHomeDir(path)
228 if err == nil {
229 http.ServeFile(rw, r, filepath.Clean(path))
230 // if the file was not found, serve the transparent GIF
231 log.Printf("got streamfile status: %d\n", rw.status)
232 if rw.status == http.StatusNotFound {
233 serveTransparentGIF(w)
234 }
235 } else {
236 serveTransparentGIF(w)
237 }
238 } else {
239 path, err := wavebase.ExpandHomeDir(path)
240 if err != nil {
241 http.Error(w, err.Error(), http.StatusBadRequest)
242 }
243 http.ServeFile(w, r, path)
244 }
245}
246
247func handleStreamFileFromReader(w http.ResponseWriter, r *http.Request, path string, no404 bool) error {
248 startTime := time.Now()

Callers 1

handleStreamLocalFileFunction · 0.85

Calls 5

ExpandHomeDirFunction · 0.92
serveTransparentGIFFunction · 0.85
SetWriteDeadlineMethod · 0.80
CleanMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected