by kybernetikos · 3y ago · 0 comments
However, I have had to deal occasionally with http libraries that tried to parse everything and would not give you access to anything that they could not parse. This was incredibly frustrating for corner cases that the library authors hadn't considered.
If you are the one who is going to take action on the data, parse don't validate is the correct approach. If you are writing a library that deals with data that it doesn't fully understand, and you're handing that data to someone else to take action with, then it may not always be the right approach.
What was your solution to this? Parse the things the library didn't?
In my view it's a very bad design for an http library, although it would have been a lot less frustrating if it had at least provided an escape hatch.
I typically design code around things like this with a sum type like:
data Header = KnownHeader1 | KnownHeader2 | UnknownHeader String String
Then I typically don't offer any extra support or extended functionality for the cases where the type is `UnknownHeader`.Which I agree, is a poor design choice. A type modeling an HTTP request should model the RFC definition as closely as possible.
I couldn't disagree more. A type modeling an HTTP request should model HTTP requests. Not some theoretical description of an HTTP request.