mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Add chunked encding test
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@34899 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
7fd24c9e94
commit
719178bc2e
3 changed files with 70 additions and 12 deletions
16
Tests/base/NSURL/Chunked.dat
Normal file
16
Tests/base/NSURL/Chunked.dat
Normal file
|
@ -0,0 +1,16 @@
|
|||
HTTP/1.1 200 OK
|
||||
Content-Type: text/plain
|
||||
Transfer-Encoding: chunked
|
||||
|
||||
25
|
||||
This is the data in the first chunk
|
||||
|
||||
1C
|
||||
and this is the second one
|
||||
|
||||
3
|
||||
con
|
||||
8
|
||||
sequence
|
||||
0
|
||||
|
|
@ -59,12 +59,18 @@
|
|||
return 1;
|
||||
}
|
||||
|
||||
lengthHeader = [NSString stringWithFormat: @"Content-Length: %d\r\n",
|
||||
[bodyData length]];
|
||||
headers = [[NSArray alloc] initWithObjects: @"HTTP/1.1 200 OK\r\n",
|
||||
@"Content-type: text/plain\r\n",
|
||||
lengthHeader,
|
||||
nil];
|
||||
if (YES == [defs boolForKey: @"FileHdrs"])
|
||||
{
|
||||
headers = nil; // Already in the file
|
||||
}
|
||||
else
|
||||
{
|
||||
lengthHeader = [NSString stringWithFormat: @"Content-Length: %d\r\n",
|
||||
[bodyData length]];
|
||||
headers = [[NSArray alloc] initWithObjects: @"HTTP/1.1 200 OK\r\n",
|
||||
@"Content-type: text/plain\r\n", lengthHeader, nil];
|
||||
}
|
||||
|
||||
serverStream = [GSServerStream serverStreamToAddr: [host address] port: port];
|
||||
if (nil == serverStream)
|
||||
{
|
||||
|
@ -161,15 +167,20 @@
|
|||
}
|
||||
|
||||
headerEnumeration = [headerArray objectEnumerator];
|
||||
|
||||
while ((header = [headerEnumeration nextObject]))
|
||||
[payload appendData: [header dataUsingEncoding: NSASCIIStringEncoding]];
|
||||
[payload appendData: [@"\n" dataUsingEncoding: NSASCIIStringEncoding]];
|
||||
if (nil != headerEnumeration)
|
||||
{
|
||||
while ((header = [headerEnumeration nextObject]))
|
||||
[payload appendData:
|
||||
[header dataUsingEncoding: NSASCIIStringEncoding]];
|
||||
[payload appendData:
|
||||
[@"\n" dataUsingEncoding: NSASCIIStringEncoding]];
|
||||
}
|
||||
[payload appendData: bodyData];
|
||||
|
||||
// provide the reply
|
||||
written = [outStream write: [payload bytes] maxLength: [payload length]];
|
||||
if (written <=0)
|
||||
written = [outStream write: [payload bytes]
|
||||
maxLength: [payload length]];
|
||||
if (written <= 0)
|
||||
{
|
||||
// something seriously wrong....
|
||||
closeConnection = YES;
|
||||
|
|
|
@ -19,13 +19,44 @@ int main()
|
|||
NSString *helpers;
|
||||
NSString *capture;
|
||||
NSString *respond;
|
||||
NSString *keepalive;
|
||||
|
||||
helpers = [[NSFileManager defaultManager] currentDirectoryPath];
|
||||
helpers = [helpers stringByAppendingPathComponent: @"Helpers"];
|
||||
helpers = [helpers stringByAppendingPathComponent: @"obj"];
|
||||
capture = [helpers stringByAppendingPathComponent: @"capture"];
|
||||
keepalive = [helpers stringByAppendingPathComponent: @"keepalive"];
|
||||
respond = [helpers stringByAppendingPathComponent: @"respond"];
|
||||
|
||||
t = [NSTask launchedTaskWithLaunchPath: keepalive
|
||||
arguments: [NSArray arrayWithObjects:
|
||||
@"-FileName", @"Chunked.dat",
|
||||
@"-FileHdrs", @"YES", // Headers are in file
|
||||
@"-Port", @"54321",
|
||||
@"-Count", @"1",
|
||||
nil]];
|
||||
if (t != nil)
|
||||
{
|
||||
const char *lit = "This is the data in the first chunk\r\n"
|
||||
"and this is the second one\r\n"
|
||||
"consequence";
|
||||
|
||||
cont = [NSData dataWithBytes: lit length: strlen(lit)];
|
||||
|
||||
// Pause to allow server subtask to set up.
|
||||
[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.5]];
|
||||
u = [NSURL URLWithString: @"http://localhost:54321/chunked"];
|
||||
// Talk to server.
|
||||
data = [u resourceDataUsingCache: NO];
|
||||
// Get status code
|
||||
str = [u propertyForKey: NSHTTPPropertyStatusCodeKey];
|
||||
PASS([data isEqual: cont], "chunked test OK");
|
||||
// Wait for server termination
|
||||
[t terminate];
|
||||
[t waitUntilExit];
|
||||
}
|
||||
|
||||
|
||||
url = [NSURL URLWithString: @"http://localhost:54321/"];
|
||||
|
||||
/* Ask the 'respond' helper to send back a response containing
|
||||
|
|
Loading…
Reference in a new issue