123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386 |
- #import <Foundation/Foundation.h>
- #if TARGET_OS_IPHONE
- #import <UIKit/UIKit.h>
- #endif
- #if TARGET_OS_WATCH
- #import <WatchKit/WatchKit.h>
- #endif
- #ifndef STRIP_GTM_FETCH_LOGGING
- #if !DEBUG
- #define STRIP_GTM_FETCH_LOGGING 1
- #else
- #define STRIP_GTM_FETCH_LOGGING 0
- #endif
- #endif
- #ifndef GTMSESSION_LOG_DEBUG
- #if DEBUG
- #define GTMSESSION_LOG_DEBUG(...) NSLog(__VA_ARGS__)
- #else
- #define GTMSESSION_LOG_DEBUG(...) \
- do { \
- } while (0)
- #endif
- #endif
- #ifndef GTMSESSION_ASSERT_DEBUG
- #if DEBUG && !defined(NS_BLOCK_ASSERTIONS) && !GTMSESSION_ASSERT_AS_LOG
- #undef GTMSESSION_ASSERT_AS_LOG
- #define GTMSESSION_ASSERT_AS_LOG 1
- #endif
- #if DEBUG && !GTMSESSION_ASSERT_AS_LOG
- #define GTMSESSION_ASSERT_DEBUG(...) NSAssert(__VA_ARGS__)
- #elif DEBUG
- #define GTMSESSION_ASSERT_DEBUG(pred, ...) \
- if (!(pred)) { \
- NSLog(__VA_ARGS__); \
- }
- #else
- #define GTMSESSION_ASSERT_DEBUG(pred, ...) \
- do { \
- } while (0)
- #endif
- #endif
- #ifndef GTMSESSION_ASSERT_DEBUG_OR_LOG
- #if DEBUG && !GTMSESSION_ASSERT_AS_LOG
- #define GTMSESSION_ASSERT_DEBUG_OR_LOG(...) NSAssert(__VA_ARGS__)
- #else
- #define GTMSESSION_ASSERT_DEBUG_OR_LOG(pred, ...) \
- if (!(pred)) { \
- NSLog(__VA_ARGS__); \
- }
- #endif
- #endif
- #if 0
- #define GTM_LOG_SESSION_DELEGATE(...) GTMSESSION_LOG_DEBUG(__VA_ARGS__)
- #else
- #define GTM_LOG_SESSION_DELEGATE(...)
- #endif
- #ifndef GTM_NULLABLE
- #if __has_feature(nullability)
- #define GTM_NULLABLE_TYPE __nullable
- #define GTM_NONNULL_TYPE __nonnull
- #define GTM_NULLABLE nullable
- #define GTM_NONNULL_DECL nonnull
- #define GTM_NULL_RESETTABLE null_resettable
- #define GTM_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
- #define GTM_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
- #else
- #define GTM_NULLABLE_TYPE
- #define GTM_NONNULL_TYPE
- #define GTM_NULLABLE
- #define GTM_NONNULL_DECL
- #define GTM_NULL_RESETTABLE
- #define GTM_ASSUME_NONNULL_BEGIN
- #define GTM_ASSUME_NONNULL_END
- #endif
- #endif
- #ifndef GTM_DECLARE_GENERICS
- #if __has_feature(objc_generics)
- #define GTM_DECLARE_GENERICS 1
- #else
- #define GTM_DECLARE_GENERICS 0
- #endif
- #endif
- #ifndef GTM_NSArrayOf
- #if GTM_DECLARE_GENERICS
- #define GTM_NSArrayOf(value) NSArray<value>
- #define GTM_NSDictionaryOf(key, value) NSDictionary<key, value>
- #else
- #define GTM_NSArrayOf(value) NSArray
- #define GTM_NSDictionaryOf(key, value) NSDictionary
- #endif
- #endif
- #if !defined(GTM_BACKGROUND_TASK_FETCHING) && \
- (TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_MACCATALYST)
- #define GTM_BACKGROUND_TASK_FETCHING 1
- #endif
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if !defined(GTMBridgeFetcher)
- #define GTMBridgeFetcher GTMSessionFetcher
- #define GTMBridgeFetcherService GTMSessionFetcherService
- #define GTMBridgeFetcherServiceProtocol GTMSessionFetcherServiceProtocol
- #define GTMBridgeAssertValidSelector GTMSessionFetcherAssertValidSelector
- #define GTMBridgeCookieStorage GTMSessionCookieStorage
- #define GTMBridgeCleanedUserAgentString GTMFetcherCleanedUserAgentString
- #define GTMBridgeSystemVersionString GTMFetcherSystemVersionString
- #define GTMBridgeApplicationIdentifier GTMFetcherApplicationIdentifier
- #define kGTMBridgeFetcherStatusDomain kGTMSessionFetcherStatusDomain
- #define kGTMBridgeFetcherStatusBadRequest GTMSessionFetcherStatusBadRequest
- #endif
- #ifndef GTMSESSION_RECONNECT_BACKGROUND_SESSIONS_ON_LAUNCH
- #if TARGET_OS_IOS && defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
- #define GTMSESSION_RECONNECT_BACKGROUND_SESSIONS_ON_LAUNCH 1
- #else
- #define GTMSESSION_RECONNECT_BACKGROUND_SESSIONS_ON_LAUNCH 0
- #endif
- #endif
- NS_ASSUME_NONNULL_BEGIN
- extern NSString *const kGTMSessionFetcherStartedNotification;
- extern NSString *const kGTMSessionFetcherStoppedNotification;
- extern NSString *const kGTMSessionFetcherRetryDelayStartedNotification;
- extern NSString *const kGTMSessionFetcherRetryDelayStoppedNotification;
- extern NSString *const kGTMSessionFetcherCompletionInvokedNotification;
- extern NSString *const kGTMSessionFetcherCompletionDataKey;
- extern NSString *const kGTMSessionFetcherCompletionErrorKey;
- extern NSString *const kGTMSessionFetcherErrorDomain;
- extern NSString *const kGTMSessionFetcherStatusDomain;
- extern NSString *const kGTMSessionFetcherStatusDataKey;
- extern NSString *const kGTMSessionFetcherStatusDataContentTypeKey;
- extern NSString *const kGTMSessionFetcherNumberOfRetriesDoneKey;
- extern NSString *const kGTMSessionFetcherElapsedIntervalWithRetriesKey;
- @interface GTMSessionFetcherUserDefaultsFactory : NSObject
- + (NSUserDefaults *)fetcherUserDefaults;
- @end
- #ifdef __cplusplus
- }
- #endif
- typedef NS_ENUM(NSInteger, GTMSessionFetcherError) {
- GTMSessionFetcherErrorDownloadFailed = -1,
- GTMSessionFetcherErrorUploadChunkUnavailable = -2,
- GTMSessionFetcherErrorBackgroundExpiration = -3,
- GTMSessionFetcherErrorBackgroundFetchFailed = -4,
- GTMSessionFetcherErrorInsecureRequest = -5,
- GTMSessionFetcherErrorTaskCreationFailed = -6,
- };
- typedef NS_ENUM(NSInteger, GTMSessionFetcherStatus) {
-
- GTMSessionFetcherStatusNotModified = 304,
- GTMSessionFetcherStatusBadRequest = 400,
- GTMSessionFetcherStatusUnauthorized = 401,
- GTMSessionFetcherStatusForbidden = 403,
- GTMSessionFetcherStatusPreconditionFailed = 412
- };
- #ifdef __cplusplus
- extern "C" {
- #endif
- @class GTMSessionCookieStorage;
- @class GTMSessionFetcher;
- typedef void (^GTMSessionFetcherConfigurationBlock)(GTMSessionFetcher *fetcher,
- NSURLSessionConfiguration *configuration);
- typedef void (^GTMSessionFetcherSystemCompletionHandler)(void);
- typedef void (^GTMSessionFetcherCompletionHandler)(NSData *_Nullable data,
- NSError *_Nullable error);
- typedef void (^GTMSessionFetcherBodyStreamProviderResponse)(NSInputStream *bodyStream);
- typedef void (^GTMSessionFetcherBodyStreamProvider)(
- GTMSessionFetcherBodyStreamProviderResponse response);
- typedef void (^GTMSessionFetcherDidReceiveResponseDispositionBlock)(
- NSURLSessionResponseDisposition disposition);
- typedef void (^GTMSessionFetcherDidReceiveResponseBlock)(
- NSURLResponse *response, GTMSessionFetcherDidReceiveResponseDispositionBlock dispositionBlock);
- typedef void (^GTMSessionFetcherChallengeDispositionBlock)(
- NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *_Nullable credential);
- typedef void (^GTMSessionFetcherChallengeBlock)(
- GTMSessionFetcher *fetcher, NSURLAuthenticationChallenge *challenge,
- GTMSessionFetcherChallengeDispositionBlock dispositionBlock);
- typedef void (^GTMSessionFetcherWillRedirectResponse)(NSURLRequest *_Nullable redirectedRequest);
- typedef void (^GTMSessionFetcherWillRedirectBlock)(NSHTTPURLResponse *redirectResponse,
- NSURLRequest *redirectRequest,
- GTMSessionFetcherWillRedirectResponse response);
- typedef void (^GTMSessionFetcherAccumulateDataBlock)(NSData *_Nullable buffer);
- typedef void (^GTMSessionFetcherSimulateByteTransferBlock)(NSData *_Nullable buffer,
- int64_t bytesWritten,
- int64_t totalBytesWritten,
- int64_t totalBytesExpectedToWrite);
- typedef void (^GTMSessionFetcherReceivedProgressBlock)(int64_t bytesWritten,
- int64_t totalBytesWritten);
- typedef void (^GTMSessionFetcherDownloadProgressBlock)(int64_t bytesWritten,
- int64_t totalBytesWritten,
- int64_t totalBytesExpectedToWrite);
- typedef void (^GTMSessionFetcherSendProgressBlock)(int64_t bytesSent, int64_t totalBytesSent,
- int64_t totalBytesExpectedToSend);
- typedef void (^GTMSessionFetcherWillCacheURLResponseResponse)(
- NSCachedURLResponse *_Nullable cachedResponse);
- typedef void (^GTMSessionFetcherWillCacheURLResponseBlock)(
- NSCachedURLResponse *proposedResponse,
- GTMSessionFetcherWillCacheURLResponseResponse responseBlock);
- typedef void (^GTMSessionFetcherRetryResponse)(BOOL shouldRetry);
- typedef void (^GTMSessionFetcherRetryBlock)(BOOL suggestedWillRetry, NSError *_Nullable error,
- GTMSessionFetcherRetryResponse response);
- API_AVAILABLE(ios(10.0), macosx(10.12), tvos(10.0), watchos(6.0))
- typedef void (^GTMSessionFetcherMetricsCollectionBlock)(NSURLSessionTaskMetrics *metrics);
- typedef void (^GTMSessionFetcherTestResponse)(NSHTTPURLResponse *_Nullable response,
- NSData *_Nullable data, NSError *_Nullable error);
- typedef void (^GTMSessionFetcherTestBlock)(GTMSessionFetcher *fetcherToTest,
- GTMSessionFetcherTestResponse testResponse);
- void GTMSessionFetcherAssertValidSelector(id _Nullable obj, SEL _Nullable sel, ...);
- NSString *GTMFetcherStandardUserAgentString(NSBundle *_Nullable bundle);
- NSString *GTMFetcherApplicationIdentifier(NSBundle *_Nullable bundle);
- NSString *GTMFetcherSystemVersionString(void);
- NSString *GTMFetcherCleanedUserAgentString(NSString *str);
- NSData *_Nullable GTMDataFromInputStream(NSInputStream *inputStream, NSError **outError);
- #ifdef __cplusplus
- }
- #endif
- typedef void (^GTMFetcherDecoratorFetcherWillStartCompletionHandler)(NSURLRequest *_Nullable,
- NSError *_Nullable);
- @protocol GTMFetcherDecoratorProtocol <NSObject>
- - (void)fetcherWillStart:(GTMSessionFetcher *)fetcher
- completionHandler:(GTMFetcherDecoratorFetcherWillStartCompletionHandler)handler;
- - (void)fetcherDidFinish:(GTMSessionFetcher *)fetcher
- withData:(nullable NSData *)data
- error:(nullable NSError *)error
- completionHandler:(void (^)(void))handler;
- @end
- @protocol GTMSessionFetcherServiceProtocol <NSObject>
- @property(atomic, strong) dispatch_queue_t callbackQueue;
- - (BOOL)fetcherShouldBeginFetching:(GTMSessionFetcher *)fetcher;
- - (void)fetcherDidCreateSession:(GTMSessionFetcher *)fetcher;
- - (void)fetcherDidBeginFetching:(GTMSessionFetcher *)fetcher;
- - (void)fetcherDidStop:(GTMSessionFetcher *)fetcher;
- - (GTMSessionFetcher *)fetcherWithRequest:(NSURLRequest *)request;
- - (BOOL)isDelayingFetcher:(GTMSessionFetcher *)fetcher;
- @property(atomic, assign) BOOL reuseSession;
- - (nullable NSURLSession *)session;
- - (nullable NSURLSession *)sessionForFetcherCreation;
- - (nullable id<NSURLSessionDelegate>)sessionDelegate;
- - (nullable NSDate *)stoppedAllFetchersDate;
- @property(atomic, readonly, strong, nullable) NSOperationQueue *delegateQueue;
- @optional
- @property(atomic, readonly, strong, nullable) NSArray<id<GTMFetcherDecoratorProtocol>> *decorators;
- @end
- #ifndef GTM_FETCHER_AUTHORIZATION_PROTOCOL
- #define GTM_FETCHER_AUTHORIZATION_PROTOCOL 1
- @protocol GTMFetcherAuthorizationProtocol <NSObject>
- @required
- - (void)authorizeRequest:(nullable NSMutableURLRequest *)request
- delegate:(id)delegate
- didFinishSelector:(SEL)sel;
- - (void)stopAuthorization;
- - (void)stopAuthorizationForRequest:(NSURLRequest *)request;
- - (BOOL)isAuthorizingRequest:(NSURLRequest *)request;
- - (BOOL)isAuthorizedRequest:(NSURLRequest *)request;
- @property(atomic, strong, readonly, nullable) NSString *userEmail;
- @optional
- @property(atomic, readonly) BOOL canAuthorize;
- @property(atomic, assign) BOOL shouldAuthorizeAllRequests;
- - (void)authorizeRequest:(nullable NSMutableURLRequest *)request
- completionHandler:(void (^)(NSError *_Nullable error))handler;
- @property(atomic, weak, nullable) id<GTMSessionFetcherServiceProtocol> fetcherService;
- - (BOOL)primeForRefresh;
- @end
- #endif
- #if GTM_BACKGROUND_TASK_FETCHING
- @protocol GTMUIApplicationProtocol <NSObject>
- - (UIBackgroundTaskIdentifier)beginBackgroundTaskWithName:(nullable NSString *)taskName
- expirationHandler:(void (^__nullable)(void))handler;
- - (void)endBackgroundTask:(UIBackgroundTaskIdentifier)identifier;
- @end
- #endif
- #pragma mark -
- @interface GTMSessionFetcher : NSObject <NSURLSessionDelegate>
- + (instancetype)fetcherWithRequest:(nullable NSURLRequest *)request;
- + (instancetype)fetcherWithURL:(NSURL *)requestURL;
- + (instancetype)fetcherWithURLString:(NSString *)requestURLString;
- + (instancetype)fetcherWithDownloadResumeData:(NSData *)resumeData;
- + (nullable instancetype)fetcherWithSessionIdentifier:(NSString *)sessionIdentifier;
- + (NSArray<GTMSessionFetcher *> *)fetchersForBackgroundSessions;
- - (instancetype)initWithRequest:(nullable NSURLRequest *)request
- configuration:(nullable NSURLSessionConfiguration *)configuration;
- @property(atomic, strong, nullable) NSURLRequest *request;
- - (void)setRequestValue:(nullable NSString *)value forHTTPHeaderField:(NSString *)field;
- @property(atomic, readonly, nullable) NSData *downloadResumeData;
- @property(atomic, strong, nullable) NSURLSessionConfiguration *configuration;
- @property(atomic, copy, nullable) GTMSessionFetcherConfigurationBlock configurationBlock;
- @property(atomic, strong, nullable) NSURLSession *session;
- @property(atomic, readonly, nullable) NSURLSessionTask *sessionTask;
- @property(atomic, readonly, nullable) NSString *sessionIdentifier;
- @property(atomic, readonly) BOOL wasCreatedFromBackgroundSession;
- @property(atomic, assign) BOOL clientWillReconnectBackgroundSession;
- @property(atomic, strong, nullable) NSDictionary<NSString *, NSString *> *sessionUserInfo;
- @property(atomic, copy, nullable) NSString *taskDescription;
- @property(atomic, assign) float taskPriority;
- - (nullable NSDictionary<NSString *, NSString *> *)sessionIdentifierMetadata;
- #if TARGET_OS_IPHONE && !TARGET_OS_WATCH
- + (void)application:(UIApplication *)application
- handleEventsForBackgroundURLSession:(NSString *)identifier
- completionHandler:(GTMSessionFetcherSystemCompletionHandler)completionHandler;
- #endif
- @property(atomic, assign) BOOL useBackgroundSession;
- @property(atomic, readonly, getter=isUsingBackgroundSession) BOOL usingBackgroundSession;
- @property(atomic, assign) BOOL useUploadTask;
- @property(atomic, readonly) BOOL canShareSession;
- @property(atomic, copy, nullable) NSArray<NSString *> *allowedInsecureSchemes;
- @property(atomic, assign) BOOL allowLocalhostRequest;
- @property(atomic, assign) BOOL allowInvalidServerCertificates;
- @property(atomic, strong, nullable) NSHTTPCookieStorage *cookieStorage;
- @property(atomic, strong, nullable) NSURLCredential *credential;
- @property(atomic, strong, nullable) NSURLCredential *proxyCredential;
- @property(atomic, strong, nullable) NSData *bodyData;
- @property(atomic, strong, nullable) NSURL *bodyFileURL;
- @property(atomic, readonly) int64_t bodyLength;
- @property(atomic, copy, nullable) GTMSessionFetcherBodyStreamProvider bodyStreamProvider;
- @property(atomic, strong, nullable) id<GTMFetcherAuthorizationProtocol> authorizer;
- @property(atomic, strong) id<GTMSessionFetcherServiceProtocol> service;
- @property(atomic, copy, nullable) NSString *serviceHost;
- @property(atomic, assign) NSInteger servicePriority;
- @property(atomic, copy, nullable) GTMSessionFetcherDidReceiveResponseBlock didReceiveResponseBlock;
- @property(atomic, copy, nullable) GTMSessionFetcherChallengeBlock challengeBlock;
- @property(atomic, copy, nullable) GTMSessionFetcherWillRedirectBlock willRedirectBlock;
- @property(atomic, copy, nullable) GTMSessionFetcherSendProgressBlock sendProgressBlock;
- @property(atomic, copy, nullable) GTMSessionFetcherAccumulateDataBlock accumulateDataBlock;
- @property(atomic, copy, nullable) GTMSessionFetcherReceivedProgressBlock receivedProgressBlock;
- @property(atomic, copy, nullable) GTMSessionFetcherDownloadProgressBlock downloadProgressBlock;
- @property(atomic, copy, nullable)
- GTMSessionFetcherWillCacheURLResponseBlock willCacheURLResponseBlock;
- @property(atomic, assign, getter=isRetryEnabled) BOOL retryEnabled;
- @property(atomic, copy, nullable) GTMSessionFetcherRetryBlock retryBlock;
- @property(atomic, copy, nullable)
- GTMSessionFetcherMetricsCollectionBlock metricsCollectionBlock API_AVAILABLE(
- ios(10.0), macosx(10.12), tvos(10.0), watchos(6.0));
- @property(atomic, assign) NSTimeInterval maxRetryInterval;
- @property(atomic, assign) NSTimeInterval minRetryInterval;
- @property(atomic, assign) double retryFactor;
- @property(atomic, readonly) NSUInteger retryCount;
- @property(atomic, readonly) NSTimeInterval nextRetryInterval;
- #if GTM_BACKGROUND_TASK_FETCHING
- @property(atomic, assign) BOOL skipBackgroundTask;
- #endif
- - (void)beginFetchWithDelegate:(nullable id)delegate didFinishSelector:(nullable SEL)finishedSEL;
- - (void)beginFetchWithCompletionHandler:(nullable GTMSessionFetcherCompletionHandler)handler;
- @property(atomic, readonly, getter=isFetching) BOOL fetching;
- - (void)stopFetching;
- @property(atomic, copy, nullable) GTMSessionFetcherCompletionHandler completionHandler;
- @property(atomic, strong, nullable) void (^resumeDataBlock)(NSData *);
- @property(atomic, readonly) NSInteger statusCode;
- @property(atomic, strong, readonly, nullable) NSDictionary<NSString *, NSString *> *responseHeaders;
- @property(atomic, strong, readonly, nullable) NSURLResponse *response;
- @property(atomic, readonly) int64_t downloadedLength;
- @property(atomic, readonly, strong, nullable) NSData *downloadedData;
- @property(atomic, strong, nullable) NSURL *destinationFileURL;
- @property(atomic, strong, readonly, nullable) NSDate *initialBeginFetchDate;
- @property(atomic, strong, nullable) id userData;
- @property(atomic, copy, nullable) NSDictionary<NSString *, id> *properties;
- - (void)setProperty:(nullable id)obj
- forKey:(NSString *)key;
- - (nullable id)propertyForKey:(NSString *)key;
- - (void)addPropertiesFromDictionary:(NSDictionary<NSString *, id> *)dict;
- @property(atomic, copy, nullable) NSString *comment;
- - (void)setCommentWithFormat:(NSString *)format, ... NS_FORMAT_FUNCTION(1, 2);
- @property(atomic, copy, nullable) NSString *log;
- @property(atomic, strong, null_resettable) dispatch_queue_t callbackQueue;
- @property(atomic, strong, null_resettable) NSOperationQueue *sessionDelegateQueue;
- - (BOOL)waitForCompletionWithTimeout:(NSTimeInterval)timeoutInSeconds
- __deprecated_msg("Use XCTestExpectation instead");
- @property(atomic, copy, nullable) GTMSessionFetcherTestBlock testBlock;
- + (void)setGlobalTestBlock:(nullable GTMSessionFetcherTestBlock)block;
- @property(atomic, readwrite) NSUInteger testBlockAccumulateDataChunkCount;
- #if GTM_BACKGROUND_TASK_FETCHING
- + (void)setSubstituteUIApplication:(nullable id<GTMUIApplicationProtocol>)substituteUIApplication;
- + (nullable id<GTMUIApplicationProtocol>)substituteUIApplication;
- #endif
- + (GTMSessionCookieStorage *)staticCookieStorage;
- + (BOOL)appAllowsInsecureRequests;
- #if STRIP_GTM_FETCH_LOGGING
- + (void)setLoggingEnabled:(BOOL)flag;
- + (BOOL)isLoggingEnabled;
- #else
- @property(atomic, copy, nullable) NSString *logRequestBody;
- @property(atomic, assign) BOOL deferResponseBodyLogging;
- @property(atomic, copy, nullable) NSString *logResponseBody;
- @property(atomic, readonly) NSData *loggedStreamData;
- @property(atomic, assign) BOOL hasLoggedError;
- @property(atomic, strong, nullable) NSURL *redirectedFromURL;
- - (void)appendLoggedStreamData:(NSData *)dataToAdd;
- - (void)clearLoggedStreamData;
- #endif
- @end
- @interface GTMSessionFetcher (BackwardsCompatibilityOnly)
- - (void)setCookieStorageMethod:(NSInteger)method
- __deprecated_msg("Create an NSHTTPCookieStorage and set .cookieStorage directly.");
- @end
- @interface GTMSessionCookieStorage : NSHTTPCookieStorage
- - (void)setCookies:(nullable NSArray<NSHTTPCookie *> *)cookies;
- - (void)removeAllCookies;
- @end
- #ifdef __OBJC__
- #if DEBUG && (!defined(NS_BLOCK_ASSERTIONS) || GTMSESSION_ASSERT_AS_LOG)
- #define __GTMSessionMonitorSynchronizedVariableInner(varname, counter) varname##counter
- #define __GTMSessionMonitorSynchronizedVariable(varname, counter) \
- __GTMSessionMonitorSynchronizedVariableInner(varname, counter)
- #define GTMSessionMonitorSynchronized(obj) \
- NS_VALID_UNTIL_END_OF_SCOPE id __GTMSessionMonitorSynchronizedVariable(__monitor, __COUNTER__) = \
- [[GTMSessionSyncMonitorInternal alloc] initWithSynchronizationObject:obj \
- allowRecursive:NO \
- functionName:__func__]
- #define GTMSessionMonitorRecursiveSynchronized(obj) \
- NS_VALID_UNTIL_END_OF_SCOPE id __GTMSessionMonitorSynchronizedVariable(__monitor, __COUNTER__) = \
- [[GTMSessionSyncMonitorInternal alloc] initWithSynchronizationObject:obj \
- allowRecursive:YES \
- functionName:__func__]
- #define GTMSessionCheckSynchronized(obj) \
- { \
- GTMSESSION_ASSERT_DEBUG( \
- [GTMSessionSyncMonitorInternal functionsHoldingSynchronizationOnObject:obj], \
- @"GTMSessionCheckSynchronized(" #obj ") failed: not sync'd" \
- @" on " #obj " in %s. Call stack:\n%@", \
- __func__, [NSThread callStackSymbols]); \
- }
- #define GTMSessionCheckNotSynchronized(obj) \
- { \
- GTMSESSION_ASSERT_DEBUG( \
- ![GTMSessionSyncMonitorInternal functionsHoldingSynchronizationOnObject:obj], \
- @"GTMSessionCheckNotSynchronized(" #obj ") failed: was sync'd" \
- @" on " #obj " in %s by %@. Call stack:\n%@", \
- __func__, [GTMSessionSyncMonitorInternal functionsHoldingSynchronizationOnObject:obj], \
- [NSThread callStackSymbols]); \
- }
- @interface GTMSessionSyncMonitorInternal : NSObject
- - (instancetype)initWithSynchronizationObject:(id)object
- allowRecursive:(BOOL)allowRecursive
- functionName:(const char *)functionName;
- + (nullable NSArray *)functionsHoldingSynchronizationOnObject:(id)object;
- @end
- #else
- #define GTMSessionMonitorSynchronized(obj) \
- do { \
- } while (0)
- #define GTMSessionMonitorRecursiveSynchronized(obj) \
- do { \
- } while (0)
- #define GTMSessionCheckSynchronized(obj) \
- do { \
- } while (0)
- #define GTMSessionCheckNotSynchronized(obj) \
- do { \
- } while (0)
- #endif
- #endif
- NS_ASSUME_NONNULL_END
|