Do not bother making a METACUBE_FLAGS_HEADER block if it is empty.
[cubemap] / server.cpp
index e4ea647..8282a56 100644 (file)
@@ -470,16 +470,18 @@ void Server::construct_header(Client *client)
                        "\r\n" +
                        stream->stream_header;
        } else if (stream->encoding == Stream::STREAM_ENCODING_METACUBE) {
-               metacube_block_header hdr;
-               memcpy(hdr.sync, METACUBE_SYNC, sizeof(hdr.sync));
-               hdr.size = htonl(stream->stream_header.size());
-               hdr.flags = htonl(METACUBE_FLAGS_HEADER);
-
                client->header_or_error = stream->http_header +
                        "Content-encoding: metacube\r\n" +
-                       "\r\n" +
-                       string(reinterpret_cast<char *>(&hdr), sizeof(hdr)) +
-                       stream->stream_header;
+                       "\r\n";
+               if (!stream->stream_header.empty()) {
+                       metacube_block_header hdr;
+                       memcpy(hdr.sync, METACUBE_SYNC, sizeof(hdr.sync));
+                       hdr.size = htonl(stream->stream_header.size());
+                       hdr.flags = htonl(METACUBE_FLAGS_HEADER);
+                       client->header_or_error.append(
+                               string(reinterpret_cast<char *>(&hdr), sizeof(hdr)));
+               }
+               client->header_or_error.append(stream->stream_header);
        } else {
                assert(false);
        }