Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add missing NSURLSession APIs
  • Loading branch information
triplef committed Feb 17, 2023
commit 05adcf606bc1cbd2934ec2b4cb99665395c04307
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2023-01-13 Frederik Seiffert <[email protected]>

* Headers/Foundation/NSURLSession.h:
* Source/NSURLSession.m:
Add missing NSURLSession APIs.

2022-02-09 Richard Frith-Macdonald <[email protected]>

* Source/Additions/GSMime.m: ([GSMimeHeader setValue:]) do not set
Expand Down
132 changes: 104 additions & 28 deletions Headers/Foundation/NSURLSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
@class NSURLRequest;
@class NSURLResponse;
@class NSURLSessionConfiguration;
@class NSURLSessionTask;
@class NSURLSessionDataTask;
@class NSURLSessionUploadTask;
@class NSURLSessionDownloadTask;


Expand Down Expand Up @@ -62,6 +64,10 @@ GS_EXPORT_CLASS
GSMultiHandle *_multiHandle;
}

+ (NSURLSession*) sharedSession;

+ (NSURLSession*) sessionWithConfiguration: (NSURLSessionConfiguration*)configuration;

/*
* Customization of NSURLSession occurs during creation of a new session.
* If you do specify a delegate, the delegate will be retained until after
Expand Down Expand Up @@ -111,11 +117,80 @@ GS_EXPORT_CLASS
/* Creates a data task to retrieve the contents of the given URL. */
- (NSURLSessionDataTask*) dataTaskWithURL: (NSURL*)url;

/* Not implemented */
- (NSURLSessionUploadTask*) uploadTaskWithRequest: (NSURLRequest*)request
fromFile: (NSURL*)fileURL;

/* Not implemented */
- (NSURLSessionUploadTask*) uploadTaskWithRequest: (NSURLRequest*)request
fromData: (NSData*)bodyData;

/* Not implemented */
- (NSURLSessionUploadTask*) uploadTaskWithStreamedRequest: (NSURLRequest*)request;

/* Creates a download task with the given request. */
- (NSURLSessionDownloadTask *) downloadTaskWithRequest: (NSURLRequest *)request;
- (NSURLSessionDownloadTask*) downloadTaskWithRequest: (NSURLRequest*)request;

/* Creates a download task to download the contents of the given URL. */
- (NSURLSessionDownloadTask *) downloadTaskWithURL: (NSURL *)url;
- (NSURLSessionDownloadTask*) downloadTaskWithURL: (NSURL*)url;

/* Not implemented */
- (NSURLSessionDownloadTask *) downloadTaskWithResumeData: (NSData *)resumeData;

- (void) getTasksWithCompletionHandler: (void (^)(GS_GENERIC_CLASS(NSArray, NSURLSessionDataTask*) *dataTasks, GS_GENERIC_CLASS(NSArray, NSURLSessionUploadTask*) *uploadTasks, GS_GENERIC_CLASS(NSArray, NSURLSessionDownloadTask*) *downloadTasks))completionHandler;

- (void) getAllTasksWithCompletionHandler: (void (^)(GS_GENERIC_CLASS(NSArray, __kindof NSURLSessionTask*) *tasks))completionHandler;

@end

/*
* NSURLSession convenience routines deliver results to
* a completion handler block. These convenience routines
* are not available to NSURLSessions that are configured
* as background sessions.
*
* Task objects are always created in a suspended state and
* must be sent the -resume message before they will execute.
*/
@interface NSURLSession (NSURLSessionAsynchronousConvenience)
/*
* data task convenience methods. These methods create tasks that
* bypass the normal delegate calls for response and data delivery,
* and provide a simple cancelable asynchronous interface to receiving
* data. Errors will be returned in the NSURLErrorDomain,
* see <Foundation/NSURLError.h>. The delegate, if any, will still be
* called for authentication challenges.
*/
- (NSURLSessionDataTask*) dataTaskWithRequest: (NSURLRequest*)request
completionHandler: (void (^)(NSData *data, NSURLResponse *response, NSError *error))completionHandler;
- (NSURLSessionDataTask*) dataTaskWithURL: (NSURL*)url
completionHandler: (void (^)(NSData *data, NSURLResponse *response, NSError *error))completionHandler;


/* Not implemented */
- (NSURLSessionUploadTask*) uploadTaskWithRequest: (NSURLRequest*)request
fromFile: (NSURL*)fileURL
completionHandler: (void (^)(NSData *data, NSURLResponse *response, NSError *error))completionHandler;

/* Not implemented */
- (NSURLSessionUploadTask*) uploadTaskWithRequest: (NSURLRequest*)request
fromData: (NSData*)bodyData
completionHandler: (void (^)(NSData *data, NSURLResponse *response, NSError *error))completionHandler;

/*
* download task convenience methods. When a download successfully
* completes, the NSURL will point to a file that must be read or
* copied during the invocation of the completion routine. The file
* will be removed automatically.
*/
- (NSURLSessionDownloadTask*) downloadTaskWithRequest: (NSURLRequest*)request
completionHandler: (void (^)(NSURL *location, NSURLResponse *response, NSError *error))completionHandler;
- (NSURLSessionDownloadTask*) downloadTaskWithURL: (NSURL *)url
completionHandler: (void (^)(NSURL *location, NSURLResponse *response, NSError *error))completionHandler;

