Updated documentation and improved inserting new vectors into headers maps

This commit is contained in:
b1rtek 2024-11-14 22:56:23 +01:00
parent 9c61f74efd
commit e2866d1907
2 changed files with 11 additions and 7 deletions

View file

@ -83,6 +83,14 @@ namespace geode::utils::web {
std::vector<std::string> headers() const;
std::optional<std::string> header(std::string_view name) const;
/**
* Retrieves a list of all headers from the response with a given name - there can be
* multiple headers with the same name, such as Set-Cookie, with each cookie in a separate
* header
* @param name name of the header
* @return std::optional<std::vector<std::string>>
*/
std::optional<std::vector<std::string>> headersWithName(std::string_view name) const;
};
@ -287,7 +295,7 @@ namespace geode::utils::web {
/**
* Gets the request headers
*
* @return std::unordered_map<std::string, std::string>
* @return std::unordered_map<std::string, std::vector<std::string>>
*/
std::unordered_map<std::string, std::vector<std::string>> getHeaders() const;

View file

@ -418,9 +418,7 @@ WebTask WebRequest::send(std::string_view method, std::string_view url) {
if (headers.contains(key)) {
headers.at(key).push_back(value);
} else {
std::vector<std::string> headerValues;
headerValues.push_back(value);
headers.insert_or_assign(key, headerValues);
headers.insert_or_assign(key, std::vector{value});
}
}
return size * nitems;
@ -529,9 +527,7 @@ WebRequest& WebRequest::header(std::string_view name, std::string_view value) {
if (m_impl->m_headers.contains(strName)) {
m_impl->m_headers.at(strName).push_back(strValue);
} else {
std::vector<std::string> headerValues;
headerValues.push_back(strValue);
m_impl->m_headers.insert_or_assign(strName, headerValues);
m_impl->m_headers.insert_or_assign(strName, std::vector{strValue});
}
return *this;