Last active
September 18, 2024 07:15
-
-
Save kh4zad/5e9e944aa43a8f290b7c865d36387d91 to your computer and use it in GitHub Desktop.
Revisions
-
kh4zad revised this gist
Jan 31, 2018 . 1 changed file with 1 addition and 1 deletion.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,5 +1,5 @@ import Alamofire import Gzip // using https://github.com/1024jp/GzipSwift public struct GZIPEncoding: ParameterEncoding { -
kh4zad created this gist
Jan 31, 2018 .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,31 @@ import Alamofire import Gzip public struct GZIPEncoding: ParameterEncoding { public func encode(_ urlRequest: URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest { var request = try urlRequest.asURLRequest() guard let parameters = parameters else { return request } do { let data = try JSONSerialization.data(withJSONObject: parameters, options: .prettyPrinted) if request.value(forHTTPHeaderField: "Content-Type") == nil { request.setValue("application/json", forHTTPHeaderField: "Content-Type") } request.httpBody = try data.gzipped() if request.httpBody != nil { request.setValue("gzip", forHTTPHeaderField: "Content-Encoding") } } catch { throw AFError.parameterEncodingFailed(reason: .jsonEncodingFailed(error: error)) } return request } }