MCPcopy Create free account
hub / github.com/kataras/iris / ServeFileWithRate

Method ServeFileWithRate

context/context.go:5478–5507  ·  view source on GitHub ↗

ServeFileWithRate same as `ServeFile` but it can throttle the speed of reading and though writing the file to the client.

(filename string, limit float64, burst int)

Source from the content-addressed store, hash-verified

5476// ServeFileWithRate same as `ServeFile` but it can throttle the speed of reading
5477// and though writing the file to the client.
5478func (ctx *Context) ServeFileWithRate(filename string, limit float64, burst int) error {
5479 f, err := os.Open(filename)
5480 if err != nil {
5481 ctx.StatusCode(http.StatusNotFound)
5482 return err
5483 }
5484 defer f.Close()
5485
5486 st, err := f.Stat()
5487 if err != nil {
5488 code := http.StatusInternalServerError
5489 if os.IsNotExist(err) {
5490 code = http.StatusNotFound
5491 }
5492
5493 if os.IsPermission(err) {
5494 code = http.StatusForbidden
5495 }
5496
5497 ctx.StatusCode(code)
5498 return err
5499 }
5500
5501 if st.IsDir() {
5502 return ctx.ServeFile(path.Join(filename, "index.html"))
5503 }
5504
5505 ctx.ServeContentWithRate(f, st.Name(), st.ModTime(), limit, burst)
5506 return nil
5507}
5508
5509// SendFile sends a file as an attachment, that is downloaded and saved locally from client.
5510// Note that compression can be registered

Callers 2

ServeFileMethod · 0.95
SendFileWithRateMethod · 0.95

Calls 9

StatusCodeMethod · 0.95
ServeFileMethod · 0.95
ServeContentWithRateMethod · 0.95
CloseMethod · 0.65
NameMethod · 0.65
OpenMethod · 0.45
StatMethod · 0.45
IsDirMethod · 0.45
ModTimeMethod · 0.45

Tested by

no test coverage detected