We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Constraints

We've got our header parsing mostly working, but we're actually not being as strict as we should be to match the RFC. Let's fix that.

Case Insensitivity

Ever wonder why there's usually a .Get method on a header object to get header values? It's because these darned keys (not necessarily values) are case insensitive! If you use the hash map directly, you'll have to account for Content-Length and content-length being the same on your own.

Valid Characters

Interestingly, definitions can be spread across multiple RFCs.field-name has an implicit definition of a token as defined by RFC 9110.

5.1. Field Names
A field name labels the corresponding field value as having the semantics defined by that name. For example, the Date header field is defined in Section 6.6.1 as containing the origination timestamp for the message in which it appears.

  field-name     = token

And then in 5.6.2:

  token          = 1*tchar

  tchar          = "!" / "#" / "$" / "%" / "&" / "'" / "*"
                 / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~"
                 / DIGIT / ALPHA
                 ; any VCHAR, except delimiters

In other words, a field-name must contain only:

  • Uppercase letters: A-Z
  • Lowercase letters: a-z
  • Digits: 0-9
  • Special characters: !, #, $, %, &, ', *, +, -, ., ^, _, `, |, ~

and at least a length of 1.

Assignment

    • Always lowercase the key before adding it to the map
    • Return an error if the key contains an invalid character.

Run and submit the CLI tests.