PUTResponse.m 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #import "PUTResponse.h"
  2. #import "HTTPLogging.h"
  3. // HTTP methods: http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
  4. // HTTP headers: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
  5. // HTTP status codes: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
  6. static const int httpLogLevel = HTTP_LOG_LEVEL_WARN;
  7. @implementation PUTResponse
  8. - (id) initWithFilePath:(NSString*)path headers:(NSDictionary*)headers body:(id)body {
  9. if ((self = [super init])) {
  10. if ([headers objectForKey:@"Content-Range"]) {
  11. HTTPLogError(@"Content-Range not supported for upload to \"%@\"", path);
  12. _status = 400;
  13. } else {
  14. BOOL overwrite = [[NSFileManager defaultManager] fileExistsAtPath:path];
  15. BOOL success;
  16. if ([body isKindOfClass:[NSString class]]) {
  17. [[NSFileManager defaultManager] removeItemAtPath:path error:NULL];
  18. success = [[NSFileManager defaultManager] moveItemAtPath:body toPath:path error:NULL];
  19. } else {
  20. success = [body writeToFile:path atomically:YES];
  21. }
  22. if (success) {
  23. _status = overwrite ? 200 : 201;
  24. } else {
  25. HTTPLogError(@"Failed writing upload to \"%@\"", path);
  26. _status = 403;
  27. }
  28. }
  29. }
  30. return self;
  31. }
  32. - (id) initWithFilePath:(NSString*)path headers:(NSDictionary*)headers bodyData:(NSData*)body {
  33. return [self initWithFilePath:path headers:headers body:body];
  34. }
  35. - (id) initWithFilePath:(NSString*)path headers:(NSDictionary*)headers bodyFile:(NSString*)body {
  36. return [self initWithFilePath:path headers:headers body:body];
  37. }
  38. - (UInt64) contentLength {
  39. return 0;
  40. }
  41. - (UInt64) offset {
  42. return 0;
  43. }
  44. - (void) setOffset:(UInt64)offset {
  45. ;
  46. }
  47. - (NSData*) readDataOfLength:(NSUInteger)length {
  48. return nil;
  49. }
  50. - (BOOL) isDone {
  51. return YES;
  52. }
  53. - (NSInteger) status {
  54. return _status;
  55. }
  56. @end