summaryrefslogtreecommitdiffhomepage
path: root/ios/MullvadREST/ApiHandlers/HTTP.swift
blob: ac4aa6730f82d1212dab6d5f1b81b8f1ac180b3c (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
51
52
//
//  HTTP.swift
//  HTTP
//
//  Created by pronebird on 06/09/2021.
//  Copyright © 2025 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")
    static let head = HTTPMethod(rawValue: "HEAD")

    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"
    static let userAgent = "User-Agent"
}