mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
Apply fixes for a couple of bug reports.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@34855 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
b2900f17b1
commit
26ffe755bb
4 changed files with 78 additions and 40 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
2012-03-01 Graham Lee
|
||||
|
||||
* Source/GSNetworks.h: import GSPrivate.h
|
||||
|
||||
2012-03-01 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Headers/Foundation/NSURLResponse.h:
|
||||
* Source/NSURLResponse.m:
|
||||
Implement new initialiser from 10.7
|
||||
|
||||
2012-03-01 Jens Alfke <jens@mooseyard.com>
|
||||
|
||||
* Source/NSJSONSerialization.m:
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#define __NSURLResponse_h_GNUSTEP_BASE_INCLUDE
|
||||
#import <GNUstepBase/GSVersionMacros.h>
|
||||
|
||||
#if OS_API_VERSION(100200,GS_API_LATEST) && GS_API_VERSION( 11300,GS_API_LATEST)
|
||||
#if OS_API_VERSION(100200,GS_API_LATEST)
|
||||
|
||||
#import <Foundation/NSObject.h>
|
||||
|
||||
|
@ -67,6 +67,17 @@ extern "C" {
|
|||
expectedContentLength: (NSInteger)length
|
||||
textEncodingName: (NSString *)name;
|
||||
|
||||
#if OS_API_VERSION(100700,GS_API_LATEST)
|
||||
/**
|
||||
* Initialises the receiver with the URL, statusCode, HTTPVersion, and
|
||||
* headerFields provided.
|
||||
*/
|
||||
- (id) initWithURL: (NSURL*)URL
|
||||
statusCode: (NSInteger)statusCode
|
||||
HTTPVersion: (NSString*)HTTPVersion
|
||||
headerFields: (NSDictionary*)headerFields;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Returns the receiver's MIME type.
|
||||
*/
|
||||
|
|
|
@ -98,6 +98,8 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#import "GSPrivate.h"
|
||||
|
||||
NSString*
|
||||
GSPrivateSockaddrHost(struct sockaddr *addr) GS_ATTRIB_PRIVATE;
|
||||
|
||||
|
|
|
@ -55,12 +55,45 @@ typedef struct {
|
|||
|
||||
@implementation NSURLResponse (Private)
|
||||
|
||||
- (void) _checkHeaders
|
||||
{
|
||||
if (NSURLResponseUnknownLength == this->expectedContentLength)
|
||||
{
|
||||
NSString *s= [self _valueForHTTPHeaderField: @"content-length"];
|
||||
|
||||
if ([s length] > 0)
|
||||
{
|
||||
this->expectedContentLength = [s intValue];
|
||||
}
|
||||
}
|
||||
|
||||
if (nil == this->MIMEType)
|
||||
{
|
||||
GSMimeHeader *c;
|
||||
GSMimeParser *p;
|
||||
NSScanner *s;
|
||||
NSString *v;
|
||||
|
||||
v = [self _valueForHTTPHeaderField: @"content-type"];
|
||||
if (v == nil)
|
||||
{
|
||||
v = @"text/plain"; // No content type given.
|
||||
}
|
||||
s = [NSScanner scannerWithString: v];
|
||||
p = [GSMimeParser new];
|
||||
c = AUTORELEASE([GSMimeHeader new]);
|
||||
[p scanHeaderBody: s into: c];
|
||||
RELEASE(p);
|
||||
ASSIGNCOPY(this->MIMEType, [c value]);
|
||||
v = [c parameterForKey: @"charset"];
|
||||
ASSIGNCOPY(this->textEncodingName, v);
|
||||
}
|
||||
}
|
||||
|
||||
- (void) _setHeaders: (id)headers
|
||||
{
|
||||
NSEnumerator *e;
|
||||
NSString *v;
|
||||
NSString *contentLength = nil;
|
||||
GSMimeHeader *contentType = nil;
|
||||
|
||||
if ([headers isKindOfClass: [NSDictionary class]] == YES)
|
||||
{
|
||||
|
@ -83,46 +116,10 @@ typedef struct {
|
|||
NSString *n = [h namePreservingCase: YES];
|
||||
NSString *v = [h fullValue];
|
||||
|
||||
if ([n caseInsensitiveCompare: @"content-type"] == NSOrderedSame)
|
||||
{
|
||||
contentType = h;
|
||||
}
|
||||
[self _setValue: v forHTTPHeaderField: n];
|
||||
}
|
||||
}
|
||||
|
||||
if (contentLength == nil)
|
||||
{
|
||||
contentLength = [self _valueForHTTPHeaderField: @"content-length"];
|
||||
}
|
||||
if ([contentLength length] == 0)
|
||||
{
|
||||
this->expectedContentLength = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->expectedContentLength = [contentLength intValue];
|
||||
}
|
||||
|
||||
if (contentType == nil)
|
||||
{
|
||||
GSMimeParser *p;
|
||||
NSScanner *s;
|
||||
|
||||
v = [self _valueForHTTPHeaderField: @"content-type"];
|
||||
if (v == nil)
|
||||
{
|
||||
v = @"text/plain"; // No content type given.
|
||||
}
|
||||
s = [NSScanner scannerWithString: v];
|
||||
p = [GSMimeParser new];
|
||||
contentType = AUTORELEASE([GSMimeHeader new]);
|
||||
[p scanHeaderBody: s into: contentType];
|
||||
RELEASE(p);
|
||||
}
|
||||
ASSIGNCOPY(this->MIMEType, [contentType value]);
|
||||
v = [contentType parameterForKey: @"charset"];
|
||||
ASSIGNCOPY(this->textEncodingName, v);
|
||||
[self _checkHeaders];
|
||||
}
|
||||
- (void) _setStatusCode: (NSInteger)code text: (NSString*)text
|
||||
{
|
||||
|
@ -250,6 +247,24 @@ typedef struct {
|
|||
return self;
|
||||
}
|
||||
|
||||
- (id) initWithURL: (NSURL*)URL
|
||||
statusCode: (NSInteger)statusCode
|
||||
HTTPVersion: (NSString*)HTTPVersion
|
||||
headerFields: (NSDictionary*)headerFields;
|
||||
{
|
||||
self = [self initWithURL: URL
|
||||
MIMEType: nil
|
||||
expectedContentLength: NSURLResponseUnknownLength
|
||||
textEncodingName: nil];
|
||||
if (nil != self)
|
||||
{
|
||||
this->statusCode = statusCode;
|
||||
this->headers = [headerFields copy];
|
||||
[self _checkHeaders];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSString *) MIMEType
|
||||
{
|
||||
return this->MIMEType;
|
||||
|
|
Loading…
Reference in a new issue