mirror of
https://github.com/kataras/iris.git
synced 2026-03-02 06:25:57 +00:00
add Context.SendFileWithRate, ServeFileWithRate and ServeContentWithRate
as requested at: https://github.com/kataras/iris/issues/1493 Former-commit-id: 7783fde04b4247056e6309e7ec1df27f027dc655
This commit is contained in:
@@ -237,7 +237,7 @@ You can serve [quicktemplate](https://github.com/valyala/quicktemplate) and [her
|
||||
- [Basic](file-server/basic/main.go)
|
||||
- [Embedding Files Into App Executable File](file-server/embedding-files-into-app/main.go)
|
||||
- [Embedding Gziped Files Into App Executable File](file-server/embedding-gziped-files-into-app/main.go)
|
||||
- [Send/Force-Download Files](file-server/send-files/main.go)
|
||||
- [Send/Force-Download Files](file-server/send-files/main.go) **UPDATED**
|
||||
- Single Page Applications
|
||||
* [single Page Application](file-server/single-page-application/basic/main.go)
|
||||
* [embedded Single Page Application](file-server/single-page-application/embedded-single-page-application/main.go)
|
||||
@@ -246,7 +246,7 @@ You can serve [quicktemplate](https://github.com/valyala/quicktemplate) and [her
|
||||
### How to Read from `context.Request() *http.Request`
|
||||
|
||||
- [Read JSON](http_request/read-json/main.go)
|
||||
* [Struct Validation](http_request/read-json-struct-validation/main.go) **UPDaTE**
|
||||
* [Struct Validation](http_request/read-json-struct-validation/main.go) **UPDATED**
|
||||
- [Read XML](http_request/read-xml/main.go)
|
||||
- [Read MsgPack](http_request/read-msgpack/main.go) **NEW**
|
||||
- [Read YAML](http_request/read-yaml/main.go)
|
||||
|
||||
Binary file not shown.
@@ -6,11 +6,26 @@ import (
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
app.Logger().SetLevel("debug")
|
||||
|
||||
app.Get("/", func(ctx iris.Context) {
|
||||
file := "./files/first.zip"
|
||||
ctx.SendFile(file, "c.zip")
|
||||
})
|
||||
app.Get("/", download)
|
||||
app.Get("/download", downloadWithRateLimit)
|
||||
|
||||
app.Listen(":8080")
|
||||
}
|
||||
|
||||
func download(ctx iris.Context) {
|
||||
src := "./files/first.zip"
|
||||
ctx.SendFile(src, "client.zip")
|
||||
}
|
||||
|
||||
func downloadWithRateLimit(ctx iris.Context) {
|
||||
// REPLACE THAT WITH A BIG LOCAL FILE OF YOUR OWN.
|
||||
src := "./files/first.zip"
|
||||
dest := "" /* optionally, keep it empty to resolve the filename based on the "src" */
|
||||
|
||||
// Limit download speed to ~50Kb/s with a burst of 100KB.
|
||||
limit := 50.0 * iris.KB
|
||||
burst := 100 * iris.KB
|
||||
ctx.SendFileWithRate(src, dest, limit, burst)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@ import "github.com/kataras/iris/v12"
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
// app.Use(iris.Gzip)
|
||||
// func(ctx iris.Context) { ctx.Gzip(true/false)}
|
||||
// OR:
|
||||
app.Get("/", func(ctx iris.Context) {
|
||||
ctx.WriteGzip([]byte("Hello World!"))
|
||||
ctx.Header("X-Custom",
|
||||
|
||||
Reference in New Issue
Block a user