Skip to content

refactor parse and dump header functions#2618

Merged
davidism merged 1 commit intomainfrom
http-parse
Mar 9, 2023
Merged

refactor parse and dump header functions#2618
davidism merged 1 commit intomainfrom
http-parse

Conversation

@davidism
Copy link
Copy Markdown
Member

@davidism davidism commented Mar 9, 2023

  • parse_list_header uses urllib.request.parse_http_list, which already unquotes and removes slash escapes. parse_dict_header and a few other places can remove inner key="value" quotes inline, without having to call unquote_header_value.
  • quote_header_value quotes the empty string, since an empty value isn't a valid token on its own.
  • quote_header_value extra_chars parameter is deprecated, it wasn't used anywhere and doesn't seem necessary for any HTTP header.
  • As part of drop support for bytes #2602, passing bytes to quote_header_value and parse_dict_header is deprecated.
  • dump_options_header skips None values instead of writing a bare key;. While bare keys are useful for headers that use dump_header, they're not valid in value; key=value parameters.
  • Inline the helper function that just did if value[-1] == "*" in dump_header and dump_options_header.
  • dump_header allow_token parameter is deprecated. quote_header_value still has the parameter, mainly for the Digest auth scheme.
  • parse_dict_header supports key*=UTF-8''value items the same way parse_options_header does.
  • Improve the docs for all these functions.

@davidism davidism added this to the 2.3.0 milestone Mar 9, 2023
deprecate some unused parameters and behaviors
deprecate passing bytes
handle quoting empty string
dumping options skips None values
unquote inline if calling the function would do some redundant work
parse dict handles values with charsets
@davidism davidism merged commit c9dbfd1 into main Mar 9, 2023
@davidism davidism deleted the http-parse branch March 9, 2023 20:41
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 24, 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.

1 participant