Commit graph

17 commits

Author SHA1 Message Date
google-labs-jules[bot]
82099e26ee feat: Add request body size limit and enhance error logging
This commit introduces two main improvements to the Touka web framework:

1.  **Configurable Request Body Size Limit:**
    - Added `MaxRequestBodySize int64` to `touka.Engine` (default 10MB).
    - You can customize this via `engine.SetMaxRequestBodySize()`.
    - The context methods `GetReqBodyFull()`, `GetReqBodyBuffer()`, and `ShouldBindJSON()` now adhere to this limit. They check `Content-Length` upfront and use `http.MaxBytesReader` to prevent reading excessively large request bodies into memory, enhancing protection against potential DoS attacks or high memory usage.
    - Added comprehensive unit tests in `context_test.go` for this feature, covering scenarios where the limit is active, disabled, and exceeded.

2.  **Enhanced Error Logging in Default Handler:**
    - The `defaultErrorHandle` in `engine.go` now logs not only the primary error passed to it but also any additional errors collected in `Context.Errors` (via `c.AddError()`).
    - This provides more comprehensive diagnostic information in the logs without altering the JSON error response structure sent to the client, ensuring backward compatibility.

These changes aim to improve the framework's robustness, memory safety, and debuggability.
2025-06-20 06:35:01 +00:00
wjqserver
53544644af use new resolveRoutePath replace path.Join && add UseIf 2025-06-17 14:20:14 +08:00
wjqserver
bfc6b439e4 [context] add SetHeaders 2025-06-14 17:58:08 +08:00
wjqserver
896182417f fix header writer after status issue 2025-06-11 11:24:54 +08:00
wjqserver
bb822599b9 update methods 2025-06-11 11:11:54 +08:00
wjqserver
ce5efae287 update 2025-06-10 21:37:53 +08:00
wjqserver
e6b54eedbf remove tgzip 2025-06-10 00:04:15 +08:00
wjqserver
1d5ffac153 [context] optimize context reset and reuse 2025-06-06 22:40:40 +08:00
wjqserver
61e67bc2a0 [context] fix writer reset 2025-06-06 21:29:09 +08:00
wjqserver
757cd962ab [context] Add Cookie Method, port from gin 2025-06-05 18:35:28 +08:00
wjqserver
b8a1c5523a ctx add logreco method 2025-06-04 21:30:56 +08:00
wjqserver
899d3ff48b add logreco 2025-06-04 20:44:23 +08:00
wjqserver
385b6239c8 add GetHTTPC 2025-06-04 18:40:00 +08:00
wjqserver
6eac3b2046 add GetProtocol 2025-06-02 02:10:25 +08:00
wjqserver
8ae88a77f0 add Raw & GetReqBodyFull 2025-05-30 16:51:38 +08:00
wjqserver
5a10829041 add ErrorUseHandle 2025-05-28 21:34:08 +08:00
wjqserver
484f2f016b init(v0.0.1) 2025-05-28 18:25:28 +08:00