Fixes issue with binary data (e.g. image.png) being corrupted when sent in response
Removes unnecessary optimization
Prepares for variable sized clientHeader / Body buffer
Removes m_receivedBytes from connection
1. Binary data
ResponseBuilder has a static stringstream which contains response header and body
Binary data was corrupted probably because body was added via << operator to the stream
solution: only use stringstream for headers, as only for them conversions are needed (e.g. size for content-size)
image.png can now be sent.
cgi should not need zero terminator anymore
2 Unnecessary optimization
Stringstream is reused, so that it's only constructed once
It was also used in a unnecessary efficient way by using a c_str() "hack" (see #20 for more details)
now just clear the stream like normal people to avoid additional problems
if really needed optimization can be put back in
3. Prepare for variable sized buffers
we talked about using std::string as buffer may not be optimal as the container is made for c strings (with zero terminator as delimiter). For example std::string += char[] invokes a strlen() for the char array which is problematic for binary data
more "appropriate" would be std::vector< char >; looked at it, would prob require a bigger rewrite
left connection buffer as std::string
changed local buffer to use a std::vector< char >, so it can be resized (variable array is an C99 extension). At first wanted to also use std::string. But .clear() is not guarenteed to not reallocate
use explicit .append(start, size) method to append to connection buffer
4. Remove receivedBytes
class Connection had variable receivedBytes
Wasn't really used, as receivedBytes is the same as buffer.size(). Therefore removed.
Summary
1. Binary data
2 Unnecessary optimization
3. Prepare for variable sized buffers
std::string += char[]
invokes a strlen() for the char array which is problematic for binary data4. Remove receivedBytes