From a3b71652090278db7db0c40ee616a7191d22efe3 Mon Sep 17 00:00:00 2001 From: Ritesh Khadgaray Date: Sun, 26 Jun 2016 11:24:57 +0530 Subject: [PATCH] add support for basic authentication --- Release/src/http/client/http_client_asio.cpp | 24 +++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/Release/src/http/client/http_client_asio.cpp b/Release/src/http/client/http_client_asio.cpp index 0e294851b6..85a26000c0 100644 --- a/Release/src/http/client/http_client_asio.cpp +++ b/Release/src/http/client/http_client_asio.cpp @@ -633,7 +633,12 @@ class asio_context : public request_context, public std::enable_shared_from_this { extra_headers.append(ctx->generate_basic_proxy_auth_header()); } - + + if (ctx->m_http_client->client_config().credentials().is_set()) + { + extra_headers.append(ctx->generate_basic_auth_header()); + } + // Check user specified transfer-encoding. std::string transferencoding; 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 } private: + utility::string_t generate_basic_auth_header() + { + utility::string_t header; + + header.append(header_names::authorization); + header.append(": Basic "); + + auto credential_str = web::details::plaintext_string(new ::utility::string_t(m_http_client->client_config().credentials().username())); + credential_str->append(":"); + credential_str->append(*m_http_client->client_config().credentials().decrypt()); + + std::vector credentials_buffer(credential_str->begin(), credential_str->end()); + + header.append(utility::conversions::to_base64(credentials_buffer)); + header.append(CRLF); + return header; + } utility::string_t generate_basic_proxy_auth_header() {