@@ -52,10 +52,11 @@ @implementation HTTPClientTestsServer - (id)main { OFTCPSocket *listener, *client; + char buffer[5]; [cond lock]; listener = [OFTCPSocket socket]; _port = [listener bindToHost: @"127.0.0.1" @@ -70,17 +71,29 @@ if (![[client readLine] isEqual: @"GET /foo HTTP/1.1"]) OF_ENSURE(0); if (![[client readLine] hasPrefix: @"User-Agent:"]) OF_ENSURE(0); + + if (![[client readLine] isEqual: @"Content-Length: 5"]) + OF_ENSURE(0); + + if (![[client readLine] isEqual: + @"Content-Type: application/x-www-form-urlencoded; charset=UTF-8"]) + OF_ENSURE(0); if (![[client readLine] isEqual: [OFString stringWithFormat: @"Host: 127.0.0.1:%" @PRIu16, _port]]) OF_ENSURE(0); if (![[client readLine] isEqual: @""]) OF_ENSURE(0); + + [client readIntoBuffer: buffer + exactLength: 5]; + if (memcmp(buffer, "Hello", 5) != 0) + OF_ENSURE(0); [client writeString: @"HTTP/1.0 200 OK\r\n" @"cONTeNT-lENgTH: 7\r\n" @"\r\n" @"foo\n" @@ -90,10 +103,18 @@ return nil; } @end @implementation TestsAppDelegate (OFHTTPClientTests) +- (void)client: (OFHTTPClient *)client + requestsBody: (OFStream *)body + request: (OFHTTPRequest *)request + context: (id)context +{ + [body writeString: @"Hello"]; +} + - (void)client: (OFHTTPClient *)client didPerformRequest: (OFHTTPRequest *)request response: (OFHTTPResponse *)response_ context: (id)context { @@ -124,11 +145,14 @@ [OFString stringWithFormat: @"http://127.0.0.1:%" @PRIu16 "/foo", server->_port]]; TEST(@"-[asyncPerformRequest:]", (client = [OFHTTPClient client]) && R([client setDelegate: self]) && - R(request = [OFHTTPRequest requestWithURL: URL]) && + (request = [OFHTTPRequest requestWithURL: URL]) && + R([request setHeaders: + [OFDictionary dictionaryWithObject: @"5" + forKey: @"Content-Length"]]) && R([client asyncPerformRequest: request context: nil])) [[OFRunLoop mainRunLoop] runUntilDate: [OFDate dateWithTimeIntervalSinceNow: 2]];