MCPcopy Create free account
hub / github.com/devfeel/dotweb / File

Method File

context.go:422–445  ·  view source on GitHub ↗

File sends a response with the content of the file if file not exists, response 404 for issue #39

(file string)

Source from the content-addressed store, hash-verified

420// if file not exists, response 404
421// for issue #39
422func (ctx *HttpContext) File(file string) (err error) {
423 f, err := os.Open(file)
424 if err != nil {
425 HTTPNotFound(ctx)
426 return nil
427 }
428 defer f.Close()
429
430 fi, _ := f.Stat()
431 if fi.IsDir() {
432 file = filepath.Join(file, ctx.HttpServer().IndexPage())
433 f, err = os.Open(file)
434 if err != nil {
435 HTTPNotFound(ctx)
436 return nil
437 }
438 defer f.Close()
439 if fi, err = f.Stat(); err != nil {
440 return err
441 }
442 }
443 http.ServeContent(ctx.Response().Writer(), ctx.Request().Request, fi.Name(), fi.ModTime(), f)
444 return nil
445}
446
447// Attachment sends a response as attachment, prompting client to save the file.
448// for issue #39

Callers 1

contentDispositionMethod · 0.95

Calls 9

HttpServerMethod · 0.95
ResponseMethod · 0.95
RequestMethod · 0.95
HTTPNotFoundFunction · 0.85
OpenMethod · 0.80
IndexPageMethod · 0.80
WriterMethod · 0.80
NameMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected