mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Try to ensure that headers with non-ascii characters are encoded properly (and at least don't cause an exception).
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@39873 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
0d98f56eca
commit
8183cd9557
3 changed files with 46 additions and 25 deletions
|
@ -1,3 +1,10 @@
|
|||
2016-06-17 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/GSHTTPURLHandle.m:
|
||||
* Source/NSURLprotocol.m:
|
||||
When sending HTTP headers, use RFC2047 rules (as specified in HTTP/1.1
|
||||
RFC2616) to encode non-ascii characters.
|
||||
|
||||
2016-06-17 Niels Grewe <niels.grewe@halbordnung.de>
|
||||
|
||||
* Headers/Foundation/NSRegularExpression.h
|
||||
|
|
|
@ -547,15 +547,20 @@ debugWrite(GSHTTPURLHandle *handle, NSData *data)
|
|||
}
|
||||
}
|
||||
|
||||
buf = [[s dataUsingEncoding: NSISOLatin1StringEncoding] mutableCopy];
|
||||
|
||||
enumerator = NSEnumerateMapTable(wProperties);
|
||||
while (NSNextMapEnumeratorPair(&enumerator, (void **)(&key), (void**)&val))
|
||||
{
|
||||
[s appendFormat: @"%@: %@\r\n", key, val];
|
||||
GSMimeHeader *h;
|
||||
|
||||
h = [[GSMimeHeader alloc] initWithName: key value: val parameters: nil];
|
||||
[buf appendData: [h rawMimeDataPreservingCase: YES foldedAt: 0]];
|
||||
RELEASE(h);
|
||||
}
|
||||
NSEndMapTableEnumeration(&enumerator);
|
||||
|
||||
[s appendString: @"\r\n"];
|
||||
buf = [[s dataUsingEncoding: NSASCIIStringEncoding] mutableCopy];
|
||||
[buf appendBytes: "\r\n" length: 2];
|
||||
|
||||
/*
|
||||
* Append any data to be sent
|
||||
|
|
|
@ -1428,11 +1428,11 @@ static NSURLProtocol *placeholder = nil;
|
|||
}
|
||||
else if (stream == this->output)
|
||||
{
|
||||
switch(event)
|
||||
switch (event)
|
||||
{
|
||||
case NSStreamEventOpenCompleted:
|
||||
{
|
||||
NSMutableString *m;
|
||||
NSMutableData *m;
|
||||
NSDictionary *d;
|
||||
NSEnumerator *e;
|
||||
NSString *s;
|
||||
|
@ -1459,39 +1459,46 @@ static NSURLProtocol *placeholder = nil;
|
|||
_shouldClose = YES;
|
||||
}
|
||||
|
||||
m = [[NSMutableString alloc] initWithCapacity: 1024];
|
||||
m = [[NSMutableData alloc] initWithCapacity: 1024];
|
||||
|
||||
/* The request line is of the form:
|
||||
* method /path?query HTTP/version
|
||||
* where the query part may be missing
|
||||
*/
|
||||
[m appendString: [this->request HTTPMethod]];
|
||||
[m appendString: @" "];
|
||||
[m appendData: [[this->request HTTPMethod]
|
||||
dataUsingEncoding: NSASCIIStringEncoding]];
|
||||
[m appendBytes: " " length: 1];
|
||||
u = [this->request URL];
|
||||
s = [[u fullPath] stringByAddingPercentEscapesUsingEncoding:
|
||||
NSUTF8StringEncoding];
|
||||
if ([s hasPrefix: @"/"] == NO)
|
||||
{
|
||||
[m appendString: @"/"];
|
||||
[m appendBytes: "/" length: 1];
|
||||
}
|
||||
[m appendString: s];
|
||||
[m appendData: [s dataUsingEncoding: NSASCIIStringEncoding]];
|
||||
s = [u query];
|
||||
if ([s length] > 0)
|
||||
{
|
||||
[m appendString: @"?"];
|
||||
[m appendString: s];
|
||||
[m appendBytes: "?" length: 1];
|
||||
[m appendData: [s dataUsingEncoding: NSASCIIStringEncoding]];
|
||||
}
|
||||
[m appendFormat: @" HTTP/%0.1f\r\n", _version];
|
||||
s = [NSString stringWithFormat: @" HTTP/%0.1f\r\n", _version];
|
||||
[m appendData: [s dataUsingEncoding: NSASCIIStringEncoding]];
|
||||
|
||||
d = [this->request allHTTPHeaderFields];
|
||||
e = [d keyEnumerator];
|
||||
while ((s = [e nextObject]) != nil)
|
||||
{
|
||||
[m appendString: s];
|
||||
[m appendString: @": "];
|
||||
[m appendString: [d objectForKey: s]];
|
||||
[m appendString: @"\r\n"];
|
||||
GSMimeHeader *h;
|
||||
|
||||
h = [[GSMimeHeader alloc] initWithName: s
|
||||
value: [d objectForKey: s]
|
||||
parameters: nil];
|
||||
[m appendData:
|
||||
[h rawMimeDataPreservingCase: YES foldedAt: 0]];
|
||||
RELEASE(h);
|
||||
}
|
||||
|
||||
/* Use valueForHTTPHeaderField: to check for content-type
|
||||
* header as that does a case insensitive comparison and
|
||||
* we therefore won't end up adding a second header by
|
||||
|
@ -1502,8 +1509,9 @@ static NSURLProtocol *placeholder = nil;
|
|||
@"Content-Type"] == nil)
|
||||
{
|
||||
/* On MacOSX, this is automatically added to POST methods */
|
||||
[m appendString:
|
||||
@"Content-Type: application/x-www-form-urlencoded\r\n"];
|
||||
static char ct[]
|
||||
= "Content-Type: application/x-www-form-urlencoded\r\n";
|
||||
[m appendBytes: ct length: sizeof(ct)];
|
||||
}
|
||||
if ([this->request valueForHTTPHeaderField: @"Host"] == nil)
|
||||
{
|
||||
|
@ -1527,21 +1535,22 @@ static NSURLProtocol *placeholder = nil;
|
|||
}
|
||||
if (nil == p)
|
||||
{
|
||||
[m appendFormat: @"Host: %@\r\n", h];
|
||||
s = [NSString stringWithFormat: @"Host: %@\r\n", h];
|
||||
}
|
||||
else
|
||||
{
|
||||
[m appendFormat: @"Host: %@:%@\r\n", h, p];
|
||||
s = [NSString stringWithFormat: @"Host: %@:%@\r\n", h, p];
|
||||
}
|
||||
[m appendData: [s dataUsingEncoding: NSASCIIStringEncoding]];
|
||||
}
|
||||
if (l >= 0 && [this->request
|
||||
valueForHTTPHeaderField: @"Content-Length"] == nil)
|
||||
{
|
||||
[m appendFormat: @"Content-Length: %d\r\n", l];
|
||||
s = [NSString stringWithFormat: @"Content-Length: %d\r\n", l];
|
||||
[m appendData: [s dataUsingEncoding: NSASCIIStringEncoding]];
|
||||
}
|
||||
[m appendString: @"\r\n"]; // End of headers
|
||||
_writeData = RETAIN([m dataUsingEncoding: NSASCIIStringEncoding]);
|
||||
RELEASE(m);
|
||||
[m appendBytes: "\r\n" length: 2]; // End of headers
|
||||
_writeData = m;
|
||||
} // Fall through to do the write
|
||||
|
||||
case NSStreamEventHasSpaceAvailable:
|
||||
|
|
Loading…
Reference in a new issue