Skip to content

Commit

Permalink
Add a getter for a bearer token from a request (#1755)
Browse files Browse the repository at this point in the history
* Add a getter for a bearer token from a request

* Replace a method for bearer token getter with a free function
  • Loading branch information
bugdea1er authored Jan 15, 2024
1 parent af2928d commit 4498019
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions httplib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 4498019

Please sign in to comment.