Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support custom headers for client

  • Loading branch information...
commit 39e84dd08d85b15c3fc9a2f5e6d6fe08195497a6 1 parent ff249aa
Sebastian Rehnby sebreh authored
2  PodioKit/Core/PKTClient.h
View
@@ -19,6 +19,8 @@ typedef void(^PKTRequestCompletionBlock)(PKTResponse *response, NSError *error);
- (instancetype)initWithAPIKey:(NSString *)key secret:(NSString *)secret;
+- (void)setValue:(NSString *)value forHTTPHeader:(NSString *)header;
+
- (void)performRequest:(PKTRequest *)request completion:(PKTRequestCompletionBlock)completion;
@end
4 PodioKit/Core/PKTClient.m
View
@@ -45,6 +45,10 @@ - (instancetype)initWithAPIKey:(NSString *)key secret:(NSString *)secret {
#pragma mark - Public
+- (void)setValue:(NSString *)value forHTTPHeader:(NSString *)header {
+ [self.requestSerializer setValue:value forHTTPHeaderField:header];
+}
+
- (void)performRequest:(PKTRequest *)request completion:(PKTRequestCompletionBlock)completion {
NSURLSessionTask *task = [self taskWithRequest:request completion:completion];
[task resume];
8 PodioKitTests/PKTClientTests.m
View
@@ -112,4 +112,12 @@ - (void)testURLRequestForDELETERequest {
expect([[urlRequest allHTTPHeaderFields][@"X-Podio-Request-Id"] length]).to.beGreaterThan(0);
}
+- (void)testSetCustomHeader {
+ PKTRequest *request = [PKTRequest PUTRequestWithPath:@"/some/path" parameters:nil];
+
+ [self.testClient setValue:@"Header value" forHTTPHeader:@"X-Test-Header"];
+ NSURLRequest *urlRequest = [self.testClient URLRequestForRequest:request];
+ expect([urlRequest allHTTPHeaderFields][@"X-Test-Header"]).to.equal(@"Header value");
+}
+
@end
Please sign in to comment.
Something went wrong with that request. Please try again.