2014-11-29 11:39:38 +00:00
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* Author: Sergei Golovin <Golovin.SV@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* Runs two TestWebServer instances to check how the class TestWebServer
|
2016-03-05 16:13:44 +00:00
|
|
|
|
* behaves. Visit http://127.0.0.1:1234/index to see all supported resources.
|
2014-11-29 11:39:38 +00:00
|
|
|
|
*
|
|
|
|
|
* If you visit the main TestWebServer instance with the following command:
|
|
|
|
|
*
|
2016-03-05 16:13:44 +00:00
|
|
|
|
* wget -O - --user=login --password=password http://127.0.0.1:1234/301 2>&1
|
2014-11-29 11:39:38 +00:00
|
|
|
|
*
|
|
|
|
|
* you should get a session log like this:
|
|
|
|
|
*
|
2016-03-05 16:13:44 +00:00
|
|
|
|
* --2014-08-13 12:08:01-- http://127.0.0.1:1234/301
|
|
|
|
|
* Resolving 127.0.0.1 (localhost)... 127.0.0.1
|
|
|
|
|
* Connecting to 127.0.0.1 (localhost)|127.0.0.1|:1234... connected.
|
2014-11-29 11:39:38 +00:00
|
|
|
|
* HTTP request sent, awaiting response... 401 Unauthorized
|
2016-03-05 16:13:44 +00:00
|
|
|
|
* Reusing existing connection to 127.0.0.1:1234.
|
2014-11-29 11:39:38 +00:00
|
|
|
|
* HTTP request sent, awaiting response... 301 Moved Permanently
|
2016-03-05 16:13:44 +00:00
|
|
|
|
* Location: http://127.0.0.1:1235/ [following]
|
|
|
|
|
* --2014-08-13 12:08:01-- http://127.0.0.1:1235/
|
|
|
|
|
* Connecting to 127.0.0.1:1235... connected.
|
2014-11-29 11:39:38 +00:00
|
|
|
|
* HTTP request sent, awaiting response... 401 Unauthorized
|
2016-03-05 16:13:44 +00:00
|
|
|
|
* Reusing existing connection to 127.0.0.1:1235.
|
2014-11-29 11:39:38 +00:00
|
|
|
|
* HTTP request sent, awaiting response... 204 No Content
|
|
|
|
|
* Length: 0
|
|
|
|
|
* Saving to: ‘STDOUT’
|
|
|
|
|
*
|
|
|
|
|
* 0K 0.00 =0s
|
|
|
|
|
*
|
|
|
|
|
* 2014-08-13 12:08:01 (0.00 B/s) - written to stdout [0/0]
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
|
#import "TestWebServer.h"
|
|
|
|
|
#import "NSURLConnectionTest.h"
|
|
|
|
|
|
|
|
|
|
#define TIMING 0.1
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv, char **env)
|
|
|
|
|
{
|
|
|
|
|
CREATE_AUTORELEASE_POOL(arp);
|
|
|
|
|
NSFileManager *fm;
|
|
|
|
|
NSBundle *bundle;
|
|
|
|
|
BOOL loaded;
|
|
|
|
|
NSString *helperPath;
|
|
|
|
|
|
|
|
|
|
fm = [NSFileManager defaultManager];
|
|
|
|
|
helperPath = [[fm currentDirectoryPath]
|
2016-03-05 16:13:44 +00:00
|
|
|
|
stringByAppendingString: @"/TestConnection.bundle"];
|
2014-11-29 11:39:38 +00:00
|
|
|
|
bundle = [NSBundle bundleWithPath: helperPath];
|
|
|
|
|
loaded = [bundle load];
|
|
|
|
|
|
2016-03-05 16:13:44 +00:00
|
|
|
|
if (loaded)
|
2014-11-29 11:39:38 +00:00
|
|
|
|
{
|
|
|
|
|
TestWebServer *server1;
|
|
|
|
|
TestWebServer *server2;
|
|
|
|
|
Class testClass;
|
|
|
|
|
BOOL debug = YES;
|
|
|
|
|
NSDictionary *d;
|
|
|
|
|
|
|
|
|
|
testClass = [bundle principalClass]; // NSURLConnectionTest
|
|
|
|
|
d = [NSDictionary dictionaryWithObjectsAndKeys:
|
2016-03-05 16:13:44 +00:00
|
|
|
|
// @"https", @"Protocol",
|
|
|
|
|
nil];
|
|
|
|
|
server1 = [[[testClass testWebServerClass] alloc]
|
|
|
|
|
initWithAddress: @"127.0.0.1"
|
|
|
|
|
port: @"1234"
|
|
|
|
|
mode: NO
|
|
|
|
|
extra: d];
|
2014-11-29 11:39:38 +00:00
|
|
|
|
[server1 setDebug: debug];
|
2016-03-05 16:13:44 +00:00
|
|
|
|
[server1 start: d]; // 127.0.0.1:1234 HTTP
|
2014-11-29 11:39:38 +00:00
|
|
|
|
|
2016-03-05 16:13:44 +00:00
|
|
|
|
server2 = [[[testClass testWebServerClass] alloc]
|
|
|
|
|
initWithAddress: @"127.0.0.1"
|
|
|
|
|
port: @"1235"
|
|
|
|
|
mode: NO
|
|
|
|
|
extra: d];
|
2014-11-29 11:39:38 +00:00
|
|
|
|
[server2 setDebug: debug];
|
2016-03-05 16:13:44 +00:00
|
|
|
|
[server2 start: d]; // 127.0.0.1:1235 HTTP
|
2014-11-29 11:39:38 +00:00
|
|
|
|
|
2016-03-05 16:13:44 +00:00
|
|
|
|
while (YES)
|
2014-11-29 11:39:38 +00:00
|
|
|
|
{
|
|
|
|
|
[[NSRunLoop currentRunLoop]
|
|
|
|
|
runUntilDate: [NSDate dateWithTimeIntervalSinceNow: TIMING]];
|
|
|
|
|
}
|
|
|
|
|
// [server1 stop];
|
|
|
|
|
// DESTROY(server1);
|
|
|
|
|
// [server2 stop];
|
|
|
|
|
// DESTROY(server2);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
[NSException raise: NSInternalInconsistencyException
|
|
|
|
|
format: @"can't load bundle TestConnection"];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DESTROY(arp);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|