Skip to content
This repository has been archived by the owner on Mar 12, 2021. It is now read-only.

Make User-Agent configurable #171

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/signalrclient/signalr_client_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace signalr
class signalr_client_config
{
public:
signalr_client_config();

SIGNALRCLIENT_API void __cdecl set_proxy(const web::web_proxy &proxy);
// Please note that setting credentials does not work in all cases.
// For example, Basic Authentication fails under Win32.
Expand All @@ -28,9 +30,13 @@ namespace signalr
SIGNALRCLIENT_API web::http::http_headers __cdecl get_http_headers() const;
SIGNALRCLIENT_API void __cdecl set_http_headers(const web::http::http_headers& http_headers);

SIGNALRCLIENT_API const utility::string_t& __cdecl get_user_agent() const;
SIGNALRCLIENT_API void __cdecl set_user_agent(const utility::string_t &user_agent_string);

private:
web::http::client::http_client_config m_http_client_config;
web::websockets::client::websocket_client_config m_websocket_client_config;
web::http::http_headers m_http_headers;
utility::string_t m_user_agent_string;
};
}
2 changes: 0 additions & 2 deletions src/signalrclient/http_sender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "stdafx.h"
#include "signalrclient/web_exception.h"
#include "web_request_factory.h"
#include "constants.h"

namespace signalr
{
Expand All @@ -16,7 +15,6 @@ namespace signalr
auto request = request_factory.create_web_request(url);
request->set_method(web::http::methods::GET);

request->set_user_agent(USER_AGENT);
request->set_client_config(signalr_client_config);

return request->get_response().then([](web_response response)
Expand Down
16 changes: 16 additions & 0 deletions src/signalrclient/signalr_client_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@
#include "signalrclient/signalr_client_config.h"
#include "cpprest/http_client.h"
#include "cpprest/ws_client.h"
#include "constants.h"

namespace signalr
{
signalr_client_config::signalr_client_config()
{
m_user_agent_string = USER_AGENT;
}

void signalr_client_config::set_proxy(const web::web_proxy &proxy)
{
m_http_client_config.set_proxy(proxy);
Expand Down Expand Up @@ -49,4 +55,14 @@ namespace signalr
{
m_http_headers = http_headers;
}

const utility::string_t& signalr_client_config::get_user_agent() const
{
return m_user_agent_string;
}

void signalr_client_config::set_user_agent(const utility::string_t& user_agent_string)
{
m_user_agent_string = user_agent_string;
}
}
9 changes: 2 additions & 7 deletions src/signalrclient/web_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ namespace signalr
m_request.set_method(method);
}

void web_request::set_user_agent(const utility::string_t &user_agent_string)
{
m_user_agent_string = user_agent_string;
}

void web_request::set_client_config(const signalr_client_config& signalr_client_config)
{
m_signalr_client_config = signalr_client_config;
Expand All @@ -31,9 +26,9 @@ namespace signalr
web::http::client::http_client client(m_url, m_signalr_client_config.get_http_client_config());

m_request.headers() = m_signalr_client_config.get_http_headers();
if (!m_user_agent_string.empty())
if (!m_signalr_client_config.get_user_agent().empty())
{
m_request.headers()[_XPLATSTR("User-Agent")] = m_user_agent_string;
m_request.headers()[_XPLATSTR("User-Agent")] = m_signalr_client_config.get_user_agent();
}

return client.request(m_request)
Expand Down
2 changes: 0 additions & 2 deletions src/signalrclient/web_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace signalr
explicit web_request(const web::uri &url);

virtual void set_method(const utility::string_t &method);
virtual void set_user_agent(const utility::string_t &user_agent_string);
virtual void set_client_config(const signalr_client_config& signalr_client_config);

virtual pplx::task<web_response> get_response();
Expand All @@ -26,7 +25,6 @@ namespace signalr
private:
const web::uri m_url;
web::http::http_request m_request;
utility::string_t m_user_agent_string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to fix this test since you removed this method.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check it, overlooked the tests

signalr_client_config m_signalr_client_config;
};
}