This file contains 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 characters
command regex curl 's/(.+)/expr -l Swift -O -- let anyRequest = %1; if let unwrappedRequest = (anyRequest as? URLRequest), let url = unwrappedRequest.url { var baseCommand = #"curl "\#(url.absoluteString)""#; let quote = String(UnicodeScalar(UInt8(39))); if unwrappedRequest.httpMethod == "HEAD" { baseCommand += " --head"; }; var command = [baseCommand]; if let method = unwrappedRequest.httpMethod, (method != "GET" && method != "HEAD") { command.append("-X \(method)"); }; if let headers = unwrappedRequest.allHTTPHeaderFields { for (key, value) in headers where key != "Cookie" { command.append("-H \(quote)\(key): \(value)\(quote)"); }; }; if let data = unwrappedRequest.httpBody, let body = String(data: data, encoding: .utf8) { command.append("-d \(quote)\(body)\(quote)"); }; print(command.joined(separator: " \\\n\t"));}/' |