diff --git a/lib/http_parser.cpp b/lib/http_parser.cpp index d4e6530e..4e2b6111 100644 --- a/lib/http_parser.cpp +++ b/lib/http_parser.cpp @@ -13,6 +13,12 @@ HTTP::Parser::Parser() { /// Completely re-initializes the HTTP::Parser, leaving it ready for either reading or writing usage. void HTTP::Parser::Clean() { + CleanPreserveHeaders(); + headers.clear(); +} + +/// Completely re-initializes the HTTP::Parser, leaving it ready for either reading or writing usage. +void HTTP::Parser::CleanPreserveHeaders() { seenHeaders = false; seenReq = false; getChunks = false; @@ -23,7 +29,6 @@ void HTTP::Parser::Clean() { protocol = "HTTP/1.1"; body.clear(); length = 0; - headers.clear(); vars.clear(); } @@ -138,13 +143,9 @@ void HTTP::Parser::SendResponse(std::string code, std::string message, Socket::C /// \param conn The connection to send over. void HTTP::Parser::StartResponse(std::string code, std::string message, HTTP::Parser & request, Socket::Connection & conn, bool bufferAllChunks) { std::string prot = request.protocol; - std::string contentType = GetHeader("Content-Type"); sendingChunks = (!bufferAllChunks && protocol == "HTTP/1.1" && request.GetHeader("Connection")!="close"); - Clean(); + CleanPreserveHeaders(); protocol = prot; - if (contentType.size()){ - SetHeader("Content-Type", contentType); - } if (sendingChunks){ SetHeader("Transfer-Encoding", "chunked"); } else { diff --git a/lib/http_parser.h b/lib/http_parser.h index 0080a38f..0204a045 100644 --- a/lib/http_parser.h +++ b/lib/http_parser.h @@ -35,6 +35,7 @@ namespace HTTP { void Chunkify(const char * data, unsigned int size, Socket::Connection & conn); void Proxy(Socket::Connection & from, Socket::Connection & to); void Clean(); + void CleanPreserveHeaders(); static std::string urlunescape(const std::string & in); static std::string urlencode(const std::string & in); std::string body;