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

php - trouble displaying mysqli database results in correct order -

depending on nth recurrence of job in control M -

sql server - Cannot query correctly (MSSQL - PHP - JSON) -