fasthttp icon indicating copy to clipboard operation
fasthttp copied to clipboard

HeaderReceived will permanently overwrite the server's maxRequestBodySize values for that connection

Open GeraltXLi opened this issue 3 years ago • 1 comments

Hi, I have an issue with the HeaderReceived.

https://github.com/valyala/fasthttp/blob/af94725d117b19e761d0c6e9c1b157516c482a71/server.go#L2187-L2197

While maxRequestBodySize is modified by HeaderReceived,in the current connection, it keeps the current value until the next modification. This causes the configuration value of the server itself to no longer be in effect.

https://github.com/valyala/fasthttp/blob/af94725d117b19e761d0c6e9c1b157516c482a71/server.go#L2079-L2103

For example, the server's maxRequestBodySize is set to 10MB, and in HeaderReceived, I set the maxRequestBodySize to 1MB while the path is /upload. So that once an upload request occurs, the size of all other request bodies under this connection(Inside this for loop) cannot be larger than 1MB, which is not expected.

GeraltXLi avatar Aug 23 '22 09:08 GeraltXLi

This is indeed a bug, a pull request would be welcome. I think it's as easy as

if reqConf.MaxRequestBodySize > 0 { 
 	maxRequestBodySize = reqConf.MaxRequestBodySize 
 } else if s.MaxRequestBodySize > 0 {
 	maxRequestBodySize = s.MaxRequestBodySize
} else {
 	maxRequestBodySize = DefaultMaxRequestBodySize
}

erikdubbelboer avatar Aug 23 '22 09:08 erikdubbelboer