envoyproxy/envoy

refactor HeaderParser to make implementation of formatters easier/saner

Open

#4,221 opened on Aug 21, 2018

View on GitHub
 (0 comments) (0 reactions) (0 assignees)C++ (5,373 forks)batch import
help wanted

Repository metrics

Stars
 (27,997 stars)
PR merge metrics
 (Avg merge 8d) (378 merged PRs in 30d)

Description

Currently HeaderParser::configure (via the parserInternal helper method) splits a string into fixed and dynamic HeaderFormatter implementations, but delegates parsing of the dynamic HeaderFormatter arguments to the actual Formatter. In practice this means each Formatter has to do its own argument parsing when most of them will likely just take a single string.

I propose to modify the constructor for RequestInfoHeaderFormatter to take a formatter name (e.g., "START_TIME", "UPSTREAM_METADATA", "PROTOCOL", etc...) and a collection of 0 or more string arguments. This will allow us to push the parsing of arguments down into HeaderParser::configure/parseInternal. Initially we'll accept the existing "JSON array of strings" and unquoted string arguments used by UPSTREAM_METADATA and START_TIME. We'll add a quoted string (with appropriate backslash de-escaping) that can be used interchangeably with the unquoted string for single-argument formatters.

Doing this will make it possible to adopt an alternative to the clunky JSON array syntax for formatters that take 2 or more arguments, although I don't purpose to do that at this point.

Relevant Links: #4148.

Contributor guide