Add operator<< with CRLF to LF conversion for fields and messages #183
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.
Overview
This PR implements
operator<<
for HTTP message types (fields
,fields_base
,request
,request_base
,response
,response_base
) with automatic CRLF to LF conversion and removal of trailing CRLF.Problem
Previously, only
fields_base
had anoperator<<
that simply output the raw buffer containing CRLF line endings and a trailing CRLF (which marks the end of HTTP headers). This made the output unsuitable for logging, debugging, and display purposes:Solution
This PR modifies the existing
operator<<
forfields_base
and adds newoperator<<
implementations for all derived types. The new implementation:\r\n
sequences are replaced with\n
for standard Unix-style line endings\r\n
that indicates the end of headers is not outputImplementation Details
The core conversion logic is in
fields_base::operator<<
:All derived type implementations simply forward to the base implementation to maintain consistency.
Benefits
std::cout
,std::ofstream
,std::stringstream
).buffer()
still available for raw accessTesting
Added comprehensive test suite in
test/unit/ostream.cpp
covering:Fixes #<issue_number>
Original prompt
Fixes #182
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.