This repository has been archived by the owner on Nov 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #135 from kgoodier/develop-future
Groundwork for future push work
- Loading branch information
Showing
20 changed files
with
1,106 additions
and
211 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// SPDYCacheStoragePolicy.h | ||
// SPDY | ||
// | ||
// Copyright (c) 2014 Twitter, Inc. All rights reserved. | ||
// Licensed under the Apache License v2.0 | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Derived from code in Apple, Inc.'s CustomHTTPProtocol sample | ||
// project, found as of this notice at | ||
// https://developer.apple.com/LIBRARY/IOS/samplecode/CustomHTTPProtocol | ||
// | ||
|
||
#include <Foundation/Foundation.h> | ||
|
||
/*! Determines the cache storage policy for a response. | ||
* \details When we provide a response up to the client we need to tell the client whether | ||
* the response is cacheable or not. The default HTTP/HTTPS protocol has a reasonable | ||
* complex chunk of code to determine this, but we can't get at it. Thus, we have to | ||
* reimplement it ourselves. This is split off into a separate file to emphasise that | ||
* this is standard boilerplate that you probably don't need to look at. | ||
* \param request The request that generated the response; must not be nil. | ||
* \param response The response itself; must not be nil. | ||
* \returns A cache storage policy to use. | ||
*/ | ||
extern NSURLCacheStoragePolicy SPDYCacheStoragePolicy(NSURLRequest *request, NSHTTPURLResponse *response); |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// | ||
// SPDYCacheStoragePolicy.m | ||
// SPDY | ||
// | ||
// Copyright (c) 2014 Twitter, Inc. All rights reserved. | ||
// Licensed under the Apache License v2.0 | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Derived from code in Apple, Inc.'s CustomHTTPProtocol sample | ||
// project, found as of this notice at | ||
// https://developer.apple.com/LIBRARY/IOS/samplecode/CustomHTTPProtocol | ||
// | ||
|
||
#import "SPDYCacheStoragePolicy.h" | ||
|
||
extern NSURLCacheStoragePolicy SPDYCacheStoragePolicy(NSURLRequest *request, NSHTTPURLResponse *response) | ||
{ | ||
bool cacheable; | ||
NSURLCacheStoragePolicy result; | ||
|
||
// First determine if the request is cacheable based on its status code. | ||
|
||
switch (response.statusCode) { | ||
case 200: | ||
case 203: | ||
case 206: | ||
case 301: | ||
case 304: | ||
case 404: | ||
case 410: | ||
cacheable = YES; | ||
break; | ||
default: | ||
cacheable = NO; | ||
break; | ||
} | ||
|
||
// If the response might be cacheable, look at the "Cache-Control" header in | ||
// the response. | ||
|
||
// IMPORTANT: We can't rely on -rangeOfString: returning valid results if the target | ||
// string is nil, so we have to explicitly test for nil in the following two cases. | ||
|
||
if (cacheable) { | ||
NSString *responseHeader; | ||
|
||
for (NSString *key in [response.allHeaderFields allKeys]) { | ||
if ([key caseInsensitiveCompare:@"cache-control"] == NSOrderedSame) { | ||
responseHeader = [response.allHeaderFields[key] lowercaseString]; | ||
break; | ||
} | ||
} | ||
|
||
if (responseHeader != nil && [responseHeader rangeOfString:@"no-store"].location != NSNotFound) { | ||
cacheable = NO; | ||
} | ||
} | ||
|
||
// If we still think it might be cacheable, look at the "Cache-Control" header in | ||
// the request. | ||
|
||
if (cacheable) { | ||
NSString *requestHeader; | ||
|
||
requestHeader = [[request valueForHTTPHeaderField:@"cache-control"] lowercaseString]; | ||
if (requestHeader != nil && | ||
[requestHeader rangeOfString:@"no-store"].location != NSNotFound && | ||
[requestHeader rangeOfString:@"no-cache"].location != NSNotFound) { | ||
cacheable = NO; | ||
} | ||
} | ||
|
||
// Use the cacheable flag to determine the result. | ||
|
||
if (cacheable) { | ||
// Modern versions of iOS use file protection to protect the cache, and thus are | ||
// happy to cache HTTPS on disk. Previous code here returned | ||
// NSURLCacheStorageAllowedInMemoryOnly for https. | ||
result = NSURLCacheStorageAllowed; | ||
} else { | ||
result = NSURLCacheStorageNotAllowed; | ||
} | ||
|
||
return result; | ||
} |
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
Oops, something went wrong.