The Go standard library includes a method `http.MaxBytesReader` that allows limiting the request body. For example, users can create a middleware like:
```go
func MiddlewareMaxBodySize(c *gin.Context) {
// Limit request body to 100 bytes
c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, 100)
c.Next()
}
```
When the body exceeds the limit, reading from the request body returns an error of type `http.MaxBytesError`.
This PR makes sure that when the error is of kind `http.MaxBytesError`, Gin returns the correct status code 413 (Request Entity Too Large) instead of a generic 400 (Bad Request).
* Sleep for one millisecond in the handler because the `Latency` will return `0s` sometimes and the test will fail
* The `TCPListener.File` is not supported by windows, it is unimplemented now
* Remove the `LF` in the `testdata/template/raw.tmpl`, because if set the git config `core.autocrlf=true`, will append `CR` to the raw.tmpl automatically, then test is failed on Windows
* fix Context.Next() - recheck len of handlers every iteration
* add tests when Context.reset() can be called inside of handler
TestEngineHandleContext
TestContextResetInHandler
TestRouterStaticFSFileNotFound
* Context.Next() - format to while style
Digging into the test code base I've found out that some of the tests for `LoadHTML*` methods are not reliable and efficient. They use timeouts to be sure that goroutine with the server has started. And even more, in old implementation, the server started only once – all the new instances silently failed due to the occupied network port.
Here is a short overview of the proposed changes:
- it's not necessary to rely on timeouts, the server starts listening synchronously and returns control when it is ready
- once the server is run, it's stopped after a test passes
- dry out http server setup
- magic with empty closure return is eliminated
- preserve router.RunTLS coverage with integration tests
* Revert "Merge pull request #753 from gin-gonic/bug"
This reverts commit 556287ff0856a5ad1f9a1b493c188cabeceba929, reversing
changes made to 32cab500ecc71d2975f5699c8a65c6debb29cfbe.
* Revert "Merge pull request #744 from aviddiviner/logger-fix"
This reverts commit c3bfd69303d0fdaf2d43a7ff07cc8ee45ec7bb3f, reversing
changes made to 9177f01c2843b91820780197f521ba48554b9df3.
* add custom Delims support
* add some test for Delims
* remove the empty line for import native package
* remove unuseful comments