Skip to content

Commit

Permalink
add support for basic authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
ritzk committed Jun 26, 2016
1 parent e8b3509 commit a3b7165
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion Release/src/http/client/http_client_asio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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<unsigned char> 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()
{
Expand Down

0 comments on commit a3b7165

Please sign in to comment.