Closed buh closed 2 years ago
Hey!
I want to suggest you to add an extension for JSONEncoder.DataEncodingStrategy that's really help to use GzipSwift for requests:
JSONEncoder.DataEncodingStrategy
extension JSONEncoder.DataEncodingStrategy { // Gzip data encoding strategy. public static var gzip: JSONEncoder.DataEncodingStrategy { return .custom { data, encoder throws in var container = encoder.singleValueContainer() let gzippedData = try data.gzipped() try container.encode(gzippedData) } } }
Here how it would be easy to use:
let encoder = JSONEncoder() encoder.dataEncodingStrategy = .gzip urlRequest.httpBody = try encoder.encode(data) urlRequest.addValue("gzip", forHTTPHeaderField: "Content-Encoding")
Let me know what you think.
Hey!
I want to suggest you to add an extension for
JSONEncoder.DataEncodingStrategy
that's really help to use GzipSwift for requests:Here how it would be easy to use:
Let me know what you think.