Skip to content

Commit 8cf0416

Browse files
committed
wip
1 parent ff2a72d commit 8cf0416

File tree

12 files changed

+85
-141
lines changed

12 files changed

+85
-141
lines changed

include/signalrclient/http_client.h

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,48 +13,46 @@
1313

1414
namespace signalr
1515
{
16-
enum class http_method
17-
{
18-
GET,
19-
POST
20-
};
21-
2216
class http_request final
2317
{
2418
public:
25-
http_method get_method() const;
19+
enum class method
20+
{
21+
GET,
22+
POST
23+
};
24+
25+
method get_method() const noexcept;
2626

27-
const std::map<std::string, std::string>& get_headers() const;
27+
const std::map<std::string, std::string>& get_headers() const noexcept;
2828

29-
const std::string& get_content() const;
29+
const std::string& get_content() const noexcept;
3030

31-
std::chrono::seconds get_timeout() const;
31+
std::chrono::seconds get_timeout() const noexcept;
3232
private:
3333
friend class negotiate;
3434

35-
http_method m_method;
35+
method m_method;
3636
std::map<std::string, std::string> m_headers;
3737
std::string m_content;
3838
std::chrono::seconds m_timeout;
3939

4040
http_request()
41-
: m_method(http_method::GET), m_timeout(std::chrono::seconds(120))
41+
: m_method(method::GET), m_timeout(std::chrono::seconds(120))
4242
{ }
4343

44-
void set_timeout(std::chrono::seconds timeout);
45-
void set_content(const std::string& body);
46-
void set_content(std::string&& body);
47-
void set_headers(const std::map<std::string, std::string>& headers);
48-
void set_method(http_method method);
44+
void set_timeout(std::chrono::seconds timeout) noexcept;
45+
void set_content(std::string body) noexcept;
46+
void set_headers(std::map<std::string, std::string> headers) noexcept;
47+
void set_method(method method) noexcept;
4948
};
5049

5150
class http_response final
5251
{
5352
public:
5453
http_response() {}
5554
http_response(http_response&& rhs) noexcept : m_status_code(rhs.m_status_code), m_content(std::move(rhs.m_content)) {}
56-
http_response(int code, const std::string& content) : m_status_code(code), m_content(content) {}
57-
http_response(int code, std::string&& content) : m_status_code(code), m_content(std::move(content)) {}
55+
http_response(int code, std::string content) : m_status_code(code), m_content(std::move(content)) {}
5856
http_response(const http_response& rhs) : m_status_code(rhs.m_status_code), m_content(rhs.m_content) {}
5957

6058
http_response& operator=(const http_response& rhs)
@@ -76,8 +74,8 @@ namespace signalr
7674
private:
7775
friend class negotiate;
7876

79-
int get_status_code() const;
80-
const std::string& get_content() const;
77+
int get_status_code() const noexcept;
78+
const std::string& get_content() const noexcept;
8179

8280
int m_status_code = 0;
8381
std::string m_content;
@@ -86,7 +84,7 @@ namespace signalr
8684
class http_client
8785
{
8886
public:
89-
virtual void send(const std::string& url, http_request& request,
87+
virtual void send(const std::string& url, const http_request& request,
9088
std::function<void(const http_response&, std::exception_ptr)> callback, cancellation_token token) = 0;
9189

9290
virtual ~http_client() {}

include/signalrclient/signalr_value.h

Lines changed: 30 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -33,79 +33,54 @@ namespace signalr
3333
};
3434

3535
/**
36-
* Create an object representing a value_type::null value.
36+
* Create an object representing a value::type::null value.
3737
*/
3838
SIGNALRCLIENT_API value();
3939

4040
/**
41-
* Create an object representing a value_type::null value.
41+
* Create an object representing a value::type::null value.
4242
*/
4343
SIGNALRCLIENT_API value(std::nullptr_t);
4444

4545
/**
46-
* Create an object representing a default value for the given value_type.
46+
* Create an object representing a default value for the given value::type.
4747
*/
4848
SIGNALRCLIENT_API value(type t);
4949

5050
/**
51-
* Create an object representing a value_type::boolean with the given bool value.
51+
* Create an object representing a value::type::boolean with the given bool value.
5252
*/
5353
SIGNALRCLIENT_API value(bool val);
5454

5555
/**
56-
* Create an object representing a value_type::float64 with the given double value.
56+
* Create an object representing a value::type::float64 with the given double value.
5757
*/
5858
SIGNALRCLIENT_API value(double val);
5959

6060
/**
61-
* Create an object representing a value_type::string with the given string value.
61+
* Create an object representing a value::type::string with the given string value.
6262
*/
63-
SIGNALRCLIENT_API value(const std::string& val);
63+
SIGNALRCLIENT_API value(std::string val);
6464

6565
/**
66-
* Create an object representing a value_type::string with the given string value.
67-
*/
68-
SIGNALRCLIENT_API value(std::string&& val);
69-
70-
/**
71-
* Create an object representing a value_type::string with the given string value.
66+
* Create an object representing a value::type::string with the given string value.
7267
*/
7368
SIGNALRCLIENT_API value(const char* val);
7469

7570
/**
76-
* Create an object representing a value_type::string with the given string value.
77-
*/
78-
SIGNALRCLIENT_API value(const char* val, size_t length);
79-
80-
/**
81-
* Create an object representing a value_type::array with the given vector of value's.
82-
*/
83-
SIGNALRCLIENT_API value(const std::vector<value>& val);
84-
85-
/**
86-
* Create an object representing a value_type::array with the given vector of value's.
87-
*/
88-
SIGNALRCLIENT_API value(std::vector<value>&& val);
89-
90-
/**
91-
* Create an object representing a value_type::map with the given map of string-value's.
92-
*/
93-
SIGNALRCLIENT_API value(const std::map<std::string, value>& map);
94-
95-
/**
96-
* Create an object representing a value_type::map with the given map of string-value's.
71+
* Create an object representing a value::type::array with the given vector of value's.
9772
*/
98-
SIGNALRCLIENT_API value(std::map<std::string, value>&& map);
73+
SIGNALRCLIENT_API value(std::vector<value> val);
9974

10075
/**
101-
* Create an object representing a value_type::binary with the given array of byte's.
76+
* Create an object representing a value::type::map with the given map of string-value's.
10277
*/
103-
SIGNALRCLIENT_API value(const std::vector<uint8_t>& bin);
78+
SIGNALRCLIENT_API value(std::map<std::string, value> map);
10479

10580
/**
106-
* Create an object representing a value_type::binary with the given array of byte's.
81+
* Create an object representing a value::type::binary with the given array of byte's.
10782
*/
108-
SIGNALRCLIENT_API value(std::vector<uint8_t>&& bin);
83+
SIGNALRCLIENT_API value(std::vector<uint8_t> bin);
10984

11085
/**
11186
* Copies an existing value.
@@ -120,7 +95,7 @@ namespace signalr
12095
/**
12196
* Cleans up the resources associated with the value.
12297
*/
123-
SIGNALRCLIENT_API ~value();
98+
SIGNALRCLIENT_API ~value() noexcept;
12499

125100
/**
126101
* Copies an existing value.
@@ -135,70 +110,70 @@ namespace signalr
135110
/**
136111
* True if the object stored is a Key-Value pair.
137112
*/
138-
SIGNALRCLIENT_API bool is_map() const;
113+
SIGNALRCLIENT_API bool is_map() const noexcept;
139114

140115
/**
141116
* True if the object stored is a double.
142117
*/
143-
SIGNALRCLIENT_API bool is_double() const;
118+
SIGNALRCLIENT_API bool is_double() const noexcept;
144119

145120
/**
146121
* True if the object stored is a string.
147122
*/
148-
SIGNALRCLIENT_API bool is_string() const;
123+
SIGNALRCLIENT_API bool is_string() const noexcept;
149124

150125
/**
151126
* True if the object stored is empty.
152127
*/
153-
SIGNALRCLIENT_API bool is_null() const;
128+
SIGNALRCLIENT_API bool is_null() const noexcept;
154129

155130
/**
156131
* True if the object stored is an array of signalr::value's.
157132
*/
158-
SIGNALRCLIENT_API bool is_array() const;
133+
SIGNALRCLIENT_API bool is_array() const noexcept;
159134

160135
/**
161136
* True if the object stored is a bool.
162137
*/
163-
SIGNALRCLIENT_API bool is_bool() const;
138+
SIGNALRCLIENT_API bool is_bool() const noexcept;
164139

165140
/**
166141
* True if the object stored is a binary blob.
167142
*/
168-
SIGNALRCLIENT_API bool is_binary() const;
143+
SIGNALRCLIENT_API bool is_binary() const noexcept;
169144

170145
/**
171-
* Returns the stored object as a double. This will throw if the underlying object is not a signalr::type::float64.
146+
* Returns the stored object as a double. This will throw if the underlying object is not a signalr::value::type::float64.
172147
*/
173148
SIGNALRCLIENT_API double as_double() const;
174149

175150
/**
176-
* Returns the stored object as a bool. This will throw if the underlying object is not a signalr::type::boolean.
151+
* Returns the stored object as a bool. This will throw if the underlying object is not a signalr::value::type::boolean.
177152
*/
178153
SIGNALRCLIENT_API bool as_bool() const;
179154

180155
/**
181-
* Returns the stored object as a string. This will throw if the underlying object is not a signalr::type::string.
156+
* Returns the stored object as a string. This will throw if the underlying object is not a signalr::value::type::string.
182157
*/
183158
SIGNALRCLIENT_API const std::string& as_string() const;
184159

185160
/**
186-
* Returns the stored object as an array of signalr::value's. This will throw if the underlying object is not a signalr::type::array.
161+
* Returns the stored object as an array of signalr::value's. This will throw if the underlying object is not a signalr::value::type::array.
187162
*/
188163
SIGNALRCLIENT_API const std::vector<value>& as_array() const;
189164

190165
/**
191-
* Returns the stored object as a map of property name to signalr::value. This will throw if the underlying object is not a signalr::type::map.
166+
* Returns the stored object as a map of property name to signalr::value. This will throw if the underlying object is not a signalr::value::type::map.
192167
*/
193168
SIGNALRCLIENT_API const std::map<std::string, value>& as_map() const;
194169

195170
/**
196-
* Returns the stored object as an array of bytes. This will throw if the underlying object is not a signalr::type::binary.
171+
* Returns the stored object as an array of bytes. This will throw if the underlying object is not a signalr::value::type::binary.
197172
*/
198173
SIGNALRCLIENT_API const std::vector<uint8_t>& as_binary() const;
199174

200175
/**
201-
* Returns the signalr::type that represents the stored object.
176+
* Returns the signalr::value::type that represents the stored object.
202177
*/
203178
SIGNALRCLIENT_API type type() const;
204179

@@ -216,7 +191,7 @@ namespace signalr
216191

217192
// constructor of types in union are not implicitly called
218193
// this is expected as we only construct a single type in the union once we know
219-
// what that type is when constructing the signalr_value type.
194+
// what that type is when constructing the signalr::value type.
220195
#pragma warning (push)
221196
#pragma warning (disable: 4582)
222197
storage() {}

src/signalrclient/connection_impl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,8 @@ namespace signalr
304304
}
305305

306306
auto http_client = m_http_client_factory(m_signalr_client_config);
307-
std::shared_ptr<signalr::http_client> s(std::move(http_client));
308-
start_negotiate_internal(url, 0, transport_started, std::move(s));
307+
std::shared_ptr<signalr::http_client> shared_client(std::move(http_client));
308+
start_negotiate_internal(url, 0, transport_started, std::move(shared_client));
309309
}
310310

311311
void connection_impl::start_negotiate_internal(const std::string& url, int redirect_count,

src/signalrclient/default_http_client.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ namespace signalr
1818
: m_config(config)
1919
{ }
2020

21-
void default_http_client::send(const std::string& url, http_request& request,
21+
void default_http_client::send(const std::string& url, const http_request& request,
2222
std::function<void(const http_response&, std::exception_ptr)> callback, cancellation_token token)
2323
{
2424
web::http::method method;
25-
if (request.get_method() == http_method::GET)
25+
if (request.get_method() == http_request::method::GET)
2626
{
2727
method = U("GET");
2828
}
29-
else if (request.get_method() == http_method::POST)
29+
else if (request.get_method() == http_request::method::POST)
3030
{
3131
method = U("POST");
3232
}

src/signalrclient/default_http_client.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace signalr
1414
public:
1515
explicit default_http_client(const signalr_client_config& config = {}) noexcept;
1616

17-
void send(const std::string& url, http_request& request,
17+
void send(const std::string& url, const http_request& request,
1818
std::function<void(const http_response&, std::exception_ptr)> callback, cancellation_token token) override;
1919

2020
private:

src/signalrclient/handshake_protocol.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ namespace signalr
1313
{
1414
std::string write_handshake(const std::unique_ptr<hub_protocol>& protocol)
1515
{
16+
auto protocol_value = signalr::value(protocol->name());
1617
auto map = std::map<std::string, signalr::value>
1718
{
18-
{ "protocol", signalr::value(protocol->name()) },
19+
{ "protocol", std::move(protocol_value) },
1920
{ "version", signalr::value((double)protocol->version()) }
2021
};
2122

0 commit comments

Comments
 (0)