-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathNSMutableURLRequest+ResponseType.m
52 lines (44 loc) · 1.5 KB
/
NSMutableURLRequest+ResponseType.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// NSMutableURLRequest+ResponseType.m
// active_resource
//
// Created by James Burka on 1/19/09.
// Copyright 2009 Burkaprojects. All rights reserved.
//
#import "NSMutableURLRequest+ResponseType.h"
#import "ObjectiveResource.h"
#import "Connection.h"
@implementation NSMutableURLRequest(ResponseType)
+(NSMutableURLRequest *) requestWithUrl:(NSURL *)url andMethod:(NSString*)method {
NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:[Connection timeout]];
[request setHTTPMethod:method];
switch ([ObjectiveResourceConfig getResponseType]) {
case JSONResponse:
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request addValue:@"application/json" forHTTPHeaderField:@"Accept"];
break;
default:
[request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"];
[request addValue:@"application/xml" forHTTPHeaderField:@"Accept"];
break;
}
return request;
}
/**
Returns this request's root mime type, which can be used to override defaults,
as in the case of a request that needs to append multipart attachments
*/
- (NSString *) rootMIMEType {
NSMutableString *rootMIMEType = [NSMutableString string];
switch ([ObjectiveResourceConfig getResponseType]) {
case JSONResponse:
[rootMIMEType setString:@"application/json"];
break;
default:
[rootMIMEType setString:@"application/xml"];
break;
}
return rootMIMEType;
}
@end