I solved myself the problem, which is non trivial.
Web server can use different scheme for separate header lines.
You can have
'\n' or '\r\n' or '\n\r'.
Believe me beacause I tested a lot of embedded web server (not the bigger ones).
The (most) important part of the header is the Content-Length.
If you (as me) are planning to change the body, you must carefull re-write the Content-Length value.
Follow the code.
The "line" variable is a line you want to analyze, for example (Content-Length). It is simple to extract it from the header
Qt Code:
  1. int Util::getCR(const QByteArray &line)
  2. {
  3. int c = 0;
  4. char ch;
  5. QChar sc;
  6. for(int i=0;i<line.size();i++)
  7. {
  8. sc = line.at(i);
  9. if (sc.isDigit())
  10. ch = sc.unicode() - '0';
  11. //qDebug()<<"UTIL getCR byte"<<line.at(i)<<sc.unicode()*1;;
  12.  
  13.  
  14. if (c == 13)
  15.  
  16. {
  17. // We found CR ASCCI '0D'
  18. // Check if there is a LF
  19.  
  20. if (i == line.size()-1)
  21. {
  22. sc = line.at(i+1);
  23. c = sc.unicode() * 1;
  24. if (c == 10)
  25. return i+1;
  26. }
  27. else
  28. return i;
  29.  
  30. }
  31. else
  32. // Do the same but first is '0A'
  33. if ( c == 10)
  34. {
  35. // We found CR ASCCI '0D'
  36. // Check if there is a LF
  37.  
  38. if (i == line.size()-1)
  39. {
  40. sc = line.at(i+1);
  41. c = sc.unicode() * 1;
  42. if (c == 13)
  43. return i+1;
  44. }
  45. else
  46. return i;
  47. }
  48. }
  49.  
  50.  
  51.  
  52. }
To copy to clipboard, switch view to plain text mode