From 4f67773a256f722e7ccaf9018703b435fa02becb Mon Sep 17 00:00:00 2001 From: eidheim Date: Sat, 18 Nov 2017 14:13:05 +0100 Subject: [PATCH] Client can now send chunked transfer encoded content --- client_http.hpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/client_http.hpp b/client_http.hpp index a28b817..6803afc 100644 --- a/client_http.hpp +++ b/client_http.hpp @@ -252,8 +252,14 @@ namespace SimpleWeb { }; std::ostream write_stream(session->request_streambuf.get()); - if(content.size() > 0) - write_stream << "Content-Length: " << content.size() << "\r\n"; + if(content.size() > 0) { + auto header_it = header.find("Content-Length"); + if(header_it == header.end()) { + header_it = header.find("Transfer-Encoding"); + if(header_it == header.end() || header_it->second != "chunked") + write_stream << "Content-Length: " << content.size() << "\r\n"; + } + } write_stream << "\r\n" << content; @@ -314,8 +320,14 @@ namespace SimpleWeb { auto content_length = content.tellg(); content.seekg(0, std::ios::beg); std::ostream write_stream(session->request_streambuf.get()); - if(content_length > 0) - write_stream << "Content-Length: " << content_length << "\r\n"; + if(content_length > 0) { + auto header_it = header.find("Content-Length"); + if(header_it == header.end()) { + header_it = header.find("Transfer-Encoding"); + if(header_it == header.end() || header_it->second != "chunked") + write_stream << "Content-Length: " << content_length << "\r\n"; + } + } write_stream << "\r\n"; if(content_length > 0) write_stream << content.rdbuf();