酷店

TBSDKURLConnectionOperation.h 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // NWURLConnectionOperation.h
  3. // ALINetworkSDK
  4. //
  5. // Created by Roger.Mu on 5/11/15.
  6. // Copyright (c) 2015 Taobao.com. All rights reserved.
  7. //
  8. typedef NS_ENUM(NSInteger, AFOperationState) {
  9. TBSDKOperationPausedState = -1,
  10. TBSDKOperationReadyState = 1,
  11. TBSDKOperationExecutingState = 2,
  12. TBSDKOperationFinishedState = 3,
  13. };
  14. typedef NSURLRequest *(^TBSDKURLConnectionOperationRedirectResponseBlock)(NSURLConnection *connection, NSURLRequest *request, NSURLResponse *redirectResponse);
  15. @interface TBSDKURLConnectionOperation : NSOperation <NSURLConnectionDelegate, NSURLConnectionDataDelegate, NSCopying>
  16. // properties
  17. @property (readonly, nonatomic, strong) NSURLRequest *request;
  18. @property (readonly, nonatomic, strong) NSURLResponse *response;
  19. @property (readonly, nonatomic, strong) NSData *responseData;
  20. @property (nonatomic, copy) NSString *responseString;
  21. @property (nonatomic, strong) NSError *error;
  22. @property (nonatomic, assign) NSStringEncoding responseStringEncoding;
  23. @property (readwrite, nonatomic, assign) long long totalBytesRead;
  24. @property (nonatomic, strong) NSURLConnection *connection;
  25. @property (nonatomic, strong) NSRecursiveLock *lock;
  26. @property (nonatomic, strong) NSOutputStream *outputStream;
  27. @property (nonatomic, strong) NSSet *runLoopModes;
  28. @property (nonatomic, assign) AFOperationState state;
  29. // block methods poperty
  30. @property (readwrite, nonatomic, copy) TBSDKURLConnectionOperationRedirectResponseBlock redirectResponse;
  31. // upload and download process
  32. @property (readwrite, nonatomic, copy) void (^uploadProgress)(NSUInteger bytes, long long totalBytes, long long totalBytesExpected);
  33. @property (readwrite, nonatomic, copy) void (^downloadProgress)(NSUInteger bytes, long long totalBytes, long long totalBytesExpected);
  34. // methods
  35. -(instancetype) initWithRequest: (NSURLRequest *) urlRequest;
  36. // block methods
  37. - (void)setUploadProgressBlock:(void (^)(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite))block;
  38. - (void)setDownloadProgressBlock:(void (^)(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead))block;
  39. - (void)setRedirectResponseBlock:(NSURLRequest * (^)(NSURLConnection *connection, NSURLRequest *request, NSURLResponse *redirectResponse))block;
  40. //由于NSURLProtocol有限制,didReceiveResponse方法在内部第二次重试的时候不会收到,因此这里手动通知
  41. - (void)connection:(NSURLConnection __unused *)connection didReceiveResponseWhenEncounterError:(NSURLResponse *)response;
  42. @end
  43. @interface TBSDKRequestDelegate : NSObject
  44. @property (nonatomic, weak) TBSDKURLConnectionOperation *weakConnection;
  45. @end