Skip to content

Commit 8e7f82f

Browse files
bugdea1erzkx
authored and
zkx
committed
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 (cherry picked from commit 4498019)
1 parent bd7200b commit 8e7f82f

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
@@ -746,6 +746,8 @@ void default_socket_options(socket_t sock);
746746

747747
const char *status_message(int status);
748748

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

751753
class MatcherBase {
@@ -1944,6 +1946,15 @@ inline const char *status_message(int status) {
19441946
}
19451947
}
19461948

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

0 commit comments

Comments
 (0)