Customising download HTTP requests

If you need to need to customise the HTTP requests made when downloading files through the document manager (for example, adding custom header fields), you should set the document manager's downloadDelegate property to point to a callback object that implements the willSendRequest: method.

- (void)willSendRequest:(NSMutableURLRequest*)request {
  // Make any changes you want to the request object here.

A good place to set the delegate is in your app delegate's application:didFinishLaunchingWithOptions: method before performing any download operations.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  KGDocumentManager *dm = [KGDocumentManager sharedManager];
  [dm setDownloadDelegate:self]; // Set the download delegate here.

The willSendRequest: method will be called for every file downloaded via the document manager. This includes the OPDS feed, document cover images, and all the files making up the documents themselves.

However, note that the push notification manager and the auth providers are independent from the document manager, so any HTTP connections they make will not trigger this callback.

Example: Amazon S3 - Stripping Out Auth Headers

Important: Either of the options discussed below assume that the content is not protected, even if it requires payment to access it from within the app. Although a properly configured app will not allow unauthorized downloads, savvy users could potentially find the location of the content and access it freely through their browsers or otherwise.

Amazon S3 does not allow Basic Authentication as used by Pugpig, and will reject such requests even if the content doesn't require authorization. One option is to distribute the content of your S3 buckets via CloudFront, which will simply ignore authorization headers and provide the advantages of using a CDN. Another way around this is to use the above informal protocol as follows:

//This will strip out the Authorization field from all requests made by the KGDocumentManager.
- (void)willSendRequest:(NSMutableURLRequest*)request {
  [request setValue:nil forHTTPHeaderField:@"Authorization"];
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request


Powered by Zendesk