Abort current connection (if any) with new request.
[yandex-traffic] / http_fetcher.cpp
1 #include <QtCore>
2 #include <QtNetwork>
3
4 #include "http_fetcher.hpp"
5
6 // --------------------------------------------------
7 // HttpFetcher
8 // --------------------------------------------------
9 HttpFetcher::HttpFetcher ()
10     : QObject ()
11 {
12     connect (&_http, SIGNAL (done (bool)), SLOT (requestDone (bool)));
13 }
14
15
16 void HttpFetcher::fetch (const QString& url)
17 {
18     QUrl u (url);
19
20     if (_http.currentId () != )
21         _http.abort ();
22
23     if (u.isValid ()) {
24         _http.setHost (u.host ());
25         _http.get (u.encodedPath (), &_buffer);
26     }
27 }
28
29
30 void HttpFetcher::requestDone (bool err)
31 {
32     if (err)
33         error (_http.error ());
34     else
35         done (_buffer.buffer ());
36     _buffer.close ();
37     _buffer.setBuffer (NULL);
38 }
39