ObjFW  Diff

Differences From Artifact [05de45f519]:

To Artifact [99ab8cb487]:


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
12
13
14
15
16
17
18

19

20
21
22
23
24
25
26







-

-







 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#include <stdlib.h>
#include <string.h>
#include <time.h>

#import "OFHTTPClient.h"
#import "OFHTTPRequest.h"
#import "OFHTTPResponse.h"
#import "OFString.h"
#import "OFTCPSocket.h"
#import "OFThread.h"
36
37
38
39
40
41
42
43

44
45
46
47
48
49
50
51
52
53
54
55
56


57
58
59
60
61
62
63
64
65
66
67
68

69
70
71
72
73
74
75
34
35
36
37
38
39
40

41
42
43
44
45
46
47
48
49
50
51
52


53
54
55
56
57
58
59
60
61
62
63
64
65

66
67
68
69
70
71
72
73







-
+











-
-
+
+











-
+








static OFString *module = @"OFHTTPClient";
static OFCondition *cond;

@interface OFHTTPClientTestsServer: OFThread
{
@public
	uint16_t port;
	uint16_t _port;
}
@end

@implementation OFHTTPClientTestsServer
- main
{
	OFTCPSocket *listener, *client;

	[cond lock];

	listener = [OFTCPSocket socket];
	port = [listener bindToHost: @"127.0.0.1"
			       port: 0];
	_port = [listener bindToHost: @"127.0.0.1"
				port: 0];
	[listener listen];

	[cond signal];
	[cond unlock];

	client = [listener accept];

	if (![[client readLine] isEqual: @"GET /foo HTTP/1.1"])
		OF_ENSURE(0);

	if (![[client readLine] isEqual:
	    [OFString stringWithFormat: @"Host: 127.0.0.1:%" @PRIu16, port]])
	    [OFString stringWithFormat: @"Host: 127.0.0.1:%" @PRIu16, _port]])
		OF_ENSURE(0);

	if (![[client readLine] hasPrefix: @"User-Agent:"])
		OF_ENSURE(0);

	if (![[client readLine] isEqual: @""])
		OF_ENSURE(0);
103
104
105
106
107
108
109
110

111
112
113
114
115
116
117
101
102
103
104
105
106
107

108
109
110
111
112
113
114
115







-
+







	[server start];

	[cond wait];
	[cond unlock];

	url = [OFURL URLWithString:
	    [OFString stringWithFormat: @"http://127.0.0.1:%" @PRIu16 "/foo",
					server->port]];
					server->_port]];

	TEST(@"-[performRequest:]",
	    (client = [OFHTTPClient client]) &&
	    R(request = [OFHTTPRequest requestWithURL: url]) &&
	    R(response = [client performRequest: request]))

	TEST(@"Normalization of server header keys",