by MichaelGG · 10y ago · 0 comments
Not even getting into sillier things that aren't just parsing, like absolute vs relative URI in request line vs host header. Or how some headers have different parse semantics.
SIP uses the same format as HTTP and the number of basic interop (and security!) issues due to parsing is astounding.
Parsing human writeable text is hard, proven via such interop issues. The key here is that this is "human writeable". If HTTP, for instance, eliminated free formatting and CRLF in favour of just LF that'd be a huge improvement. You could actually parse all headers, correctly, just doing:
Var parts = msg.split(\n\n)
Var hdrs = parts[0].split(\n).map(|x| {
Var xs = x.split(:)
xs.[0], xs.[1] }
Instead, people write similar code, thinking it works, and might achieve interop with some popular implementations that handle things well enough.If they used a tight text protocol (which really is basically a bloated binary protocol, just eg with newline instead of null as a terminator), none of these encoding issues would exist. It'd still be pointlessly inefficient, but reduce basic parse issues.
In fact the IETF has belatedly realised this for HTTP and the latest RFC kills spacing around colon and line folding. In the name of security, since it was causing actual issues since implementations weren't reading messages the same way.
And funny enough, this updated HTTP1.1 RFC breaks preciously working implementations.
I think with HTTP specifically, the problem is that implementations came first. There were already multiple implementations in the wild before the RFCs were written. Thus, the spec was written to accommodate the implementations rather than the other way around.
Actually, we've been parsing human writable text for half of a century. It's kind of a solved problem. We have good enough tools and DSLs to make binary protocols much harder to deal with.
Perhaps others mainly think of things like the ASN.1 used in X.509 (and part of TLS) when they hear "binary protocol", which is at the high end of the complexity scale; but binary protocols can be and often are much simpler.