]> git.tdb.fi Git - libs/net.git/blobdiff - source/client.cpp
Rename data to content in Message
[libs/net.git] / source / client.cpp
index fde7c8d7bd20f48d10ea1f51dda748bb092249a9..a4bc342f38c2738c27047f6a80818196fbd17396 100644 (file)
@@ -36,8 +36,10 @@ Client::~Client()
 
 void Client::use_event_dispatcher(IO::EventDispatcher *ed)
 {
+       if(event_disp && sock)
+               event_disp->remove(*sock);
        event_disp=ed;
-       if(sock)
+       if(event_disp && sock)
                event_disp->add(*sock);
 }
 
@@ -66,10 +68,11 @@ void Client::start_request(const Request &r)
        in_buf.clear();
 }
 
-void Client::get_url(const std::string &url)
+const Response *Client::get_url(const std::string &url)
 {
        start_request(Request::from_url(url));
        wait_response();
+       return response;
 }
 
 void Client::tick()
@@ -130,12 +133,13 @@ void Client::data_available()
                if(in_buf.find("\r\n\r\n")!=string::npos || in_buf.find("\n\n")!=string::npos)
                {
                        response=new Response(Response::parse(in_buf));
+                       response->set_user_data(request->get_user_data());
                        in_buf=string();
                }
        }
        else
        {
-               len=response->parse_data(in_buf);
+               len=response->parse_content(in_buf);
                in_buf.erase(0, len);
        }