<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 23 Mar 2017, at 10:18, Logan Wright <<a href="mailto:logan@qutheory.io" class="">logan@qutheory.io</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Alex,<div class=""><br class=""></div><div class="">Since this is a parser, I'd opt for something more general like `[String: String?]` (would need to check on the optional there), because that's how the parser will likely receive it, ie:</div><div class=""><br class="">Key: Value\r\n<br class="">Other-Key: OtherValue\r\n<br class=""></div></div></div></blockquote><div><br class=""></div><div>The problem is that the HTTP spec permits:</div><div><br class=""></div><div><div>Key: Value\r\n<br class=""><div dir="ltr" class=""><div class="">Other-Key: OtherValue\r\n<br class=""></div></div><div class=""><div dir="ltr" class=""><div class="">Key: Different Value\r\n<br class=""><div dir="ltr" class=""></div></div></div></div></div></div><div><br class=""></div>and this isn't possible with a single dictionary as an implementation. So instead of constraining the implementation to a particular assumption about how implementations may need to use it, define the API for how you want to interact with it, e.g.:</div><div><br class=""></div><div><a href="https://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#getHeader(java.lang.String)" class="">https://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#getHeader(java.lang.String)</a></div><div><a href="https://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#getHeaders(java.lang.String)" class="">https://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#getHeaders(java.lang.String)</a> </div><div><a href="https://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#getHeaderNames()" class="">https://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#getHeaderNames()</a> </div><div><br class=""></div><div>In other words, make the simple case easy but permit the additional cases as well.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="">Then inside the initializer, the model would modify it, create arrays or custom headers models as they see fit. This allows the server side apis to opt out out of taking too many opinions and lets frameworks decide what's best for them. Many want simple [String: String], at Vapor we use [HeaderKey: String] for case insensitivity, some might want something that's considered more "correct" as [CaseInsensitive: [String?]?] or something.</div></div></div></blockquote><div><br class=""></div><div>Do you want/need [String:String?], or do you just want something as simple as a data structure that takes a String subscript and returns a String? In fact you can have two views (much like different views exist on strings for e.g. utf8 and utf16) that provide you the case sensitivity or not:</div><div><br class=""></div><div>headers.caseSensitive["Cache-Control"]</div><div>headers.caseInsensitive["Cache-Control"]</div><div><br class=""></div><div>One could always provide the default case-sensitive view on the headers as well:</div><div><br class=""></div><div>headers["Cache-Control"]</div><div><br class=""></div><div>That API, while it would be satisfied by [String:String?], doesn't imply that it must be [String:String?].</div><div><br class=""></div><div>Furthermore it's worth noting that [String:String?] is not order preserving on the headers, while HTTP is an ordered sequence of such headers. I doubt there's anyone who would need to know that but it's an example of something that an API may need to provide that can't be done with a trivial implementation.</div><br class=""><blockquote type="cite" class=""><div dir="ltr" class=""><div class="">All of these are arguably valid, so I think taking the approach of Parser's perspective and how things are received would be a good paradigm to strive towards.</div></div></blockquote><div><br class=""></div><div>I'm not clear what you're referring to here; do you have an example?</div><br class=""><blockquote type="cite" class=""><div dir="ltr" class=""><div class="">The one thing missing in my example is order, which perhaps `[(String, String?)]` would be better if there are significant implications for order here to an end model. </div></div></blockquote><div><br class=""></div><div>This is why I think defining the headers to be <a specific data structure> is impractical, and using a protocol to define how you interact with them is more appropriate.</div><br class=""></div><div>Alex</div><br class=""></body></html>