forked from swift-server/http
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTTPVersion.swift
More file actions
57 lines (49 loc) · 1.47 KB
/
HTTPVersion.swift
File metadata and controls
57 lines (49 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// This source file is part of the Swift.org Server APIs open source project
//
// Copyright (c) 2017 Swift Server API project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
//
/// Version number of the HTTP Protocol
public struct HTTPVersion {
/// Major version component.
public private(set) var major: Int
/// Minor version component.
public private(set) var minor: Int
/// Creates an HTTP version.
public init(major: Int, minor: Int) {
self.major = major
self.minor = minor
}
}
extension HTTPVersion : Hashable {
/// :nodoc:
public var hashValue: Int {
return (major << 8) | minor
}
/// :nodoc:
public static func == (lhs: HTTPVersion, rhs: HTTPVersion) -> Bool {
return lhs.major == rhs.major && lhs.minor == rhs.minor
}
/// :nodoc:
public static func ~= (match: HTTPVersion, version: HTTPVersion) -> Bool {
return match == version
}
}
extension HTTPVersion : Comparable {
/// :nodoc:
public static func < (lhs: HTTPVersion, rhs: HTTPVersion) -> Bool {
if lhs.major != rhs.major {
return lhs.major < rhs.major
} else {
return lhs.minor < rhs.minor
}
}
}
extension HTTPVersion : CustomStringConvertible {
/// :nodoc:
public var description: String {
return "HTTP/" + major.description + "." + minor.description
}
}