Last active
July 18, 2025 10:29
Revisions
-
shaps80 revised this gist
May 4, 2020 . 1 changed file with 0 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -32,8 +32,4 @@ extension URLRequest { return command.joined(separator: " \\\n\t") } } -
shaps80 revised this gist
May 4, 2020 . 1 changed file with 12 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,18 +1,20 @@ import Foundation extension URLRequest { /** Returns a cURL command representation of this URL request. */ public var curlString: String { guard let url = url else { return "" } var baseCommand = #"curl "\#(url.absoluteString)""# if httpMethod == "HEAD" { baseCommand += " --head" } var command = [baseCommand] if let method = httpMethod, method != "GET" && method != "HEAD" { command.append("-X \(method)") } @@ -22,16 +24,16 @@ extension URLRequest { command.append("-H '\(key): \(value)'") } } if let data = httpBody, let body = String(data: data, encoding: .utf8) { command.append("-d '\(body)'") } return command.joined(separator: " \\\n\t") } init?(curlString: String) { return nil } } -
shaps80 created this gist
Feb 13, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ extension URLRequest { /** Returns a cURL command representation of this URL request. */ public var curlString: String { guard let url = url else { return "" } var baseCommand = "curl \(url.absoluteString)" if httpMethod == "HEAD" { baseCommand += " --head" } var command = [baseCommand] if let method = httpMethod, method != "GET" && method != "HEAD" { command.append("-X \(method)") } if let headers = allHTTPHeaderFields { for (key, value) in headers where key != "Cookie" { command.append("-H '\(key): \(value)'") } } if let data = httpBody, let body = String(data: data, encoding: .utf8) { command.append("-d '\(body)'") } return command.joined(separator: " \\\n\t") } init?(curlString: String) { return nil } }