summaryrefslogtreecommitdiffhomepage
path: root/ios/MullvadREST/HTTP.swift
blob: 900ab2a49aee6c5d15284985ccfe12946d6005f5 (plain)
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
//
//  HTTP.swift
//  HTTP
//
//  Created by pronebird on 06/09/2021.
//  Copyright © 2021 Mullvad VPN AB. All rights reserved.
//

import Foundation

/// HTTP method
struct HTTPMethod: RawRepresentable {
    static let get = HTTPMethod(rawValue: "GET")
    static let post = HTTPMethod(rawValue: "POST")
    static let delete = HTTPMethod(rawValue: "DELETE")
    static let put = HTTPMethod(rawValue: "PUT")

    let rawValue: String
    init(rawValue: String) {
        self.rawValue = rawValue.uppercased()
    }
}

struct HTTPStatus: RawRepresentable, Equatable {
    static let notModified = HTTPStatus(rawValue: 304)
    static let badRequest = HTTPStatus(rawValue: 400)
    static let notFound = HTTPStatus(rawValue: 404)

    static func isSuccess(_ code: Int) -> Bool {
        (200 ..< 300).contains(code)
    }

    let rawValue: Int
    init(rawValue: Int) {
        self.rawValue = rawValue
    }

    var isSuccess: Bool {
        Self.isSuccess(rawValue)
    }
}

/// HTTP headers
enum HTTPHeader {
    static let host = "Host"
    static let authorization = "Authorization"
    static let contentType = "Content-Type"
    static let etag = "ETag"
    static let ifNoneMatch = "If-None-Match"
}