Behavior of header matching should treat field names as case-insensitive, but not values
See original GitHub issueOverview
First, the default behavior of Karate is incorrect in how it handles the matching of header field names. It treats them in a case-sensitive manner, which is incorrect, as will be explained below.
Second, the documentation is (perhaps inadvertently) misleading in that it suggests that both header field names and header field values are treated case-insensitive according to the HTTP spec.
Problem 1 Detailed
For Karate to correctly follow the HTTP Spec for headers, it should have default behavior as follows:
- When using
match header <field-name> == // etc..
the field name in question should be found no matter what case it is supplied in.
For example, whether or not the user enters vary
or Vary
here, and whether or not it is returned in the response as vary
or Vary
, or even as vArY
, it should match.
Problem 1 Explanation
The HTTP spec specifies that:
Field names are case-insensitive.
It explicitly does not specify the same for field values, thus indicating that field values should be treated in a case-sensitive manner.
For further proof of this, consider that the curl command lowercases all header field names by default, but not the field values.
In issue 504, the same issue was raised, but the decision appears to have been to introduce a secondary feature that can be toggled on to configure lower-casing of both header field names and header field values prior to when matching occurs. That is fine as an additional feature since it is documented, but that solution also does not meet the spec because it lowercases both the header field names and header field values.
The bottom line is that Karate does not adhere to the HTTP spec in either the default configuration or when lowerCaseResponseHeaders
has been set to true
.
Problem 1 Proposed solution
By default, Karate should match header field names in a case-insensitive way.
Problem 2 Detailed
The README documentation incorrectly states the following:
Since as per the HTTP spec, headers are case-insensitive you may want to switch on this setting:
* configure lowerCaseResponseHeaders = true
- if you need to perform a lot of assertions on theresponseHeaders
.
Problem 2 Explanation
The README statement is incorrect. Headers are not case-insenstive according to the spec. Field names are.
Problem 2 Proposed Solution
The README should be reworded to something like the following:
Since as per the HTTP spec, header field names are case-insensitive . . .
Zip repro
The attached zip file contains a minimal, complete, and verifiable example. The scenario therein should succeed if Karate’s default behavior correctly reflected the HTTP spec because the value in the response from the fake JSON service (at least at the time of this writing) is as follows:
Vary: Origin, Accept-Encoding
Which means that the And match header vary == 'Origin, Accept-Encoding'
assertion should succeed. Currently it fails.
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (6 by maintainers)
@ilamn yes I can confirm the last RC4 will go out this week
Thanks a lot for the quick turnaround @ptrthomas . can confirm it works now. is there any further RC planned ? would be nice if there is one, so that I can use the fix at my work.