// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
+#include <boost/utility/string_ref.hpp>
+
#include <curl/curl.h>
#include <curl/easy.h>
#include <curl/multi.h>
int RGWHTTPHeadersCollector::receive_header(void * const ptr, const size_t len)
{
- const std::string header_line(static_cast<const char * const>(ptr), len);
+ const boost::string_ref header_line(static_cast<const char * const>(ptr), len);
/* We're tokening the line that way due to backward compatibility. */
const size_t sep_loc = header_line.find_first_of(" \t:");
- if (std::string::npos == sep_loc) {
+ if (boost::string_ref::npos == sep_loc) {
/* Wrongly formatted header? Just skip it. */
return 0;
}
return 0;
}
+ const auto value_part = header_line.substr(sep_loc + 1);
+
/* Skip spaces and tabs after the separator. */
- const size_t val_loc_s = header_line.find_first_not_of(' ', sep_loc + 1);
- const size_t val_loc_e = header_line.find_first_of("\r\n", sep_loc + 1);
+ const size_t val_loc_s = value_part.find_first_not_of(' ');
+ const size_t val_loc_e = value_part.find_first_of("\r\n");
- if (std::string::npos == val_loc_s || std::string::npos == val_loc_e) {
+ if (boost::string_ref::npos == val_loc_s ||
+ boost::string_ref::npos == val_loc_e) {
/* Empty value case. */
found_headers.emplace(name, header_value_t());
} else {
found_headers.emplace(name, header_value_t(
- header_line.substr(val_loc_s, val_loc_e - val_loc_s)));
+ value_part.substr(val_loc_s, val_loc_e - val_loc_s)));
}
return 0;