Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added HEAD requests.

  • Loading branch information...
commit 3553f9b7720925258d074bfaa30a24b908d95a92 1 parent 1b7f378
@micpringle micpringle authored
View
9 Demo/Demo/DemoViewController.m
@@ -11,6 +11,15 @@
@implementation DemoViewController
+- (void)viewDidLoad {
+
+ [SVHTTPRequest HEAD:@"https://api.github.com/repos/samvermette/SVHTTPRequest"
+ parameters:nil
+ completion:^(id response, NSHTTPURLResponse *urlResponse, NSError *error) {
+ NSString *tag = [urlResponse.allHeaderFields objectForKey:@"ETag"];
+ NSLog(@"ETag for SVHTTPRequest: %@", [tag stringByTrimmingCharactersInSet:[NSCharacterSet punctuationCharacterSet]]);
+ }];
+}
- (IBAction)watchersRequest {
View
2  SVHTTPRequest/SVHTTPClient.h
@@ -22,6 +22,8 @@
- (void)PUT:(NSString*)path parameters:(NSDictionary*)parameters completion:(void (^)(id response, NSHTTPURLResponse *urlResponse, NSError *error))completionBlock;
- (void)DELETE:(NSString*)path parameters:(NSDictionary*)parameters completion:(void (^)(id response, NSHTTPURLResponse *urlResponse, NSError *error))completionBlock;
+- (void)HEAD:(NSString*)path parameters:(NSDictionary*)parameters completion:(void (^)(id response, NSHTTPURLResponse *urlResponse, NSError *error))completionBlock;
+
- (void)cancelRequestsWithPath:(NSString*)path;
- (void)cancelAllRequests;
View
4 SVHTTPRequest/SVHTTPClient.m
@@ -86,6 +86,10 @@ - (void)DELETE:(NSString *)path parameters:(NSDictionary *)parameters completion
[self queueRequest:path method:SVHTTPRequestMethodDELETE parameters:parameters saveToPath:nil progress:nil completion:completionBlock];
}
+- (void)HEAD:(NSString *)path parameters:(NSDictionary *)parameters completion:(void (^)(id, NSHTTPURLResponse*, NSError*))completionBlock {
+ [self queueRequest:path method:SVHTTPRequestMethodHEAD parameters:parameters saveToPath:nil progress:nil completion:completionBlock];
+}
+
#pragma mark - Operation Cancelling
- (void)cancelRequestsWithPath:(NSString *)path {
View
5 SVHTTPRequest/SVHTTPRequest.h
@@ -16,7 +16,8 @@ enum {
SVHTTPRequestMethodGET = 0,
SVHTTPRequestMethodPOST,
SVHTTPRequestMethodPUT,
- SVHTTPRequestMethodDELETE
+ SVHTTPRequestMethodDELETE,
+ SVHTTPRequestMethodHEAD
};
typedef NSUInteger SVHTTPRequestMethod;
@@ -31,6 +32,8 @@ typedef NSUInteger SVHTTPRequestMethod;
+ (SVHTTPRequest*)PUT:(NSString*)address parameters:(NSDictionary*)parameters completion:(void (^)(id response, NSHTTPURLResponse *urlResponse, NSError *error))block;
+ (SVHTTPRequest*)DELETE:(NSString*)address parameters:(NSDictionary*)parameters completion:(void (^)(id response, NSHTTPURLResponse *urlResponse, NSError *error))block;
++ (SVHTTPRequest*)HEAD:(NSString*)address parameters:(NSDictionary*)parameters completion:(void (^)(id response, NSHTTPURLResponse *urlResponse, NSError *error))block;
+
- (SVHTTPRequest*)initWithAddress:(NSString*)urlString
method:(SVHTTPRequestMethod)method
parameters:(NSDictionary*)parameters
View
11 SVHTTPRequest/SVHTTPRequest.m
@@ -116,6 +116,12 @@ + (SVHTTPRequest*)DELETE:(NSString *)address parameters:(NSDictionary *)paramete
return requestObject;
}
++ (SVHTTPRequest*)HEAD:(NSString *)address parameters:(NSDictionary *)parameters completion:(void (^)(id, NSHTTPURLResponse *, NSError *))block {
+ SVHTTPRequest *requestObject = [[self alloc] initWithAddress:address method:SVHTTPRequestMethodHEAD parameters:parameters saveToPath:nil progress:nil completion:block];
+ [requestObject start];
+
+ return requestObject;
+}
#pragma mark -
@@ -143,7 +149,8 @@ - (SVHTTPRequest*)initWithAddress:(NSString*)urlString method:(SVHTTPRequestMeth
[self.operationRequest setHTTPMethod:@"PUT"];
else if(method == SVHTTPRequestMethodDELETE)
[self.operationRequest setHTTPMethod:@"DELETE"];
-
+ else if(method == SVHTTPRequestMethodHEAD)
+ [self.operationRequest setHTTPMethod:@"HEAD"];
self.state = SVHTTPRequestStateReady;
return self;
@@ -191,7 +198,7 @@ - (void)addParametersToRequest:(NSDictionary*)paramsDict {
NSString *parameterString = [stringParameters componentsJoinedByString:@"&"];
- if([method isEqualToString:@"GET"]) {
+ if([method isEqualToString:@"GET"] || [method isEqualToString:@"HEAD"]) {
NSString *baseAddress = self.operationRequest.URL.absoluteString;
baseAddress = [baseAddress stringByAppendingFormat:@"?%@", [stringParameters componentsJoinedByString:@"&"]];
[self.operationRequest setURL:[NSURL URLWithString:baseAddress]];
Please sign in to comment.
Something went wrong with that request. Please try again.