http - (Swift) How to check if content-encoding is gzip -


is there way in swift find out if data request returns in gzip?

i want write test method check if content-encoding returns gzip file:
enter image description here

you can info header fields in httpurlresponse:

urlsession.shared.datatask(with: url) { (data, response, error) in     if let response = response as? httpurlresponse {         if let encoding = response.allheaderfields["content-encoding"] as? string {             print(encoding)             print(encoding == "gzip")         }     } }.resume() 

note downloads headers and data.

if want headers without downloading data, better solution use urlrequest set "head" this:

var request = urlrequest(url: url) request.httpmethod = "head"  urlsession.shared.datatask(with: request) { (_, response, _) in     if let response = response as? httpurlresponse {         if let enc = response.allheaderfields["content-encoding"] as? string {             print(enc)             print(enc == "gzip")         }     } }.resume() 

this way, headers downloaded.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -