question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Behavior of header matching should treat field names as case-insensitive, but not values

See original GitHub issue

Overview

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 the responseHeaders.

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:closed
  • Created 3 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ptrthomascommented, Feb 8, 2021

@ilamn yes I can confirm the last RC4 will go out this week

0reactions
ilamncommented, Feb 8, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Behavior of header matching should treat field names as case ...
The HTTP spec specifies that: Field names are case-insensitive. It explicitly does not specify the same for field values, thus indicating that ...
Read more >
Are HTTP headers case-sensitive? - Stack Overflow
Answer is still true, RFC 7230 states: "Each header field consists of a case-insensitive field name followed by a colon (":"), optional leading...
Read more >
rfc4485.txt - » RFC Editor
Header field parameter names MUST be case insensitive. Header field values and parameter values are sometimes case sensitive, and sometimes case insensitive ......
Read more >
HTTP headers - MDN Web Docs - Mozilla
An HTTP header consists of its case-insensitive name followed by a colon ( : ), then by its value. Whitespace before the value...
Read more >
How to enable case-insensitive property name matching with ...
Learn how to enable case-insensitive property name matching while serializing to and deserializing from JSON in .NET.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found