diff --git a/include/signalrclient/signalr_client_config.h b/include/signalrclient/signalr_client_config.h index a1b3d29..f9e26ae 100644 --- a/include/signalrclient/signalr_client_config.h +++ b/include/signalrclient/signalr_client_config.h @@ -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. @@ -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; }; } \ No newline at end of file diff --git a/src/signalrclient/http_sender.cpp b/src/signalrclient/http_sender.cpp index 9741ad5..f331ae6 100644 --- a/src/signalrclient/http_sender.cpp +++ b/src/signalrclient/http_sender.cpp @@ -4,7 +4,6 @@ #include "stdafx.h" #include "signalrclient/web_exception.h" #include "web_request_factory.h" -#include "constants.h" namespace signalr { @@ -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) diff --git a/src/signalrclient/signalr_client_config.cpp b/src/signalrclient/signalr_client_config.cpp index 523ba56..4f79f81 100644 --- a/src/signalrclient/signalr_client_config.cpp +++ b/src/signalrclient/signalr_client_config.cpp @@ -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); @@ -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; + } } \ No newline at end of file diff --git a/src/signalrclient/web_request.cpp b/src/signalrclient/web_request.cpp index cf4ae08..a1b0d77 100644 --- a/src/signalrclient/web_request.cpp +++ b/src/signalrclient/web_request.cpp @@ -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; @@ -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) diff --git a/src/signalrclient/web_request.h b/src/signalrclient/web_request.h index cd6314e..e0adfee 100644 --- a/src/signalrclient/web_request.h +++ b/src/signalrclient/web_request.h @@ -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 get_response(); @@ -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; signalr_client_config m_signalr_client_config; }; } \ No newline at end of file