header(sv) works the same as it used, added headersWithName(sv) to get the whole vector

This commit is contained in:
B1rtek 2024-11-14 10:04:00 +01:00
parent ed493f8460
commit 9c61f74efd
2 changed files with 12 additions and 9 deletions

View file

@ -82,7 +82,8 @@ namespace geode::utils::web {
Result<> into(std::filesystem::path const& path) const;
std::vector<std::string> headers() const;
std::optional<std::string> header(std::string_view name, int index = 0) const;
std::optional<std::string> header(std::string_view name) const;
std::optional<std::vector<std::string>> headersWithName(std::string_view name) const;
};
class GEODE_DLL WebProgress final {

View file

@ -145,14 +145,16 @@ std::vector<std::string> WebResponse::headers() const {
return map::keys(m_impl->m_headers);
}
std::optional<std::string> WebResponse::header(std::string_view name, int index) const {
auto str = std::string(name);
if (m_impl->m_headers.contains(str)) {
const auto headersWithName = m_impl->m_headers.at(str);
if (headersWithName.size() > index) {
return headersWithName.at(index);
}
return std::nullopt;
std::optional<std::string> WebResponse::header(std::string_view name) const {
if (auto str = std::string(name); m_impl->m_headers.contains(str)) {
return m_impl->m_headers.at(str).at(0);
}
return std::nullopt;
}
std::optional<std::vector<std::string>> WebResponse::headersWithName(std::string_view name) const {
if (auto str = std::string(name); m_impl->m_headers.contains(str)) {
return m_impl->m_headers.at(str);
}
return std::nullopt;
}