Inspecting Headers with Objective-C

Occasionally, an iOS app may to need to parse the headers out of an HTTP request. Here is one example to implement such behavior.

First consider the NSHTTPURLResponse Object:

<NSHTTPURLResponse: 0x79f4b7e0> 
{ 
    URL: http://zbeyer.com/stuff/mobile-testing/index.html 
} 
{ 
    status code: 200, 
    headers {
      "Accept-Ranges" = bytes;
      Age = 157;
      Connection = "Keep-Alive";
      "Content-Encoding" = gzip;
      "Content-Length" = 94;
      "Content-Type" = "text/html";
      Date = "Mon, 06 Jun 2016 21:20:29 GMT";
      "Last-Modified" = "Mon, 06 Jun 2016 18:36:03 GMT";
      Server = "nginx/1.10.1";
      Vary = "Accept-Encoding";
    } 
}

For this example, I am interested in the “Last Modified” header field on my sample index.html file. My application wants to know how long it’s been since that url was last updated.

Continue reading

Bookmark and Share