/* Not implemented */
- (NSURLSessionDownloadTask*) downloadTaskWithResumeData: (NSData*)resumeData
completionHandler: (void (^)(NSURL *location, NSURLResponse *response, NSError *error))completionHandler;

@end

Expand All @@ -131,6 +206,12 @@ typedef NS_ENUM(NSUInteger, NSURLSessionTaskState) {
NSURLSessionTaskStateCompleted = 3,
};

GS_EXPORT const float NSURLSessionTaskPriorityDefault;
GS_EXPORT const float NSURLSessionTaskPriorityLow;
GS_EXPORT const float NSURLSessionTaskPriorityHigh;

GS_EXPORT const int64_t NSURLSessionTransferSizeUnknown;

/*
* NSURLSessionTask - a cancelable object that refers to the lifetime
* of processing a given request.
Expand Down Expand Up @@ -245,6 +326,9 @@ GS_EXPORT_CLASS
- (void) suspend;
- (void) resume;

- (float) priority;
- (void) setPriority: (float)priority;

@end

GS_EXPORT_CLASS
Expand Down Expand Up @@ -273,6 +357,7 @@ GS_EXPORT_CLASS
GS_EXPORT_CLASS
@interface NSURLSessionConfiguration : NSObject <NSCopying>
{
NSString *_identifier;
NSURLCache *_URLCache;
NSURLRequestCachePolicy _requestCachePolicy;
NSArray *_protocolClasses;
Expand All @@ -288,60 +373,51 @@ GS_EXPORT_CLASS

- (NSURLRequest*) configureRequest: (NSURLRequest*)request;

@property (class, readonly, strong)
NSURLSessionConfiguration *defaultSessionConfiguration;
+ (NSURLSessionConfiguration*) defaultSessionConfiguration;
+ (NSURLSessionConfiguration*) ephemeralSessionConfiguration;
+ (NSURLSessionConfiguration*) backgroundSessionConfigurationWithIdentifier:(NSString*)identifier;

- (NSDictionary*) HTTPAdditionalHeaders;
- (void) setHTTPAdditionalHeaders: (NSDictionary*)headers;

- (NSHTTPCookieAcceptPolicy) HTTPCookieAcceptPolicy;
- (void) setHTTPCookieAcceptPolicy: (NSHTTPCookieAcceptPolicy)policy;

- (NSHTTPCookieStorage*) HTTPCookieStorage;

#if !NO_GNUSTEP
- (NSInteger) HTTPMaximumConnectionLifetime;
#endif
- (void) setHTTPCookieStorage: (NSHTTPCookieStorage*)storage;

- (NSInteger) HTTPMaximumConnectionsPerHost;
- (void) setHTTPMaximumConnectionsPerHost: (NSInteger)n;

- (BOOL) HTTPShouldSetCookies;
- (void) setHTTPShouldSetCookies: (BOOL)flag;

- (BOOL) HTTPShouldUsePipelining;
- (void) setHTTPShouldUsePipelining: (BOOL)flag;

- (NSString*) identifier;

- (NSArray*) protocolClasses;

- (NSURLRequestCachePolicy) requestCachePolicy;
- (void) setRequestCachePolicy: (NSURLRequestCachePolicy)policy;

- (void) setHTTPAdditionalHeaders: (NSDictionary*)headers;

- (void) setHTTPCookieAcceptPolicy: (NSHTTPCookieAcceptPolicy)policy;
- (NSURLCache*) URLCache;
- (void) setURLCache: (NSURLCache*)cache;

- (void) setHTTPCookieStorage: (NSHTTPCookieStorage*)storage;
- (NSURLCredentialStorage*) URLCredentialStorage;
- (void) setURLCredentialStorage: (NSURLCredentialStorage*)storage;

#if !NO_GNUSTEP
/** Permits a session to be configured so that older connections are reused.
* A value of zero or less uses the default behavior where connections are
* reused as long as they are not older than 118 seconds, which is reasonable
* for the vast majority if situations.
*/
- (NSInteger) HTTPMaximumConnectionLifetime;
- (void) setHTTPMaximumConnectionLifetime: (NSInteger)n;
#endif

- (void) setHTTPMaximumConnectionsPerHost: (NSInteger)n;

- (void) setHTTPShouldSetCookies: (BOOL)flag;

- (void) setHTTPShouldUsePipelining: (BOOL)flag;

- (void) setRequestCachePolicy: (NSURLRequestCachePolicy)policy;

- (void) setURLCache: (NSURLCache*)cache;

- (void) setURLCredentialStorage: (NSURLCredentialStorage*)storage;

- (NSURLCache*) URLCache;

- (NSURLCredentialStorage*) URLCredentialStorage;

@end

typedef NS_ENUM(NSInteger, NSURLSessionAuthChallengeDisposition) {
Expand Down
Loading