gin-contrib / size Goto Github PK
View Code? Open in Web Editor NEWLimit size of POST requests for Gin framework
License: MIT License
Limit size of POST requests for Gin framework
License: MIT License
Hi there, thanks for building this!
This middleware works as expected, the only issue I'm experiencing is that the request body is written as part of the middleware func:
ctx.String(http.StatusRequestEntityTooLarge, "request too large")
I'm trying to build an API where every response is JSON- even errors like this. What do you suggest? My response body ends up looking like:
request too large{"error":"HTTP request too large"}
Thanks in advance.
am i able to create a dynamic max limit inside a specified route ?
RequestSizeLimiter
instead of the RateLimiter
你好,我用了这个中间件,在上传大文件的时候会在服务端报错,客户端收不到任何信息
package main
import (
"net/http"
limits "github.com/gin-contrib/size"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
r.Use(limits.RequestSizeLimiter(10))
r.POST("/", handler)
_ = r.Run(":8080")
}
func handler(ctx *gin.Context) {
if file, err := ctx.FormFile("file"); err != nil {
ctx.JSON(http.StatusOK, gin.H{"msg": "fail: " + err.Error()})
} else {
ctx.JSON(http.StatusOK, gin.H{"msg": "ok: " + file.Filename})
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.