Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RestKit 0.20.0pre5: HTTP headers per request

i want to send an If-Modified-Since http header with a GET request, issued by [RKObjectManager getObjectsAtPath:...].

the migration guide tells that i can set only "global" default request headers for an RKObjectManager instance:

RKObjectManager* objectManager = [RKObjectManager managerWithBaseURLString:url];
[objectManager.HTTPClient setDefaultHeader:@"If-Modified-Since" value:@"Sat, 29 Dec 2012 19:43:31 GMT"];

since i want to keep a centralized RKObjetManager instance (via [RKObjectManager sharedManaged]), this is not really a good option.

is creating a specific RKObjectManager before each request and set my http headers as "default" the only solution or is there a better way?

like image 248
manu Avatar asked Dec 06 '22 10:12

manu


1 Answers

There are a few options here:

  1. Obtain an NSURLRequest object using requestWithObject:method:path:parameters:, configure the NSURLRequest appropriately, and then invoke objectRequestOperationWithRequest:success:failure: or managedObjectRequestOperationWithRequest:managedObjectContext:success:failure:. This will let you configure the requests on a one-off basis.
  2. Configure a custom subclass of RKHTTPRequestOperation via setHTTPOperationClass: on RKObjectManager. This will let you hook subclass in that can configure every NSURLRequest as the object manager makes requests, letting you centralize the configuration.
  3. On the latest development branch, you can also register a subclass of RKObjectRequestOperation with the manager that will be used for requests of your choosing, enabling you to centralize customization at the object request operation level.

Options 1 or 2 are probably most appropriate for the HTTP level concern you outline, but I mention as an alternative for doing the same sort of customization at the object mapping level.

like image 52
Blake Watters Avatar answered Jan 31 '23 09:01

Blake Watters