Fix HTTP::Response and HTTP::Request as_string/parse commutativity issue #62959 #212
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.
Problem
Calling
as_string()
on an HTTP::Response or HTTP::Request object and then restoring it viaparse()
would modify the content by adding an unwanted trailing newline. This made serialization/deserialization non-commutative, causing issues when usingas_string()
as a means to serialize HTTP messages.Reproduction:
The same issue affected HTTP::Request objects.
Root Cause
Both
HTTP::Response::as_string()
andHTTP::Request::as_string()
were passing@_
to the parent class method:This caused
HTTP::Message::as_string()
to incorrectly detect that no explicit$eol
parameter was provided (checking@_ == 1
), triggering logic that appends a trailing newline to content not already ending with one.Solution
Changed both methods to pass the
$eol
parameter explicitly instead of forwarding@_
:This ensures
HTTP::Message::as_string()
correctly receives the$eol
parameter and doesn't add spurious newlines.Testing
Impact
This is a minimal, surgical fix that ensures
as_string()
andparse()
are now properly commutative, allowing HTTP::Response and HTTP::Request objects to be reliably serialized and deserialized without content corruption.Fixes #62959
Original prompt
Fixes #48
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.