]> git.mxchange.org Git - simgear.git/blobdiff - simgear/io/test_HTTP.cxx
Fix #1783: repeated error message on console
[simgear.git] / simgear / io / test_HTTP.cxx
index 442e9ffdbb4c790873d04641770ab5fbd4082fac..ea57837b4f04fb18ca6b5d4206337203eb559f87 100644 (file)
@@ -53,48 +53,23 @@ public:
     bool complete;
     bool failed;
     string bodyData;
-    string bodyContentType;
-    
+
     TestRequest(const std::string& url, const std::string method = "GET") : 
         HTTP::Request(url, method),
         complete(false)
     {
-      bodyContentType = "text/plain";
+
     }
     
-    std::map<string, string> sendHeaders;
     std::map<string, string> headers;
 protected:
-    string_list requestHeaders() const
-    {
-        string_list r;
-        std::map<string, string>::const_iterator it;
-        for (it = sendHeaders.begin(); it != sendHeaders.end(); ++it) {
-            r.push_back(it->first);
-        }
-        return r;
-    }
-    
-    string header(const string& name) const
-    {
-        std::map<string, string>::const_iterator it = sendHeaders.find(name);
-        if (it == sendHeaders.end()) {
-            return string();
-        }
-        
-        return it->second;
-    }
-    
-    virtual void responseHeadersComplete()
-    {
-    }
     
-    virtual void responseComplete()
+    virtual void onDone()
     {
         complete = true;
     }  
     
-    virtual void failure()
+    virtual void onFail()
     {
         failed = true;
     }
@@ -105,11 +80,6 @@ protected:
         bodyData += string(s, n);
     }
     
-    virtual std::string requestBodyType() const
-    {
-        return bodyContentType;
-    }
-    
     virtual void responseHeader(const string& header, const string& value)
     {
         headers[header] =  value;
@@ -409,6 +379,8 @@ class TestServer : public NetChannel
 public:   
     TestServer()
     {
+        Socket::initSockets();
+
         open();
         bind(NULL, 2000); // localhost, any port
         listen(5);
@@ -444,14 +416,14 @@ TestServer testServer;
 void waitForComplete(HTTP::Client* cl, TestRequest* tr)
 {
     SGTimeStamp start(SGTimeStamp::now());
-    while (start.elapsedMSec() <  1000) {
+    while (start.elapsedMSec() <  10000) {
         cl->update();
         testServer.poll();
         
         if (tr->complete) {
             return;
         }
-        SGTimeStamp::sleepForMSec(1);
+        SGTimeStamp::sleepForMSec(15);
     }
     
     cerr << "timed out" << endl;
@@ -460,14 +432,14 @@ void waitForComplete(HTTP::Client* cl, TestRequest* tr)
 void waitForFailed(HTTP::Client* cl, TestRequest* tr)
 {
     SGTimeStamp start(SGTimeStamp::now());
-    while (start.elapsedMSec() <  1000) {
+    while (start.elapsedMSec() <  10000) {
         cl->update();
         testServer.poll();
         
         if (tr->failed) {
             return;
         }
-        SGTimeStamp::sleepForMSec(1);
+        SGTimeStamp::sleepForMSec(15);
     }
     
     cerr << "timed out waiting for failure" << endl;
@@ -535,8 +507,8 @@ int main(int argc, char* argv[])
     {
         TestRequest* tr = new TestRequest("http://localhost:2000/test_headers");
         HTTP::Request_ptr own(tr);
-        tr->sendHeaders["X-Foo"] = "Bar";
-        tr->sendHeaders["X-AnotherHeader"] = "A longer value";
+        tr->requestHeader("X-Foo") = "Bar";
+        tr->requestHeader("X-AnotherHeader") = "A longer value";
         cl.makeRequest(tr);
 
         waitForComplete(&cl, tr);
@@ -721,7 +693,7 @@ int main(int argc, char* argv[])
     {
         cout << "POST" << endl;
         TestRequest* tr = new TestRequest("http://localhost:2000/test_post?foo=abc&bar=1234&username=johndoe", "POST");
-        tr->bodyContentType = "application/x-www-form-urlencoded";
+        tr->setBodyData("", "application/x-www-form-urlencoded");
         
         HTTP::Request_ptr own(tr);
         cl.makeRequest(tr);