Skip to content

refactor parse_options_header#2614

Merged
davidism merged 1 commit intomainfrom
parse_options_header
Mar 6, 2023
Merged

refactor parse_options_header#2614
davidism merged 1 commit intomainfrom
parse_options_header

Conversation

@davidism
Copy link
Copy Markdown
Member

@davidism davidism commented Mar 6, 2023

Based on the implementation @Tronic shared in #1628, I've refactored parse_options_header. The new implementation is 2-3 times faster. The parser now does an initial pass for valid ; key=value parts, then does two simpler checks for continuation and charset markers on each key.

This parses parameters that are valid according to RFC 9110. Some invalid values were previously accepted, such as key, key=, and key = value (spaces around equals). Invalid parts are ignored.

This updates the parsing of quoted strings to handle both \" escaping in HTTP headers and %22 in multipart form data.

We already handled RFC 2231 continuation and charset markers, however I don't think either feature is sent by modern clients. Only UTF-8, ASCII, and ISO-8859-1 charsets are accepted, others are left quoted.

Removed the remnants of the multiple=True flag that was removed earlier.

fixes #1628

follow RFC 9110, discarding invalid parts
2-3 times faster
disallow arbitrary encodings
handle encoded quotes for HTTP headers and multipart form data

Co-authored-by: L. Kärkkäinen <98187+Tronic@users.noreply.github.com>
@davidism davidism added this to the 2.3.0 milestone Mar 6, 2023
@davidism davidism merged commit 267acec into main Mar 6, 2023
@davidism davidism deleted the parse_options_header branch March 6, 2023 18:44
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

parse_options_header quote handling

1 participant