Created
October 22, 2010 15:35
-
-
Save mxcl/640774 to your computer and use it in GitHub Desktop.
NSURLRequest+mxcl.m
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
#import <Foundation/Foundation.h> | |
@interface NSURLRequest (mxcl) | |
+ (id)requestWithURL:(NSURL *)url; | |
+ (id)requestWithURL:(NSURL *)url cachePolicy:(NSURLRequestCachePolicy)cachePolicy timeoutInterval:(NSTimeInterval)timeoutInterval; | |
+ (id)requestWithURLString:(NSString *)url; // for convenience | |
@end | |
@interface NSMutableURLRequest (mxcl) | |
- (id)init; | |
@end | |
@implementation NSMutableURLRequest (mxcl) | |
- (id)init { | |
self = [super init]; //TODO we need to call the pre-category version! | |
if (self) { | |
[self setValue:TDUserAgent forHTTPHeaderField:@"User-Agent"]; | |
[self setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"]; | |
} | |
return self; | |
} | |
@end | |
@implementation NSURLRequest (mxcl) | |
+ (id)requestWithURL:(NSURL *)url { | |
NSMutableURLRequest *rq = [NSMutableURLRequest new]; | |
rq.URL = url; | |
rq.cachePolicy = NSURLRequestUseProtocolCachePolicy; | |
rq.timeoutInterval = TDURLRequestWebServiceTimeout; | |
return [rq autorelease]; | |
} | |
+ (id)requestWithURL:(NSURL *)url cachePolicy:(NSURLRequestCachePolicy)cachePolicy timeoutInterval:(NSTimeInterval)timeoutInterval { | |
NSMutableURLRequest *rq = [NSMutableURLRequest new]; | |
rq.URL = url; | |
rq.cachePolicy = NSURLRequestUseProtocolCachePolicy; | |
rq.timeoutInterval = TDURLRequestWebServiceTimeout; | |
return [rq autorelease]; | |
} | |
+ (id)requestWithURLString:(NSString *)url { | |
return [NSURLRequest requestWithURL:[NSURL URLWithString:url]]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment