Fix for sending non-chunked when connection:close is encountered
This commit is contained in:
parent
9d34ad7f5b
commit
701b421d9c
2 changed files with 11 additions and 4 deletions
|
@ -138,9 +138,15 @@ void HTTP::Parser::SendResponse(std::string code, std::string message, Socket::C
|
||||||
/// \param request The HTTP request to respond to.
|
/// \param request The HTTP request to respond to.
|
||||||
/// \param conn The connection to send over.
|
/// \param conn The connection to send over.
|
||||||
void HTTP::Parser::StartResponse(std::string code, std::string message, HTTP::Parser & request, Socket::Connection & conn) {
|
void HTTP::Parser::StartResponse(std::string code, std::string message, HTTP::Parser & request, Socket::Connection & conn) {
|
||||||
protocol = request.protocol;
|
std::string prot = request.protocol;
|
||||||
body = "";
|
std::string contentType = GetHeader("Content-Type");
|
||||||
if (protocol == "HTTP/1.1") {
|
sendingChunks = (protocol == "HTTP/1.1" && request.GetHeader("Connection")!="close");
|
||||||
|
Clean();
|
||||||
|
protocol = prot;
|
||||||
|
if (contentType.size()){
|
||||||
|
SetHeader("Content-Type", contentType);
|
||||||
|
}
|
||||||
|
if (sendingChunks){
|
||||||
SetHeader("Transfer-Encoding", "chunked");
|
SetHeader("Transfer-Encoding", "chunked");
|
||||||
} else {
|
} else {
|
||||||
SetBody("");
|
SetBody("");
|
||||||
|
@ -546,7 +552,7 @@ void HTTP::Parser::Chunkify(std::string & bodypart, Socket::Connection & conn) {
|
||||||
/// \param conn The connection to use for sending.
|
/// \param conn The connection to use for sending.
|
||||||
void HTTP::Parser::Chunkify(const char * data, unsigned int size, Socket::Connection & conn) {
|
void HTTP::Parser::Chunkify(const char * data, unsigned int size, Socket::Connection & conn) {
|
||||||
static char hexa[] = "0123456789abcdef";
|
static char hexa[] = "0123456789abcdef";
|
||||||
if (protocol == "HTTP/1.1") {
|
if (sendingChunks) {
|
||||||
//prepend the chunk size and \r\n
|
//prepend the chunk size and \r\n
|
||||||
if (!size){
|
if (!size){
|
||||||
conn.SendNow("0\r\n\r\n\r\n", 7);
|
conn.SendNow("0\r\n\r\n\r\n", 7);
|
||||||
|
|
|
@ -47,6 +47,7 @@ namespace HTTP {
|
||||||
bool seenHeaders;
|
bool seenHeaders;
|
||||||
bool seenReq;
|
bool seenReq;
|
||||||
bool getChunks;
|
bool getChunks;
|
||||||
|
bool sendingChunks;
|
||||||
unsigned int doingChunk;
|
unsigned int doingChunk;
|
||||||
bool parse(std::string & HTTPbuffer);
|
bool parse(std::string & HTTPbuffer);
|
||||||
void parseVars(std::string data);
|
void parseVars(std::string data);
|
||||||
|
|
Loading…
Add table
Reference in a new issue