Created
August 24, 2018 19:33
-
-
Save lacyrhoades/4d1e2a4979838901fbe042653714250b to your computer and use it in GitHub Desktop.
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
struct TwilioEncoding: ParameterEncoding { | |
static var totallyNormal = TwilioEncoding() | |
// Twilio requires this weird encoding for arrays | |
func encode(_ urlRequest: URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest { | |
var request = try URLEncoding().encode(urlRequest, with: parameters) | |
if let data = request.httpBody, let string = String(data: data, encoding: .utf8) { | |
let replaced = string.replacingOccurrences(of: "%5B%5D=", with: "=") | |
request.httpBody = replaced.data(using: .utf8) | |
} | |
return request | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment