mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
fix for #302
This commit is contained in:
parent
be12e91109
commit
ec914793c3
7 changed files with 73 additions and 24 deletions
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
|||
2024-02-11 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Headers/Foundation/NSURLProtocol.h:
|
||||
* Source/GSEasyHandle.m:
|
||||
* Source/GSHTTPURLProtocol.m:
|
||||
* Source/GSNativeProtocol.m:
|
||||
* Source/NSURLProtocol.m:
|
||||
* Source/NSURLSession.m:
|
||||
Add +canInitWithTask: and altered code to differentiate between
|
||||
protocols which can be used with NSURLConnection and those which
|
||||
can be used with NSURLSession to fix #302
|
||||
|
||||
2024-02-11 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSLocale.m: (+canonicalLocaleIdentifierFromString:)
|
||||
|
|
|
@ -209,6 +209,11 @@ GS_EXPORT_CLASS
|
|||
*/
|
||||
+ (BOOL) canInitWithRequest: (NSURLRequest *)request;
|
||||
|
||||
/** This method is called to decide whether a class can deal with
|
||||
* the specified task. The abstract class implementation return NO.
|
||||
*/
|
||||
+ (BOOL) canInitWithTask: (NSURLSessionTask*)task;
|
||||
|
||||
/** <override-subclass />
|
||||
* Returns the 'canonical' version of the request.<br />
|
||||
* The canonical form is used to look up requests in the cache by
|
||||
|
|
|
@ -51,12 +51,14 @@ handleEasyCode(int code)
|
|||
static size_t
|
||||
curl_write_function(char *data, size_t size, size_t nmemb, void *userdata)
|
||||
{
|
||||
GSEasyHandle *handle;
|
||||
|
||||
if (!userdata)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GSEasyHandle *handle = (GSEasyHandle*)userdata;
|
||||
handle = (GSEasyHandle*)userdata;
|
||||
|
||||
[handle resetTimer]; //FIXME should be deffered after the function returns?
|
||||
|
||||
|
@ -66,12 +68,14 @@ curl_write_function(char *data, size_t size, size_t nmemb, void *userdata)
|
|||
static size_t
|
||||
curl_read_function(char *data, size_t size, size_t nmemb, void *userdata)
|
||||
{
|
||||
GSEasyHandle *handle;
|
||||
|
||||
if (!userdata)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GSEasyHandle *handle = (GSEasyHandle*)userdata;
|
||||
handle = (GSEasyHandle*)userdata;
|
||||
|
||||
[handle resetTimer]; //FIXME should be deffered after the function returns?
|
||||
|
||||
|
@ -81,13 +85,15 @@ curl_read_function(char *data, size_t size, size_t nmemb, void *userdata)
|
|||
size_t
|
||||
curl_header_function(char *data, size_t size, size_t nmemb, void *userdata)
|
||||
{
|
||||
GSEasyHandle *handle;
|
||||
double length;
|
||||
|
||||
if (!userdata)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GSEasyHandle *handle = (GSEasyHandle*)userdata;
|
||||
double length;
|
||||
handle = (GSEasyHandle*)userdata;
|
||||
|
||||
[handle resetTimer]; //FIXME should be deffered after the function returns?
|
||||
|
||||
|
@ -103,12 +109,14 @@ curl_header_function(char *data, size_t size, size_t nmemb, void *userdata)
|
|||
static int
|
||||
curl_seek_function(void *userdata, curl_off_t offset, int origin)
|
||||
{
|
||||
GSEasyHandle *handle;
|
||||
|
||||
if (!userdata)
|
||||
{
|
||||
return CURL_SEEKFUNC_FAIL;
|
||||
}
|
||||
|
||||
GSEasyHandle *handle = (GSEasyHandle*)userdata;
|
||||
handle = (GSEasyHandle*)userdata;
|
||||
|
||||
return [handle seekInputStreamWithOffset: offset origin: origin];
|
||||
}
|
||||
|
@ -117,6 +125,12 @@ static int
|
|||
curl_debug_function(CURL *handle, curl_infotype type, char *data,
|
||||
size_t size, void *userptr)
|
||||
{
|
||||
NSURLSessionTask *task;
|
||||
NSString *text;
|
||||
NSURLRequest *o;
|
||||
NSURLRequest *r;
|
||||
id<GSLogDelegate> d;
|
||||
|
||||
if (!userptr)
|
||||
{
|
||||
return 0;
|
||||
|
@ -127,11 +141,11 @@ curl_debug_function(CURL *handle, curl_infotype type, char *data,
|
|||
return 0; // Don't log encrypted data here
|
||||
}
|
||||
|
||||
NSURLSessionTask *task = (NSURLSessionTask*)userptr;
|
||||
NSString *text = @"";
|
||||
NSURLRequest *o = [task originalRequest];
|
||||
NSURLRequest *r = [task currentRequest];
|
||||
id<GSLogDelegate> d = [(nil == r ? o : r) _debugLogDelegate];
|
||||
task = (NSURLSessionTask*)userptr;
|
||||
text = @"";
|
||||
o = [task originalRequest];
|
||||
r = [task currentRequest];
|
||||
d = [(nil == r ? o : r) _debugLogDelegate];
|
||||
|
||||
if (d != nil)
|
||||
{
|
||||
|
@ -177,10 +191,12 @@ curl_socket_function(void *userdata, curl_socket_t fd, curlsocktype type)
|
|||
{
|
||||
if (nil != (self = [super init]))
|
||||
{
|
||||
char *eb;
|
||||
|
||||
_rawHandle = curl_easy_init();
|
||||
_delegate = delegate;
|
||||
|
||||
char *eb = (char *)malloc(sizeof(char) * (CURL_ERROR_SIZE + 1));
|
||||
eb = (char *)malloc(sizeof(char) * (CURL_ERROR_SIZE + 1));
|
||||
_errorBuffer = memset(eb, 0, sizeof(char) * (CURL_ERROR_SIZE + 1));
|
||||
|
||||
[self setupCallbacks];
|
||||
|
@ -395,8 +411,9 @@ curl_socket_function(void *userdata, curl_socket_t fd, curlsocktype type)
|
|||
{
|
||||
if (nil != host)
|
||||
{
|
||||
NSString *originHost = [_URL host];
|
||||
NSString *value = nil;
|
||||
NSString *originHost = [_URL host];
|
||||
NSString *value;
|
||||
struct curl_slist *connect_to;
|
||||
|
||||
if (0 == port)
|
||||
{
|
||||
|
@ -408,7 +425,6 @@ curl_socket_function(void *userdata, curl_socket_t fd, curlsocktype type)
|
|||
originHost, (unsigned long)port, host];
|
||||
}
|
||||
|
||||
struct curl_slist *connect_to = NULL;
|
||||
connect_to = curl_slist_append(NULL, [value UTF8String]);
|
||||
handleEasyCode(
|
||||
curl_easy_setopt(_rawHandle, CURLOPT_CONNECT_TO, connect_to));
|
||||
|
|
|
@ -323,9 +323,10 @@ parseArgumentPart(NSString *part, NSString *name)
|
|||
|
||||
@implementation GSHTTPURLProtocol
|
||||
|
||||
+ (BOOL) canInitWithRequest: (NSURLRequest*)request
|
||||
+ (BOOL) canInitWithTask: (NSURLSessionTask*)task
|
||||
{
|
||||
NSURL *url;
|
||||
NSURLRequest *request = [task currentRequest];
|
||||
NSURL *url;
|
||||
|
||||
if (nil != (url = [request URL])
|
||||
&& ([[url scheme] isEqualToString: @"http"]
|
||||
|
@ -431,6 +432,7 @@ parseArgumentPart(NSString *part, NSString *name)
|
|||
NSURLSessionTask *task = [self task];
|
||||
NSURLSession *session = [task session];
|
||||
NSURLSessionConfiguration *config = [session configuration];
|
||||
BOOL debugLibcurl;
|
||||
|
||||
if ([[request HTTPMethod] isEqualToString:@"GET"])
|
||||
{
|
||||
|
@ -452,7 +454,7 @@ parseArgumentPart(NSString *part, NSString *name)
|
|||
}
|
||||
}
|
||||
|
||||
BOOL debugLibcurl = [[[NSProcessInfo processInfo] environment]
|
||||
debugLibcurl = [[[NSProcessInfo processInfo] environment]
|
||||
objectForKey: @"URLSessionDebugLibcurl"] ? YES : NO;
|
||||
|
||||
/* Programatically turning debug on in the request supercedes any
|
||||
|
@ -636,9 +638,10 @@ parseArgumentPart(NSString *part, NSString *name)
|
|||
- (NSURLRequest*) redirectRequestForResponse: (NSHTTPURLResponse*)response
|
||||
fromRequest: (NSURLRequest*)fromRequest
|
||||
{
|
||||
NSString *method = nil;
|
||||
NSURL *targetURL;
|
||||
NSString *location;
|
||||
NSString *method = nil;
|
||||
NSURL *targetURL;
|
||||
NSString *location;
|
||||
NSMutableURLRequest *request;
|
||||
|
||||
if (nil == [response allHeaderFields])
|
||||
{
|
||||
|
@ -673,7 +676,7 @@ parseArgumentPart(NSString *part, NSString *name)
|
|||
return nil;
|
||||
}
|
||||
|
||||
NSMutableURLRequest *request = AUTORELEASE([fromRequest mutableCopy]);
|
||||
request = AUTORELEASE([fromRequest mutableCopy]);
|
||||
[request setHTTPMethod: method];
|
||||
|
||||
if (nil != [targetURL scheme] && nil != [targetURL host])
|
||||
|
|
|
@ -104,13 +104,15 @@ static BOOL isEasyHandleAddedToMultiHandle(GSNativeProtocolInternalState state)
|
|||
|
||||
- (void) getBodyWithCompletion: (void (^)(GSURLSessionTaskBody *body))completion
|
||||
{
|
||||
GSURLSessionTaskBody *body;
|
||||
|
||||
if (nil != _knownBody)
|
||||
{
|
||||
completion(_knownBody);
|
||||
return;
|
||||
};
|
||||
|
||||
GSURLSessionTaskBody *body = AUTORELEASE([[GSURLSessionTaskBody alloc] init]);
|
||||
body = AUTORELEASE([[GSURLSessionTaskBody alloc] init]);
|
||||
completion(body);
|
||||
}
|
||||
|
||||
|
@ -198,6 +200,11 @@ static BOOL isEasyHandleAddedToMultiHandle(GSNativeProtocolInternalState state)
|
|||
|
||||
@implementation GSNativeProtocol
|
||||
|
||||
+ (BOOL) canInitWithRequest: (NSURLRequest*)request
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (instancetype) initWithTask: (NSURLSessionTask*)_task
|
||||
cachedResponse: (NSCachedURLResponse*)_cachedResponse
|
||||
client: (id<NSURLProtocolClient>)_client
|
||||
|
|
|
@ -721,6 +721,11 @@ typedef struct {
|
|||
return NO;
|
||||
}
|
||||
|
||||
+ (BOOL) canInitWithTask: (NSURLSessionTask*)task
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
+ (NSURLRequest *) canonicalRequestForRequest: (NSURLRequest *)request
|
||||
{
|
||||
return request;
|
||||
|
|
|
@ -684,6 +684,7 @@ static unsigned nextSessionIdentifier()
|
|||
{
|
||||
NSURLSessionTask *task = [protocol task];
|
||||
NSURLSession *session;
|
||||
id<NSURLSessionDelegate> delegate;
|
||||
|
||||
NSAssert(nil != task, @"Missing task");
|
||||
|
||||
|
@ -712,7 +713,7 @@ static unsigned nextSessionIdentifier()
|
|||
}
|
||||
}
|
||||
|
||||
id<NSURLSessionDelegate> delegate = [session delegate];
|
||||
delegate = [session delegate];
|
||||
if (nil != delegate)
|
||||
{
|
||||
[[session delegateQueue] addOperationWithBlock:
|
||||
|
@ -1008,7 +1009,7 @@ static unsigned nextSessionIdentifier()
|
|||
e = [[[session configuration] protocolClasses] objectEnumerator];
|
||||
while (nil != (protocolClass = [e nextObject]))
|
||||
{
|
||||
if ([protocolClass canInitWithRequest: request])
|
||||
if ([protocolClass canInitWithTask: self])
|
||||
{
|
||||
_protocolClass = protocolClass;
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue