Match headers case-insensitively.

This commit is contained in:
tastytea 2019-10-06 14:35:43 +02:00
parent 2fa3bff89c
commit d43b1c72db
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
2 changed files with 7 additions and 3 deletions

View File

@ -20,6 +20,7 @@
#include <utility> #include <utility>
#include <iostream> #include <iostream>
#include <exception> #include <exception>
#include <algorithm>
#include <Poco/Net/FilePartSource.h> #include <Poco/Net/FilePartSource.h>
#include <Poco/URI.h> #include <Poco/URI.h>
#include "version.hpp" #include "version.hpp"
@ -265,10 +266,13 @@ return_call API::register_app2(const string &client_id,
return ret; return ret;
} }
const string API::get_header(const std::string &header) const const string API::get_header(std::string header) const
{ {
string headers; string headers;
_http.get_headers(headers); _http.get_headers(headers);
std::transform(headers.begin(), headers.end(), headers.begin(), ::tolower);
std::transform(header.begin(), header.end(), header.begin(), ::tolower);
size_t startpos = headers.find(header + ':'); size_t startpos = headers.find(header + ':');
if (startpos != std::string::npos) if (startpos != std::string::npos)
{ {

View File

@ -411,7 +411,7 @@ namespace Mastodon
string &access_token); string &access_token);
/*! /*!
* @brief Gets the header from the last answer. * @brief Gets the header from the last answer. Case insensitive.
* *
* @param header The header to get * @param header The header to get
* *
@ -419,7 +419,7 @@ namespace Mastodon
* *
* @since before 0.11.0 * @since before 0.11.0
*/ */
const string get_header(const string &header) const; const string get_header(string header) const;
/*! /*!
* @brief Turn exceptions on or off. Defaults to off. * @brief Turn exceptions on or off. Defaults to off.