summaryrefslogtreecommitdiffhomepage
path: root/ios/MullvadRustRuntime/MullvadApiResponse.swift
blob: 597de40b7545ec855f02fdad81bfc3501267ce1a (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
//
//  MullvadApiResponse.swift
//  MullvadVPN
//
//  Created by Jon Petersson on 2025-01-24.
//  Copyright © 2025 Mullvad VPN AB. All rights reserved.
//

public class MullvadApiResponse {
    private let response: SwiftMullvadApiResponse

    public init(response: consuming SwiftMullvadApiResponse) {
        self.response = response
    }

    deinit {
        mullvad_response_drop(response)
    }

    public var body: Data? {
        guard let body = response.body else {
            return nil
        }

        return Data(UnsafeBufferPointer(start: body, count: Int(response.body_size)))
    }

    public var etag: String? {
        response.etag.map { String(cString: $0) }
    }

    public var errorDescription: String? {
        response.error_description.map { String(cString: $0) }
    }

    public var statusCode: UInt16 {
        response.status_code
    }

    public var serverResponseCode: String? {
        response.server_response_code.map { String(cString: $0) }
    }

    public var success: Bool {
        response.success
    }
}