Skip to content

Commit a8653a8

Browse files
Copy Uri code from cpprestsdk (#11)
1 parent 807667b commit a8653a8

File tree

11 files changed

+1890
-23
lines changed

11 files changed

+1890
-23
lines changed

src/signalrclient/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,13 @@ set (SOURCES
1515
transport_factory.cpp
1616
url_builder.cpp
1717
websocket_transport.cpp
18+
../../third_party_code/cpprestsdk/uri.cpp
19+
../../third_party_code/cpprestsdk/uri_builder.cpp
1820
)
1921

22+
include_directories(
23+
../../third_party_code/cpprestsdk)
24+
2025
add_library (signalrclient SHARED ${SOURCES})
2126

2227
if(NOT USE_CPPRESTSDK)

src/signalrclient/url_builder.cpp

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,52 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
#include "stdafx.h"
5-
#include "cpprest/http_client.h"
5+
#include "uri_builder.h"
66
#include "signalrclient/transport_type.h"
77

88
namespace signalr
99
{
1010
namespace url_builder
1111
{
12-
web::uri_builder &convert_to_websocket_url(web::uri_builder &builder, transport_type transport)
12+
uri_builder &convert_to_websocket_url(uri_builder &builder, transport_type transport)
1313
{
1414
if (transport == transport_type::websockets)
1515
{
16-
if (builder.scheme() == _XPLATSTR("https"))
16+
if (builder.scheme() == "https")
1717
{
18-
builder.set_scheme(utility::conversions::to_string_t("wss"));
18+
builder.set_scheme("wss");
1919
}
2020
else
2121
{
22-
builder.set_scheme(utility::conversions::to_string_t("ws"));
22+
builder.set_scheme("ws");
2323
}
2424
}
2525

2626
return builder;
2727
}
2828

29-
web::uri_builder build_uri(const std::string& base_url, const std::string& command, const std::string& query_string)
29+
uri_builder build_uri(const std::string& base_url, const std::string& command, const std::string& query_string)
3030
{
31-
web::uri_builder builder(utility::conversions::to_string_t(base_url));
32-
builder.append_path(utility::conversions::to_string_t(command));
33-
return builder.append_query(utility::conversions::to_string_t(query_string));
31+
uri_builder builder(base_url);
32+
builder.append_path(command);
33+
return builder.append_query(query_string);
3434
}
3535

36-
web::uri_builder build_uri(const std::string& base_url, const std::string& command)
36+
uri_builder build_uri(const std::string& base_url, const std::string& command)
3737
{
38-
web::uri_builder builder(utility::conversions::to_string_t(base_url));
39-
return builder.append_path(utility::conversions::to_string_t(command));
38+
uri_builder builder(base_url);
39+
return builder.append_path(command);
4040
}
4141

4242
std::string build_negotiate(const std::string& base_url)
4343
{
44-
return utility::conversions::to_utf8string(build_uri(base_url, "negotiate").to_string());
44+
return build_uri(base_url, "negotiate").to_string();
4545
}
4646

4747
std::string build_connect(const std::string& base_url, transport_type transport, const std::string& query_string)
4848
{
4949
auto builder = build_uri(base_url, "", query_string);
50-
return utility::conversions::to_utf8string(convert_to_websocket_url(builder, transport).to_string());
51-
}
52-
53-
std::string build_start(const std::string& base_url, const std::string &query_string)
54-
{
55-
return utility::conversions::to_utf8string(build_uri(base_url, "", query_string).to_string());
50+
return convert_to_websocket_url(builder, transport).to_string();
5651
}
5752
}
5853
}

src/signalrclient/url_builder.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#pragma once
55

6-
#include "cpprest/http_client.h"
76
#include "signalrclient/transport_type.h"
87

98
namespace signalr
@@ -12,6 +11,5 @@ namespace signalr
1211
{
1312
std::string build_negotiate(const std::string& base_url);
1413
std::string build_connect(const std::string& base_url, transport_type transport, const std::string& query_string);
15-
std::string build_start(const std::string& base_url, const std::string& query_string);
1614
}
1715
}

src/signalrclient/websocket_transport.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "websocket_transport.h"
66
#include "logger.h"
77
#include "signalrclient/signalr_exception.h"
8+
#include "base_uri.h"
89
#include <future>
910

1011
namespace signalr
@@ -144,8 +145,8 @@ namespace signalr
144145

145146
void websocket_transport::start(const std::string& url, transfer_format format, std::function<void(std::exception_ptr)> callback) noexcept
146147
{
147-
web::uri uri(utility::conversions::to_string_t(url));
148-
assert(uri.scheme() == _XPLATSTR("ws") || uri.scheme() == _XPLATSTR("wss"));
148+
signalr::uri uri(url);
149+
assert(uri.scheme() == "ws" || uri.scheme() == "wss");
149150

150151
{
151152
std::lock_guard<std::mutex> stop_lock(m_start_stop_lock);

test/signalrclienttests/url_builder_tests.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,10 @@ TEST(url_builder_connect_webSockets, url_correct_if_query_string_not_empty)
2626
"ws://fake/?q1=1&q2=2",
2727
url_builder::build_connect("http://fake/", transport_type::websockets, "q1=1&q2=2"));
2828
}
29+
30+
TEST(url_builder_connect, url_correct_if_query_string_not_empty_and_adding_query_string)
31+
{
32+
ASSERT_EQ(
33+
"ws://fake/?q=0&q1=1&q2=2",
34+
url_builder::build_connect("http://fake/?q=0", transport_type::websockets, "q1=1&q2=2"));
35+
}

third-party-notices.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.NET Core uses third-party libraries or other resources that may be
2+
distributed under licenses different than the .NET Core software.
3+
4+
In the event that we accidentally failed to list a required notice, please
5+
bring it to our attention. Post an issue or email us:
6+
7+
dotnet@microsoft.com
8+
9+
The attached notices are provided for information only.
10+
11+
License notice for cpprestsdk
12+
------------------------------------------------------------------------------
13+
Copyright (c) Microsoft Corporation
14+
15+
All rights reserved.
16+
17+
Permission is hereby granted, free of charge, to any person obtaining a copy of
18+
this software and associated documentation files (the "Software"), to deal in
19+
the Software without restriction, including without limitation the rights to
20+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
21+
the Software, and to permit persons to whom the Software is furnished to do so,
22+
subject to the following conditions:
23+
24+
The above copyright notice and this permission notice shall be included in all
25+
copies or substantial portions of the Software.
26+
27+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33+
SOFTWARE.

0 commit comments

Comments
 (0)