Skip to content

Commit a3b7165

Browse files
committed
add support for basic authentication
1 parent e8b3509 commit a3b7165

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

Release/src/http/client/http_client_asio.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,12 @@ class asio_context : public request_context, public std::enable_shared_from_this
633633
{
634634
extra_headers.append(ctx->generate_basic_proxy_auth_header());
635635
}
636-
636+
637+
if (ctx->m_http_client->client_config().credentials().is_set())
638+
{
639+
extra_headers.append(ctx->generate_basic_auth_header());
640+
}
641+
637642
// Check user specified transfer-encoding.
638643
std::string transferencoding;
639644
if (ctx->m_request.headers().match(header_names::transfer_encoding, transferencoding) && transferencoding == "chunked")
@@ -732,6 +737,23 @@ class asio_context : public request_context, public std::enable_shared_from_this
732737
}
733738

734739
private:
740+
utility::string_t generate_basic_auth_header()
741+
{
742+
utility::string_t header;
743+
744+
header.append(header_names::authorization);
745+
header.append(": Basic ");
746+
747+
auto credential_str = web::details::plaintext_string(new ::utility::string_t(m_http_client->client_config().credentials().username()));
748+
credential_str->append(":");
749+
credential_str->append(*m_http_client->client_config().credentials().decrypt());
750+
751+
std::vector<unsigned char> credentials_buffer(credential_str->begin(), credential_str->end());
752+
753+
header.append(utility::conversions::to_base64(credentials_buffer));
754+
header.append(CRLF);
755+
return header;
756+
}
735757

736758
utility::string_t generate_basic_proxy_auth_header()
737759
{

0 commit comments

Comments
 (0)