Add GSDigestURIOmitsQuery key

This commit is contained in:
Earl Robsham 2025-03-25 19:40:03 -04:00
parent dc4270128d
commit f8173506cd
5 changed files with 21 additions and 3 deletions

View file

@ -1,8 +1,11 @@
2025-03-21 Earl Robsham <earl.robsham@savant.com>
* Headers/Foundation/NSURLHandle.h:
* Sources/externs.m:
* Source/GSHTTPURLHandle.m:
* Source/NSURLProtocol.m:
Updates `Authorization` header generation to include the query parameters (if present).
Brings the implementation inline with MacOS.
Also adds the `GSDigestURIOmitsQuery` key for use with ` -[NSHTTPURLHandle writeProperty:forKey:]` / `+[NSURLProtocol setProperty:forKey:inRequest:]` to toggle off this updated behavior.
2025-03-08 Richard Frith-Macdonald <rfm@gnu.org>

View file

@ -114,6 +114,14 @@ GS_EXPORT NSString * const GSHTTPPropertyKeyFileKey;
*/
GS_EXPORT NSString * const GSHTTPPropertyPasswordKey;
/**
* Key for passing to [NSURLHandle]'s and [NSHTTPURLProtocol]'s
* <code>propertyForKey..</code> methods. Specifying <code>@YES</code> will
* signal Digest Authentication logic to always omit the 'query' portion of the
* URI when generating the `Authorization` header.
*/
GS_EXPORT NSString * const GSDigestURIOmitsQuery;
#endif
/**

View file

@ -536,6 +536,7 @@ debugWrite(GSHTTPURLHandle *handle, NSData *data)
NSURLCredential *cred;
NSString *method;
NSString *path;
NSNumber *omitQuery;
/* Create credential from user and password stored in the URL.
* Returns nil if we have no username or password.
@ -573,7 +574,8 @@ debugWrite(GSHTTPURLHandle *handle, NSData *data)
}
}
if ([[u query] length] == 0)
omitQuery = [request objectForKey:GSDigestURIOmitsQuery];
if ([[u query] length] == 0 || [omitQuery boolValue])
{
path = [u pathWithEscapes];
}
@ -849,6 +851,7 @@ debugWrite(GSHTTPURLHandle *handle, NSData *data)
NSString *method;
NSString *path;
NSString *auth;
NSNumber *omitQuery;
ac = [ah value];
space = [GSHTTPAuthentication
@ -902,7 +905,8 @@ debugWrite(GSHTTPURLHandle *handle, NSData *data)
}
}
if ([[url query] length] == 0)
omitQuery = [request objectForKey:GSDigestURIOmitsQuery];
if ([[url query] length] == 0 || [omitQuery boolValue])
{
path = [url pathWithEscapes];
}

View file

@ -1399,6 +1399,7 @@ typedef struct {
if (_credential != nil)
{
GSHTTPAuthentication *authentication;
NSNumber *omitQuery;
/* Get information about basic or
* digest authentication.
@ -1410,10 +1411,11 @@ typedef struct {
/* Generate authentication header value for the
* authentication type in the challenge.
*/
omitQuery = [this->request _propertyForKey:GSDigestURIOmitsQuery];
auth = [authentication
authorizationForAuthentication: hdr
method: [this->request HTTPMethod]
path: [[url query] length] == 0 ?
path: [[url query] length] == 0 || [omitQuery boolValue] ?
[url pathWithEscapes] :
[NSString stringWithFormat:@"%@?%@", [url pathWithEscapes], [url query]]
];

View file

@ -562,6 +562,7 @@ GS_DECLARE NSString* const GSHTTPPropertyProxyPortKey = @"GSHTTPPropertyProxyPor
GS_DECLARE NSString* const GSHTTPPropertyCertificateFileKey = @"GSHTTPPropertyCertificateFileKey";
GS_DECLARE NSString* const GSHTTPPropertyKeyFileKey = @"GSHTTPPropertyKeyFileKey";
GS_DECLARE NSString* const GSHTTPPropertyPasswordKey = @"GSHTTPPropertyPasswordKey";
GS_DECLARE NSString* const GSDigestURIOmitsQuery = @"GSDigestURIOmitsQuery";
/* NSURLProtectionSpace */
GS_DECLARE NSString* const NSURLProtectionSpaceFTPProxy = @"ftp";