Index: /trunk/FACT++/src/magicweather.cc
===================================================================
--- /trunk/FACT++/src/magicweather.cc	(revision 13191)
+++ /trunk/FACT++/src/magicweather.cc	(revision 13192)
@@ -1,3 +1,7 @@
 #include <boost/bind.hpp>
+
+#include <string>    // std::string
+#include <algorithm> // std::transform
+#include <cctype>    // std::tolower
 
 #include "FACT.h"
@@ -82,6 +86,4 @@
         }
 
-        PostClose(false);
-
         const string str(fArray.data(), bytes_received);
         memset(fArray.data(), 0, fArray.size());
@@ -95,4 +97,6 @@
 
         int hh=0, mm=0, ss=0, y=0, m=0, d=0;
+
+        bool keepalive = false;
 
         stringstream is(str);
@@ -108,60 +112,64 @@
             if (isheader)
             {
-                /*
-                 if (line.substr(0, 16)=="Content-Length: ")
-                 {
-                     fSize = atoi(line.substr(16).data());
-                     cout << "Size==" << fSize << endl;
-                 }
-
-                 if (line.substr(0, 15)=="Last-Modified: ")
-                     cout << "Last==" << line.substr(15).data() << endl;
-                */
+                const size_t p = line.find_first_of(": ");
+                if (p==string::npos)
+                    continue;
+
+                std::transform(line.begin(), line.end(), line.begin(), (int(&)(int))std::tolower);
+
+                const string key = line.substr(0, p);
+                const string val = line.substr(p+2);
+
+                if (key=="connection" && val=="keep-alive")
+                    keepalive = true;
             }
             else
             {
                 if (line.substr(0, 2)=="ST")
-                    data.fStatus = atoi(line.substr(2).data());
+                    data.fStatus = stoi(line.substr(2));
 
                 if (line.substr(0, 2)=="TE")
-                    data.fTemp = atof(line.substr(2).data());
+                    data.fTemp = stof(line.substr(2));
 
                 if (line.substr(0, 2)=="DP")
-                    data.fDew = atof(line.substr(2).data());
+                    data.fDew = stof(line.substr(2));
 
                 if (line.substr(0, 3)=="HUM")
-                    data.fHum = atof(line.substr(3).data());
+                    data.fHum = stof(line.substr(3));
 
                 if (line.substr(0, 2)=="WS")
-                    data.fWind = atof(line.substr(2).data());
+                    data.fWind = stof(line.substr(2));
 
                 if (line.substr(0, 3)=="MWD")
-                    data.fDir = atof(line.substr(3).data());
+                    data.fDir = stof(line.substr(3));
 
                 if (line.substr(0, 2)=="WP")
-                    data.fGusts = atof(line.substr(2).data());
+                    data.fGusts = stof(line.substr(2));
 
                 if (line.substr(0, 5)=="PRESS")
-                    data.fPress = atof(line.substr(5).data());
+                    data.fPress = stof(line.substr(5));
 
                 if (line.substr(0, 4)=="HOUR")
-                    hh = atoi(line.substr(4).data());
+                    hh = stoi(line.substr(4));
 
                 if (line.substr(0, 6)=="MINUTS")
-                    mm = atoi(line.substr(6).data());
+                    mm = stoi(line.substr(6));
 
                 if (line.substr(0, 7)=="SECONDS")
-                    ss = atoi(line.substr(7).data());
+                    ss = stoi(line.substr(7));
 
                 if (line.substr(0, 4)=="YEAR")
-                    y = atoi(line.substr(4).data());
+                    y = stoi(line.substr(4));
 
                 if (line.substr(0, 5)=="MONTH")
-                    m = atoi(line.substr(5).data());
+                    m = stoi(line.substr(5));
 
                 if (line.substr(0, 3)=="DAY")
-                    d = atoi(line.substr(3).data());
+                    d = stoi(line.substr(3));
             }
         }
+
+        if (!keepalive)
+            PostClose(false);
 
         try
@@ -175,5 +183,5 @@
                 << data.fTemp << "°C H=" << data.fHum << "% P="
                 << data.fPress << "hPa Td=" << data.fDew << "°C V="
-                << data.fWind << "km/h dir=" << data.fDir << "deg" << endl;
+                << data.fWind << "km/h dir=" << data.fDir << "deg";
             Message(msg);
 
@@ -201,6 +209,16 @@
     {
         const string dir = "/site/weather/weather_data.txt";
-
-        const string cmd = "GET "+dir+" HTTP/1.1\r\nHost: www.fact-project.org\r\n\r\n";
+        const string cmd =
+            "GET "+dir+" HTTP/1.1\r\n"
+            "Accept: */*\r\n"
+            "Content-Type: application/octet-stream\r\n"
+            "User-Agent: FACT\r\n"
+            "Host: www.fact-project.org\r\n"
+            "Pragma: no-cache\r\n"
+            "Cache-Control: no-cache\r\n"
+            "Expires: 0\r\n"
+            "Connection: Keep-Alive\r\n"
+            "Cache-Control: max-age=0\r\n"
+            "\r\n";
         PostMessage(cmd);
     }
