Skip to content

Commit 4498019

Browse files
authored
Add a getter for a bearer token from a request (yhirose#1755)
* Add a getter for a bearer token from a request * Replace a method for bearer token getter with a free function
1 parent af2928d commit 4498019

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

httplib.h

+11
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,8 @@ void default_socket_options(socket_t sock);
745745

746746
const char *status_message(int status);
747747

748+
std::string get_bearer_token_auth(const Request &req);
749+
748750
namespace detail {
749751

750752
class MatcherBase {
@@ -1943,6 +1945,15 @@ inline const char *status_message(int status) {
19431945
}
19441946
}
19451947

1948+
inline std::string get_bearer_token_auth(const Request &req) {
1949+
if (req.has_header("Authorization")) {
1950+
static std::string BearerHeaderPrefix = "Bearer ";
1951+
return req.get_header_value("Authorization")
1952+
.substr(BearerHeaderPrefix.length());
1953+
}
1954+
return "";
1955+
}
1956+
19461957
template <class Rep, class Period>
19471958
inline Server &
19481959
Server::set_read_timeout(const std::chrono::duration<Rep, Period> &duration) {

0 commit comments

Comments
 (0)