<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">This automatically include all future version without modify any existing code.</div><div class=""><br class=""></div>extension HTTPVersion {<div class=""> public func > (lhs: HTTPVersion, rhs: HTTPVersion) -> Bool</div><div class=""> {</div><div class=""> return lhs.major > rhs.major ? true : (lhs.minor > rhs.minor)</div><div class=""> }</div><div class=""><br class=""></div><div class=""> public static var minimumVersionSupportsMulitpleDomain: HTTPVersion {</div><div class=""> return HTTPVersion(1,1)</div><div class=""> }</div><div class=""><br class=""></div><div class=""> var isMulitpleDomainCapable: Bool {</div><div class=""> return self > HTTPVersion.minimumVersionSupportsMulitpleDomain</div><div class=""> }</div><div class="">}</div><div class=""><br class=""></div><div class="">Cheers,</div><div class="">Michael</div><div class=""><div><blockquote type="cite" class=""><div class="">On Jun 14, 2017, at 2:30 AM, Rien <<a href="mailto:Rien@Balancingrock.nl" class="">Rien@Balancingrock.nl</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><blockquote type="cite" class="">On 14 Jun 2017, at 09:12, Michael Chiu <<a href="mailto:hatsuneyuji@icloud.com" class="">hatsuneyuji@icloud.com</a>> wrote:<br class=""><br class="">I think currently the http version is come from the http_parser which has parsed the version string to number anyway. hence the performance should be similar.<br class=""></blockquote><div class=""><br class=""></div><div class="">That is likely, but imo the HTTP API should be judged on its own merits.</div><div class=""><br class=""></div><br class=""><blockquote type="cite" class=""><br class="">I do see some advantage to use struct tho, for example comparing only major version.<br class=""></blockquote><div class=""><br class=""></div><div class=""><br class=""></div><div class="">That is where I don’t see a real world advantage. Theoretically you are correct, but in a real world example?, do you have an example where this is indeed useful?</div><div class="">Given the limited range of useful versions numbers (only 3!) I just don’t see it.</div><div class=""><br class=""></div><div class="">I realize that this reaches into preferred programming techniques, but I like to use capability test on the type.</div><div class="">I.e. I would write</div><div class=""><br class=""></div><div class=""><font face="Courier New" class="">enum HttpVersion { case http1_0, http1_1, http2_0 }</font></div><div class=""><font face="Courier New" class=""><br class=""></font></div><div class=""><font face="Courier New" class="">extension HttpVersion {</font></div><div class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>var isMultipleDomainCapable: Bool {</font></div><div class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>switch self {</font></div><div class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>case .http1_0: return false</font></div><div class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>case .http1_1: return true</font></div><div class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>case .http2_0: return true</font></div><div class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>}</font></div><div class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</font></div><div class=""><font face="Courier New" class="">}</font></div><div class=""><font face="Courier New" class=""><br class=""></font></div><div class=""><font face="Courier New" class="">if version.isMultipleDomainCapable {<span class="Apple-tab-span" style="white-space: pre;">        </span>}</font></div><div class=""><br class=""></div><div class="">instead of:</div><div class=""><br class=""></div><div class=""><font face="Courier New" class="">struct HttpVersion {</font></div><div class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let major: Int</font></div><div class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let minor: Int</font></div><div class=""><font face="Courier New" class=""><br class=""></font></div><div class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>static func == ...</font></div><div class=""><font face="Courier New" class="">}</font></div><div class=""><font face="Courier New" class=""><br class=""></font></div><div class=""><font face="Courier New" class="">if (version == HttpVersion(1, 1) || (version == HttpVersion(2, 0)) {</font></div><div class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>// supports multiple domains</font></div><div class=""><font face="Courier New" class="">}</font></div><div class=""><br class=""></div>Regards,<br class="">Rien<br class=""><br class="">Site: <a href="http://balancingrock.nl/" class="">http://balancingrock.nl</a><br class="">Blog: <a href="http://swiftrien.blogspot.com/" class="">http://swiftrien.blogspot.com</a><br class="">Github: <a href="http://github.com/Balancingrock" class="">http://github.com/Balancingrock</a><br class="">Project: <a href="http://swiftfire.nl/" class="">http://swiftfire.nl</a> - An HTTP(S) web server framework in Swift<br class=""><br class=""><blockquote type="cite" class=""><br class="">Michael<br class=""><br class=""><blockquote type="cite" class="">On Jun 13, 2017, at 11:41 PM, Rien via swift-server-dev <<a href="mailto:swift-server-dev@swift.org" class="">swift-server-dev@swift.org</a>> wrote:<br class=""><br class="">The choices seem to be:<br class=""><br class="">1) String<br class="">2) Enum<br class="">3) Tuple<br class="">4) Struct<br class="">5) Class<br class=""><br class="">1) String<br class="">Advantage: it is in fact an utf-8 string. No conversions needed.<br class="">Disadvantage: It is mostly thought of as a number, thus the abstraction does not match the type, very minor performance penalty in comparing. Illogical to add HTTP-version extensions to the type.<br class=""><br class="">2) Enum<br class="">Advantage: shortest possible representation (?), fastest compare (?), easy to use.<br class="">Disadvantage: Needs converting to and from.<br class=""><br class="">3) Tuple<br class="">Advantage: Matches fairly wel with the abstraction.<br class="">Disadvantage: Fairly complex conversion, adding members/operations is non-intuitive, not very easy to use.<br class=""><br class="">4) Struct<br class="">Advantage: Matches fairly wel with the abstraction.<br class="">Disadvantage: Fairly complex conversion. Not very easy to use without adding members/operations.<br class=""><br class="">5) This was for completeness only, I would be very surprised if anybody would actually propose this… ;-)<br class=""><br class=""><br class="">To me that leaves option 2 and 4.<br class="">Advantage of 2 over 4:<br class=""><br class="">- I find the abstraction a better match. The difference between 1, 1.1 and 2 is such that it makes little sense to be to differentiate based on the numerical values. It makes much more sense to differentiate based on the “whole number”. AFAIIC they could just as easily have named the versions A, B, C etc. The numbers do not convey any information as such.<br class="">- Switch is easier and more intuitive to use.<br class="">- Enums can have additional properties and operations similar to struct.<br class=""><br class="">Advantage of 4 over 2:<br class="">I don’t see any.<br class=""><br class="">Regards,<br class="">Rien<br class=""><br class="">Site: <a href="http://balancingrock.nl/" class="">http://balancingrock.nl</a><br class="">Blog: <a href="http://swiftrien.blogspot.com/" class="">http://swiftrien.blogspot.com</a><br class="">Github: <a href="http://github.com/Balancingrock" class="">http://github.com/Balancingrock</a><br class="">Project: <a href="http://swiftfire.nl/" class="">http://swiftfire.nl</a> - An HTTP(S) web server framework in Swift<br class=""><br class=""><br class=""><br class=""><blockquote type="cite" class="">On 13 Jun 2017, at 22:44, Chris Bailey via swift-server-dev <<a href="mailto:swift-server-dev@swift.org" class="">swift-server-dev@swift.org</a>> wrote:<br class=""><br class="">Based on our discussed approach of reviewing each of the types in the HTTP project, I've raised the following PR to convert HTTPVersion from (Int, Int) to a struct based on Paulo's proposal: <br class=""> <a href="https://github.com/swift-server/http/pull/6" class="">https://github.com/swift-server/http/pull/6</a> <br class=""><br class="">I've not yet added Hashable, Equatable and CustomStringConvertible protocols - we can do that if we're happy with the change. <br class=""><br class="">Chris<br class="">Unless stated otherwise above:<br class="">IBM United Kingdom Limited - Registered in England and Wales with number 741598. <br class="">Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU<br class="">_______________________________________________<br class="">swift-server-dev mailing list<br class=""><a href="mailto:swift-server-dev@swift.org" class="">swift-server-dev@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-server-dev" class="">https://lists.swift.org/mailman/listinfo/swift-server-dev</a><br class=""></blockquote><br class="">_______________________________________________<br class="">swift-server-dev mailing list<br class=""><a href="mailto:swift-server-dev@swift.org" class="">swift-server-dev@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-server-dev" class="">https://lists.swift.org/mailman/listinfo/swift-server-dev</a><br class=""></blockquote><br class=""></blockquote><br class=""></div></div></blockquote></div><br class=""></div></body></html>