Consolidate header field-pair validation into fields::is_field_valid#2506
Merged
Conversation
The is_field_name(name) && is_field_value(value) predicate was repeated across five output paths (set_header, write_headers, write_content_chunked trailer, perform_websocket_handshake, check_and_write_headers). Introduce fields::is_field_valid(name, value) and route all five through it so the CR/LF-injection guard has a single definition. No behavior change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
The
is_field_name(name) && is_field_value(value)predicate — the guard against CR/LF injection / response splitting — had accumulated in five separate output paths:set_headerwrite_headers(server response headers, added in skip invalid fields in write_headers to prevent response splitting #2505)write_content_chunkedtrailerperform_websocket_handshakecheck_and_write_headersThe most recent addition (#2505) was a near-verbatim copy of the chunked-trailer skip block. This consolidates the shared predicate into a single
fields::is_field_valid(name, value)helper and routes all five sites through it.Notes
emplace/continue/return false/ setError::InvalidHeaders); only the duplicated predicate is centralized.fieldsdeclaration block,inlinedefinition in the implementation area next tois_field_value.Testing
make test_splitbuilds clean.set_headertests all pass.