Scala – 1 Star – Would Not Program Again
The section on HTTP headers and typing is a little concerning to me. I've been making rust-http recently and (before I was aware of Spray) I felt strongly about the typing. So, I'd like to discuss this. Am I wrong after all? Here clearly is someone that disagrees with me. I think I should probably write up a long blog post on the topic explaining my reasoning and so forth.<p>rust-http is, at present at least, rejecting the standard practice of stringly typed headers and is using strongly typed headers.<p>> ... and even types for every ‘known’ HTTP header.<p>> The known HTTP header part was particularly ridiculous. HTTP headers are <i>defined</i> as simple key/value pairs. You’re supposed to be allowed to add arbitrary headers. You’re not supposed to be constrained by the framework you’re using not having any support for CORS yet.<p>He has taken a strong position against this strong typing; I take a similarly strong position <i>for</i> such strong typing.<p>Yes, HTTP headers are defined as simple key/value pairs. But headers are <i>not</i> text; they are <i>data</i>. XML is defined as text. Should we use regular expressions to work with it? (True, it also has the DOM defined. But HTTP headers <i>also</i> have a grammar defined—it just happens to include the admissibility of extension headers.)<p>HTTP is a serialisation format for messages; messages made up of computer-readable data, not text.<p>I wrote a handful of paragraphs about this subject at <a href="https://github.com/chris-morgan/rust-http/issues/1" rel="nofollow">https://github.com/chris-morgan/rust-http/issues/1</a> where using a map instead of typed headers was suggested.<p>As I also note there, I would not attempt such a scheme in a language like Python (my primary language for some years) because its type system is not well adjusted to something like this; I am certain it would cause many problems and feel it likely it would cause more than it solved. But in a language with a solid type system capable of expressing these things, taking advantage of it should lead to a faster, more correct program.<p>In the end, I believe strongly typed headers are a good thing to have (it will actually make most code distinctly nicer—e.g. ``response.headers.date = Some(now())`` instead of ``response.headers.set("Date", now().to_http_header())``). The implementation of the scheme in rust-http is certainly not perfect yet; I'm not happy with it at present; I'm expecting to turn the extension headers into a trait object, and I've even considered crazy ideas like allowing users of the library to make their own header collection (request.headers and response.headers) types—that would allow custom headers to be made first-class citizens but could lead to compatibility problems.<p>Still, I don't want to make something that I believe should be the best HTTP library around and find that people hate to use it. What do you think about this header matter?