mirror of
https://github.com/yhirose/cpp-httplib
synced 2024-11-21 06:26:02 -07:00
Add a getter for a bearer token from a request (#1755)
* Add a getter for a bearer token from a request * Replace a method for bearer token getter with a free function
This commit is contained in:
parent
af2928d316
commit
449801990f
1 changed files with 11 additions and 0 deletions
11
httplib.h
11
httplib.h
|
@ -745,6 +745,8 @@ void default_socket_options(socket_t sock);
|
|||
|
||||
const char *status_message(int status);
|
||||
|
||||
std::string get_bearer_token_auth(const Request &req);
|
||||
|
||||
namespace detail {
|
||||
|
||||
class MatcherBase {
|
||||
|
@ -1943,6 +1945,15 @@ inline const char *status_message(int status) {
|
|||
}
|
||||
}
|
||||
|
||||
inline std::string get_bearer_token_auth(const Request &req) {
|
||||
if (req.has_header("Authorization")) {
|
||||
static std::string BearerHeaderPrefix = "Bearer ";
|
||||
return req.get_header_value("Authorization")
|
||||
.substr(BearerHeaderPrefix.length());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
template <class Rep, class Period>
|
||||
inline Server &
|
||||
Server::set_read_timeout(const std::chrono::duration<Rep, Period> &duration) {
|
||||
|
|
Loading…
Reference in a new issue