[swift-server-dev] Convert HTTPVersion to struct
me at helgehess.eu
Wed Jun 14 05:11:25 CDT 2017
On 14. Jun 2017, at 11:36, Rien via swift-server-dev <swift-server-dev at swift.org> wrote:
>> On 14 Jun 2017, at 11:14, Chris Bailey <BAILEYC at uk.ibm.com> wrote:
>> One factor is whether you consider the version to be discrete values or a structured format for data - I'd argue that we have a structured format due to the expectation that future versions of the HTTP spec could arrive.
> But do you want your code littered with numerical tests or conceptual tests?
> Suppose a new version of HTTP does arrive, do you really want to manually walk through the code and find all tests on the numerical values?
> Or would it be easier to use switch statements on an enum and have all missing cases pointed out to you?
This is actually a argument *for* using numbers. When using an enum in an API makes the same break every time you change it. And that is killer for a an API representing a living protocol like HTTP.
Also in proper source you would check for: `if major >= 2`, not `==`, another advantage of using version _numbers_.
In the context of HTTPVersion I think there shouldn’t be too much discussion though, for two reasons:
- If we get HTTP/3.x, we almost certainly have a new API revision.
- The HTTP version should only matter for logging purposes. The differences in capabilities
should be handled by the implementation (e.g. keep alive vs not, multiplexing or not, etc).
In other words, you should never have to check for the versions, but rather features.
More information about the swift-server-dev