]> git.sesse.net Git - cubemap/blobdiff - httpinput.cpp
Fix a memory leak with raw inputs.
[cubemap] / httpinput.cpp
index 5a93969ff4801c425ca9dc418cc030147e12c808..78e73a10eb9afeb5724ebbaa4efa6b0d9cb36f57 100644 (file)
 
 using namespace std;
 
+namespace {
+
+string host_header(const string &host, const string &port)
+{
+       if (port == "http" || atoi(port.c_str()) == 80) {
+               return host;
+       } else {
+               return host + ":" + port;
+       }
+}
+
+}  // namespace
+
 extern ServerPool *servers;
 
 HTTPInput::HTTPInput(const string &url, Input::Encoding encoding)
@@ -339,7 +352,7 @@ void HTTPInput::do_work()
                                        state = CLOSING_SOCKET;
                                } else {
                                        state = SENDING_REQUEST;
-                                       request = "GET " + path + " HTTP/1.0\r\nUser-Agent: cubemap\r\n\r\n";
+                                       request = "GET " + path + " HTTP/1.0\r\nHost: " + host_header(host, port) + "\r\nUser-Agent: cubemap\r\n\r\n";
                                        request_bytes_sent = 0;
                                }
 
@@ -482,7 +495,6 @@ void HTTPInput::do_work()
 
 void HTTPInput::process_data(char *ptr, size_t bytes)
 {
-       pending_data.insert(pending_data.end(), ptr, ptr + bytes);
        {
                MutexLock mutex(&stats_mutex);
                stats.bytes_received += bytes;
@@ -496,6 +508,7 @@ void HTTPInput::process_data(char *ptr, size_t bytes)
        }
 
        assert(encoding == Input::INPUT_ENCODING_METACUBE);
+       pending_data.insert(pending_data.end(), ptr, ptr + bytes);
 
        for ( ;; ) {
                // If we don't have enough data (yet) for even the Metacube header, just return.