falco
falco copied to clipboard
Header field / subfield rework
Using the current approach, and in the proposed changes in #248, we have of storing fields in a structured format is challenging to achieve compatibility with unusual behavior of Fastly's RFC-8941 header dictionary implementation.
This PRs implementation takes the approach of extracting the field being operated on at the time of access using the observed behavior of Fastly's implementation.
With this approach edge cases in how fastly handles things can be correctly supported for example dealing with fields that contain the field separator.
set req.http.foo:a = "1,b=2";
log req.http.foo:a; // -> 1,b=2
log req.http.foo:b; // -> 2"
The regular expression used in this is admittedly quite opaque and was derived through trial and error based on observing Fastly behavior in as many cases as I could come up with. This same general approach could be achieved with an iterative parser which would be easier to follow what is happening but would be considerably more code. If there is maintainability concern with the regex approach I'm happy to rework this.
Additionally the subfield
built-in function shares the field access behavior of the :
operator. Updated that function to share the same implementation.
This implementation was validated against Fastly's behavior using this suite of tests: https://github.com/richardmarshall/falco-validation-tests/blob/main/header_fields/main.test.vcl