fix: when EXPECTING_BODY nil will hand request #332
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
summy
This pull request updates the behavior of the HTTP library to handle cases where the request body is
nil
for methods that expect a body (e.g., POST, PUT, PATCH). It introduces an error message for such cases and adjusts the corresponding tests to align with the new behavior.Related issues
closed #331
Changes to HTTP request handling:
lib/resty/http.lua
: Updated the_M.send_request
function to return an error when the request body isnil
for methods that expect a body. The error message advises using an empty string (""
) if an empty body is intended.Changes to tests:
t/06-simpleinterface.t
: Modified test 7 to explicitly set the request body to an empty string (""
) for POST, PUT, and PATCH requests, ensuring theContent-Length
header is correctly set.t/06-simpleinterface.t
: Added a new test (test 9) to verify that an error is returned when the request body isnil
for POST, PUT, and PATCH requests. This test confirms the new behavior and validates the error messages.