+
+ cout << "done 404 test" << endl;
+
+ {
+ TestRequest* tr = new TestRequest("http://localhost:2000/test_args?foo=abc&bar=1234&username=johndoe");
+ HTTP::Request_ptr own(tr);
+ cl.makeRequest(tr);
+ waitForComplete(&cl, tr);
+ COMPARE(tr->responseCode(), 200);
+ }
+
+ cout << "done1" << endl;
+// test HTTP/1.0
+ {
+ TestRequest* tr = new TestRequest("http://localhost:2000/test_1_0");
+ HTTP::Request_ptr own(tr);
+ cl.makeRequest(tr);
+ waitForComplete(&cl, tr);
+ COMPARE(tr->responseCode(), 200);
+ COMPARE(tr->responseLength(), strlen(BODY1));
+ COMPARE(tr->bodyData, string(BODY1));
+ }
+
+ cout << "done2" << endl;
+// test HTTP/1.1 Connection::close
+ {
+ TestRequest* tr = new TestRequest("http://localhost:2000/test_close");
+ HTTP::Request_ptr own(tr);
+ cl.makeRequest(tr);
+ waitForComplete(&cl, tr);
+ COMPARE(tr->responseCode(), 200);
+ COMPARE(tr->responseLength(), strlen(BODY1));
+ COMPARE(tr->bodyData, string(BODY1));
+ }
+ cout << "done3" << endl;
+// test connectToHost failure
+/*
+ {
+ TestRequest* tr = new TestRequest("http://not.found/something");
+ HTTP::Request_ptr own(tr);
+ cl.makeRequest(tr);
+ waitForFailed(tr);
+ COMPARE(tr->responseCode(), -1);
+ }
+ */
+// test proxy
+ {
+ cl.setProxy("localhost", 2000);
+ TestRequest* tr = new TestRequest("http://www.google.com/test2");
+ HTTP::Request_ptr own(tr);
+ cl.makeRequest(tr);
+ waitForComplete(&cl, tr);
+ COMPARE(tr->responseCode(), 200);
+ COMPARE(tr->responseLength(), body2Size);
+ COMPARE(tr->bodyData, string(body2, body2Size));
+ }
+
+ {
+ cl.setProxy("localhost", 2000, "ABCDEF");
+ TestRequest* tr = new TestRequest("http://www.google.com/test3");
+ HTTP::Request_ptr own(tr);
+ cl.makeRequest(tr);
+ waitForComplete(&cl, tr);
+ COMPARE(tr->responseCode(), 200);
+ COMPARE(tr->responseBytesReceived(), body2Size);
+ COMPARE(tr->bodyData, string(body2, body2Size));
+ }
+
+// pipelining
+ cout << "testing HTTP 1.1 pipelineing" << endl;
+
+ {
+ cl.setProxy("", 80);
+ TestRequest* tr = new TestRequest("http://localhost:2000/test1");
+ HTTP::Request_ptr own(tr);
+ cl.makeRequest(tr);
+
+
+ TestRequest* tr2 = new TestRequest("http://localhost:2000/testLorem");
+ HTTP::Request_ptr own2(tr2);
+ cl.makeRequest(tr2);
+
+ TestRequest* tr3 = new TestRequest("http://localhost:2000/test1");
+ HTTP::Request_ptr own3(tr3);
+ cl.makeRequest(tr3);
+
+ waitForComplete(&cl, tr3);
+ VERIFY(tr->complete);
+ VERIFY(tr2->complete);
+ COMPARE(tr->bodyData, string(BODY1));
+
+ COMPARE(tr2->responseLength(), strlen(BODY3));
+ COMPARE(tr2->responseBytesReceived(), strlen(BODY3));
+ COMPARE(tr2->bodyData, string(BODY3));
+
+ COMPARE(tr3->bodyData, string(BODY1));
+ }
+
+// multiple requests with an HTTP 1.0 server
+ {
+ cout << "http 1.0 multiple requests" << endl;
+
+ cl.setProxy("", 80);
+ TestRequest* tr = new TestRequest("http://localhost:2000/test_1_0/A");
+ HTTP::Request_ptr own(tr);
+ cl.makeRequest(tr);
+
+ TestRequest* tr2 = new TestRequest("http://localhost:2000/test_1_0/B");
+ HTTP::Request_ptr own2(tr2);
+ cl.makeRequest(tr2);
+
+ TestRequest* tr3 = new TestRequest("http://localhost:2000/test_1_0/C");
+ HTTP::Request_ptr own3(tr3);
+ cl.makeRequest(tr3);
+
+ waitForComplete(&cl, tr3);
+ VERIFY(tr->complete);
+ VERIFY(tr2->complete);
+
+ COMPARE(tr->responseLength(), strlen(BODY1));
+ COMPARE(tr->responseBytesReceived(), strlen(BODY1));
+ COMPARE(tr->bodyData, string(BODY1));
+
+ COMPARE(tr2->responseLength(), strlen(BODY3));
+ COMPARE(tr2->responseBytesReceived(), strlen(BODY3));
+ COMPARE(tr2->bodyData, string(BODY3));
+ COMPARE(tr3->bodyData, string(BODY1));
+ }
+
+// POST
+ {
+ cout << "POST" << endl;
+ TestRequest* tr = new TestRequest("http://localhost:2000/test_post?foo=abc&bar=1234&username=johndoe", "POST");
+ HTTP::Request_ptr own(tr);
+ cl.makeRequest(tr);
+ waitForComplete(&cl, tr);
+ COMPARE(tr->responseCode(), 204);
+ }
+
+ // test_zero_length_content
+ {
+ cout << "zero-length-content-response" << endl;
+ TestRequest* tr = new TestRequest("http://localhost:2000/test_zero_length_content");
+ HTTP::Request_ptr own(tr);
+ cl.makeRequest(tr);
+ waitForComplete(&cl, tr);
+ COMPARE(tr->responseCode(), 200);
+ COMPARE(tr->bodyData, string());
+ COMPARE(tr->responseBytesReceived(), 0);
+ }
+