HTTPResponseProxy.m 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #import "HTTPResponseProxy.h"
  2. #pragma clang diagnostic ignored "-Wdirect-ivar-access"
  3. @implementation HTTPResponseProxy
  4. @synthesize response;
  5. @synthesize status;
  6. - (NSInteger)status {
  7. if (status != 0) {
  8. return status;
  9. } else if ([response respondsToSelector:@selector(status)]) {
  10. return [response status];
  11. }
  12. return 200;
  13. }
  14. - (void)setStatus:(NSInteger)statusCode {
  15. status = statusCode;
  16. }
  17. - (NSInteger)customStatus {
  18. return status;
  19. }
  20. // Implement the required HTTPResponse methods
  21. - (UInt64)contentLength {
  22. if (response) {
  23. return [response contentLength];
  24. } else {
  25. return 0;
  26. }
  27. }
  28. - (UInt64)offset {
  29. if (response) {
  30. return [response offset];
  31. } else {
  32. return 0;
  33. }
  34. }
  35. - (void)setOffset:(UInt64)offset {
  36. if (response) {
  37. [response setOffset:offset];
  38. }
  39. }
  40. - (NSData *)readDataOfLength:(NSUInteger)length {
  41. if (response) {
  42. return [response readDataOfLength:length];
  43. } else {
  44. return nil;
  45. }
  46. }
  47. - (BOOL)isDone {
  48. if (response) {
  49. return [response isDone];
  50. } else {
  51. return YES;
  52. }
  53. }
  54. // Forward all other invocations to the actual response object
  55. - (void)forwardInvocation:(NSInvocation *)invocation {
  56. if ([response respondsToSelector:[invocation selector]]) {
  57. [invocation invokeWithTarget:response];
  58. } else {
  59. [super forwardInvocation:invocation];
  60. }
  61. }
  62. - (BOOL)respondsToSelector:(SEL)selector {
  63. if ([super respondsToSelector:selector])
  64. return YES;
  65. return [response respondsToSelector:selector];
  66. }
  67. @end