Commit 2a2e510b authored by YannGarcia's avatar YannGarcia
Browse files

Bug fixed in http_codec::encode_response()

parent fee1e6e4
Loading
Loading
Loading
Loading
+11 −6
Original line number Diff line number Diff line
@@ -260,6 +260,7 @@ int http_codec::encode_response (const LibItsHttp__TypesAndValues::Response& p_r
    const LibItsHttp__TypesAndValues::Header& header = headers[i];
    loggers::get_instance().log_msg("http_codec::encode_response: Processing header ", header.header__name());
    if (std::string(static_cast<const char*>(header.header__name())).compare("Content-Length") == 0) {
      loggers::get_instance().log("http_codec::encode_response: Skip it");
      continue;
    } else {
      p_encoding_buffer.put_cs(header.header__name());
@@ -302,16 +303,18 @@ int http_codec::encode_response (const LibItsHttp__TypesAndValues::Response& p_r
      _ec.length = os.lengthof();
      _ec.is_content_length_present = 0x01;
    }
    loggers::get_instance().log("http_codec::encode_request: length=%d", _ec.length);
    loggers::get_instance().log("http_codec::encode_response: length=%d", _ec.length);
  } else {
    loggers::get_instance().log("http_codec::encode_request: HTTP body field not present");
    loggers::get_instance().log("http_codec::encode_response: HTTP body field not present");
    _ec.length = 0;
    _ec.is_content_length_present = 0x00;
  }

  // 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_response: 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)));
    _ec.is_content_length_present = 0x01;
  } else {
    p_encoding_buffer.put_cs("0");
@@ -320,10 +323,12 @@ int http_codec::encode_response (const LibItsHttp__TypesAndValues::Response& p_r
  loggers::get_instance().log("http_codec::encode_response: 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.length != 0) {
  if (_ec.is_content_length_present == 0x01) {
    loggers::get_instance().log_msg("http_codec::encode_response: Add body ", os);
    p_encoding_buffer.put_os(os);
    p_encoding_buffer.put_cs("\r\n");
    //    p_encoding_buffer.put_cs("\r\n");
  }
   
  return 0;