-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPUTResponse.m
executable file
·69 lines (56 loc) · 1.79 KB
/
PUTResponse.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#import "PUTResponse.h"
#import "HTTPLogging.h"
// HTTP methods: http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
// HTTP headers: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
// HTTP status codes: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
static const int httpLogLevel = HTTP_LOG_LEVEL_WARN;
@implementation PUTResponse
- (id) initWithFilePath:(NSString*)path headers:(NSDictionary*)headers body:(id)body {
if ((self = [super init])) {
if ([headers objectForKey:@"Content-Range"]) {
HTTPLogError(@"Content-Range not supported for upload to \"%@\"", path);
_status = 400;
} else {
BOOL overwrite = [[NSFileManager defaultManager] fileExistsAtPath:path];
BOOL success;
if ([body isKindOfClass:[NSString class]]) {
[[NSFileManager defaultManager] removeItemAtPath:path error:NULL];
success = [[NSFileManager defaultManager] moveItemAtPath:body toPath:path error:NULL];
} else {
success = [body writeToFile:path atomically:YES];
}
if (success) {
_status = overwrite ? 200 : 201;
} else {
HTTPLogError(@"Failed writing upload to \"%@\"", path);
_status = 403;
}
}
}
return self;
}
- (id) initWithFilePath:(NSString*)path headers:(NSDictionary*)headers bodyData:(NSData*)body {
return [self initWithFilePath:path headers:headers body:body];
}
- (id) initWithFilePath:(NSString*)path headers:(NSDictionary*)headers bodyFile:(NSString*)body {
return [self initWithFilePath:path headers:headers body:body];
}
- (UInt64) contentLength {
return 0;
}
- (UInt64) offset {
return 0;
}
- (void) setOffset:(UInt64)offset {
;
}
- (NSData*) readDataOfLength:(NSUInteger)length {
return nil;
}
- (BOOL) isDone {
return YES;
}
- (NSInteger) status {
return _status;
}
@end