curl_wrapper/src/types.cpp

44 lines
1.2 KiB
C++
Raw Normal View History

/* This file is part of curl_wrapper.
* Copyright © 2020 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "types.hpp"
#include <boost/regex.hpp>
#include <string>
#include <string_view>
namespace curl_wrapper
{
std::string answer::get_header(const std::string_view field) const
{
const boost::regex re_field(string("^") + field.data()
+ R"(:\s+([^\r\n]+))",
boost::regex::icase);
boost::cmatch match;
boost::regex_search(headers.c_str(), match, re_field);
if (match[1].matched)
{
return match[1].str();
}
return {};
}
} // namespace curl_wrapper