Commit 4bc40900 authored by vagrant's avatar vagrant
Browse files

Bug fixed on Content-length

parent f71e68d9
......@@ -142,11 +142,12 @@ int http_codec::encode_request(const LibItsHttp__TypesAndValues::Request& p_requ
for (int i = 0; i < headers.size_of(); i++) {
const LibItsHttp__TypesAndValues::HeaderLine& header = headers[i];
loggers::get_instance().log_msg("http_codec::encode_request: Processing header ", header.header__name());
p_encoding_buffer.put_cs(header.header__name());
p_encoding_buffer.put_cs(": ");
if (std::string(static_cast<const char*>(header.header__name())).compare("Content-length") == 0) { // Skip it, processed later
loggers::get_instance().log("http_codec::encode_request: Skip it");
continue;
} else {
p_encoding_buffer.put_cs(header.header__name());
p_encoding_buffer.put_cs(": ");
const OPTIONAL<LibItsHttp__TypesAndValues::charstring__list>& o = header.header__value();
if (o.ispresent()) {
const LibItsHttp__TypesAndValues::charstring__list& v = dynamic_cast<const OPTIONAL<LibItsHttp__TypesAndValues::charstring__list> &>(o);
......@@ -194,16 +195,18 @@ int http_codec::encode_request(const LibItsHttp__TypesAndValues::Request& p_requ
}
// Encode Content-length header
p_encoding_buffer.put_cs("Content-length: ");
if (_ec.length != 0) {
p_encoding_buffer.put_cs(int2str(_ec.length + 2/*Stand for the last CRLF*/));
loggers::get_instance().log("http_codec::encode_request: Content-length: %s", static_cast<const char*>(int2str(_ec.length + 2/*Stand for the last CRLF*/)));
p_encoding_buffer.put_cs(static_cast<const char*>(int2str(_ec.length + 2/*Stand for the last CRLF*/)));
_ec.is_content_length_present = 0x01;
} else {
p_encoding_buffer.put_cs("0");
_ec.is_content_length_present = 0x00;
}
loggers::get_instance().log("http_codec::encode_request: Content-length: %d - %x", _ec.length, _ec.is_content_length_present);
p_encoding_buffer.put_cs("\r\n");
// Add message body
p_encoding_buffer.put_cs("\r\n");
if (_ec.is_content_length_present == 0x01) {
loggers::get_instance().log_msg("http_codec::encode_request: Add body ", os);
......@@ -211,6 +214,7 @@ int http_codec::encode_request(const LibItsHttp__TypesAndValues::Request& p_requ
p_encoding_buffer.put_cs("\r\n");
}
loggers::get_instance().log_to_hexa("<<< http_codec::encode_request: ", p_encoding_buffer);
return 0;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment