fork download
  1. #include <stdlib.h>
  2. #include <iostream>
  3. #include <sstream>
  4. #include <string>
  5. #include <map>
  6. #include <boost/algorithm/string.hpp>
  7.  
  8. int main(int argc, char* argv[]) {
  9. std::string raw = "HTTP/1.1 200 OK\r\n"
  10. "Content-Type: image/jpeg; charset=utf-8\r\n"
  11. "Content-Length: 123\r\n\r\n";
  12.  
  13. std::map<std::string, std::string> headers;
  14. std::istringstream rawstream(raw);
  15. std::string header;
  16. while (std::getline(rawstream, header) && header != "\r") {
  17. std::string::size_type index = header.find(':');
  18. if (index != std::string::npos) {
  19. headers.insert(std::make_pair(
  20. boost::algorithm::to_lower_copy(boost::algorithm::trim_copy(header.substr(0, index))),
  21. boost::algorithm::trim_copy(header.substr(index + 1))
  22. ));
  23. }
  24. }
  25.  
  26. for (auto& kv : headers) {
  27. std::cout << kv.first << ": " << kv.second << std::endl;
  28. }
  29.  
  30. return 0;
  31. }
  32.  
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
content-length: 123
content-type: image/jpeg; charset=utf-8