feat: add option to restore request body after reading#307
feat: add option to restore request body after reading#307inhere merged 1 commit intogookit:masterfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds a new global configuration option to control whether HTTP request bodies are restored after being read during validation. This enhancement allows the request body to remain available for subsequent middleware or handlers that may need to access the original request data.
Key changes:
- Added
RestoreRequestBodyfield toGlobalOptionstruct with default valuefalse - Modified
FromRequestfunction to conditionally restore the request body after reading for JSON content - Added comprehensive test coverage to verify both enabled and disabled restoration behavior
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| validate.go | Added RestoreRequestBody option to GlobalOption struct and implemented body restoration logic in FromRequest function |
| validate_test.go | Added test function to verify request body restoration functionality works correctly in both enabled and disabled states |
|
Hi, @inhere Is there any plan to release a new version soon? Our project depends on this package, and we’d like to include this change in our upcoming release. Really appreciate your work! |
|
@almas-x OK, New version will be released this week. |
|
Is there a reason to always restore it and don't have a setting for it ? |
The HTTP request body in Go is typically read-only once by default. The configuration option is designed to make users aware of situations where they explicitly restore the body, as automatically restoring it by default could unintentionally disrupt the original behavior. |
This pull request introduces a new global option to control whether the HTTP request body should be automatically restored after being read. This enhancement increases the flexibility of the validation process by allowing users to enable or disable request body restoration, ensuring that the body remains available for further processing by subsequent middleware or handlers.
Key Changes:
This update addresses goravel/goravel Issue #334.