SPB Git

spb/os-vault Public

Self-custody, multi-chain crypto wallet for macOS. One recovery phrase, six chain families, zero API keys — nothing leaves your Mac.

Swift 96% Shell 3.4% Makefile 0.6%
897 B · 28 lines swift
Raw Blame History
1import Foundation23public extension URLRequest {4    func cURL(pretty: Bool = false) -> String {5        let newLine = pretty ? "\\\n" : ""6        let method = (pretty ? "--request " : "-X ") + "\(httpMethod ?? "GET") \(newLine)"7        let url: String = (pretty ? "--url " : "") + "\'\(self.url?.absoluteString ?? "")\' \(newLine)"89        var cURL = "curl "10        var header = ""11        var data = ""1213        if let httpHeaders = allHTTPHeaderFields, !httpHeaders.keys.isEmpty {14            for (key, value) in httpHeaders {15                header += (pretty ? "--header " : "-H ") + "\'\(key): \(value)\' \(newLine)"16            }17        }1819        if let bodyData = httpBody, let bodyString = String(data: bodyData, encoding: .utf8), !bodyString.isEmpty {20            data = "--data '\(bodyString)'"21        }2223        cURL += method + url + header + data2425        return cURL26    }27}28