Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Why does RFC 3986 (URI generic syntax) declare the "host" component to be case-insensitive when the syntax rules show it to be case-sensitive?
First, a reminder to future self (the figure RFC 3986, Section 3. Syntax Components complemented with Section 3.2. Authority):
The following are two example URIs and their component parts:
userinfo host port
| | |
____|______ ___|_____ _|
/ \ / \ / \
foo://user:password@example.com:8042/over/there?name=ferret#nose
\_/ \____________________________/\_________/ \_________/ \__/
| | | | |
scheme authority *----------- path query fragment
| |
| _____________________|__
/ \ / \
urn:example:animal:ferret:nose
Section 3.2.2. Host makes it clear on multiple occasions that the "host" part is case-insensitive,
The host subcomponent is case-insensitive. [..] Although host is case-insensitive, producers and normalizers should use lowercase for registered names and hexadecimal addresses for the sake of uniformity, while only using uppercase letters for percent-encodings.
but the syntax rules allow for upper-case letters as well:
host = IP-literal / IPv4address / reg-name reg-name = *( unreserved / pct-encoded / sub-delims ) unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
Is the reasoning behind this related to the robustness principle? The "scheme" URI component (section 3.1. Scheme) seems to be defined with the same ambiguity, but it does justify it:
Although schemes are case-insensitive, the canonical form is lowercase and documents that specify schemes must do so with lowercase letters. An implementation should accept uppercase letters as equivalent to lowercase in scheme names (e.g., allow "HTTP" as well as "http") for the sake of robustness but should only produce lowercase scheme names for consistency.
scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
Section 3.2.2. Host does not state this rationale explicitly, so I presume that it is implied then?
As Moshi pointed out, I conflated the concepts of "case-sensitivity" and "case of letters":
The "scheme" component and the "host" authority sub-component being case-insensitive means that they can contain letters of any cases, but an implementation should treat "scheme" and "host" values, respectively, as identical if they only differ in the cases of the letters contained. (See ALPHA
's definition in Section 1.3 Syntax Notation.)
For future reference (summing up this answer):
-
[RFC 3986 (URI generic syntax), Section 6.2.2.1]: "scheme and host are case-insensitive [..]. The other generic syntax components are assumed to be case-sensitive unless specifically defined otherwise by the scheme"
-
[RFC 9110 (HTTP semantics), Section 4.2.3]: "The scheme and host are case-insensitive and normally provided in lowercase; all other components are compared in a case-sensitive manner."
1 answer
The following users marked this post as Works for me:
User | Comment | Date |
---|---|---|
toraritte | (no comment) | Mar 30, 2024 at 21:28 |
This question probably stems from misunderstanding what case sensitivity is. Being case insensitive does not mean only allowing one case - in fact, it implies the opposite! If one case was treated differently from the other, that would be the definition of case sensitivity.
What case insensitivity means is that they are treated as equivalent, i.e. GOOGLE.com is considered "the same as" google.com.
0 comment threads