orotool/src/nap/quick_rest.cpp

50 lines
1.5 KiB
C++
Raw Normal View History

2020-08-29 14:28:47 +01:00
/* Copyright 2020, Michele Santullo
* This file is part of orotool.
*
* Orotool is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Orotool 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Orotool. If not, see <http://www.gnu.org/licenses/>.
*/
#include "quick_rest.hpp"
#include "private/page_fetch.hpp"
#include <cassert>
2020-08-29 14:28:47 +01:00
namespace nap {
2020-09-03 01:59:33 +01:00
QuickRest::QuickRest (std::size_t body_padding) :
m_body_padding(body_padding)
{
}
2020-08-29 14:28:47 +01:00
void QuickRest::add_headers (std::initializer_list<HeaderPairView> headers) {
m_header_lines.reserve(m_header_lines.size() + headers.size());
2020-08-29 14:28:47 +01:00
for (const auto& entry : headers) {
std::string line;
line.reserve(entry.first.size() + 2 + entry.second.size());
line.append(entry.first);
line.append(": ");
line.append(entry.second);
m_header_lines.push_back(std::move(line));
2020-08-29 14:28:47 +01:00
}
}
void QuickRest::set_user_agent (std::string&& name) {
m_user_agent = std::move(name);
}
HttpResponse QuickRest::fetch (std::string_view url) {
2020-09-03 01:59:33 +01:00
return page_fetch(std::string(url), m_user_agent, m_header_lines, m_body_padding);
2020-08-29 14:28:47 +01:00
}
} //namespace nap