-
Notifications
You must be signed in to change notification settings - Fork 136
Fixing proxy port bug when using Win32 path #903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+119
−27
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include "pch.h" | ||
#include "winhttp_provider.h" | ||
|
||
NAMESPACE_XBOX_HTTP_CLIENT_BEGIN | ||
|
||
http_internal_wstring WinHttpProvider::BuildNamedProxyString(_In_ const xbox::httpclient::Uri &proxyUri) | ||
{ | ||
http_internal_wstring wProxyHost = utf16_from_utf8(proxyUri.Host()); | ||
if (proxyUri.IsPortDefault()) | ||
{ | ||
return wProxyHost; | ||
} | ||
if (proxyUri.Port() > 0) | ||
{ | ||
auto portStr = std::to_wstring(proxyUri.Port()); | ||
http_internal_wstring result = wProxyHost; | ||
result.push_back(L':'); | ||
result.append(portStr.c_str()); | ||
return result; | ||
} | ||
return wProxyHost; | ||
} | ||
|
||
NAMESPACE_XBOX_HTTP_CLIENT_END |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
#include "pch.h" | ||
#include "UnitTestIncludes.h" | ||
#define TEST_CLASS_OWNER L"libHttpClient" | ||
#include "DefineTestMacros.h" | ||
#include "Utils.h" | ||
#include "../Common/Win/utils_win.h" | ||
#include "../../Source/HTTP/WinHttp/winhttp_provider.h" | ||
|
||
using namespace xbox::httpclient; | ||
|
||
NAMESPACE_XBOX_HTTP_CLIENT_TEST_BEGIN | ||
|
||
DEFINE_TEST_CLASS(ProxyTests) | ||
{ | ||
public: | ||
DEFINE_TEST_CLASS_PROPS(ProxyTests); | ||
|
||
DEFINE_TEST_CASE(NamedProxyPortFormatting) | ||
{ | ||
DEFINE_TEST_CASE_PROPERTIES(NamedProxyPortFormatting); | ||
// Verify BuildNamedProxyString includes the numeric port (regression guard for prior bug treating uint16_t as a single wide char). | ||
xbox::httpclient::Uri uri{"http://127.0.0.1:8888"}; | ||
auto proxyName = WinHttpProvider::BuildNamedProxyString(uri); | ||
VERIFY_ARE_EQUAL_STR(L"127.0.0.1:8888", proxyName.c_str()); | ||
} | ||
|
||
DEFINE_TEST_CASE(NamedProxyNoPort) | ||
{ | ||
DEFINE_TEST_CASE_PROPERTIES(NamedProxyNoPort); | ||
xbox::httpclient::Uri uri{"http://localhost"}; | ||
auto proxyName = WinHttpProvider::BuildNamedProxyString(uri); | ||
VERIFY_ARE_EQUAL_STR(L"localhost", proxyName.c_str()); | ||
} | ||
|
||
DEFINE_TEST_CASE(NamedProxyExplicitDefaultPort) | ||
{ | ||
DEFINE_TEST_CASE_PROPERTIES(NamedProxyExplicitDefaultPort); | ||
// Explicit default port (http://example.com:80) is preserved by Uri parsing (Port()==80 not treated as default) | ||
xbox::httpclient::Uri uri{"http://example.com:80"}; | ||
auto proxyName = WinHttpProvider::BuildNamedProxyString(uri); | ||
VERIFY_ARE_EQUAL_STR(L"example.com:80", proxyName.c_str()); | ||
|
||
// Verify no default port works | ||
xbox::httpclient::Uri uri2{"http://example.com"}; | ||
auto proxyName2 = WinHttpProvider::BuildNamedProxyString(uri2); | ||
VERIFY_ARE_EQUAL_STR(L"example.com", proxyName2.c_str()); | ||
} | ||
|
||
DEFINE_TEST_CASE(NamedProxyIPv6LiteralWithPort) | ||
{ | ||
DEFINE_TEST_CASE_PROPERTIES(NamedProxyIPv6LiteralWithPort); | ||
// Uri class should normalize; host for IPv6 literal typically without brackets when accessed via Host() | ||
xbox::httpclient::Uri uri{"http://[2001:db8::1]:3128"}; | ||
auto proxyName = WinHttpProvider::BuildNamedProxyString(uri); | ||
// Expect host + :port (no brackets re-added by BuildNamedProxyString) | ||
// If Uri::Host() preserves brackets, adjust expected accordingly; we detect by checking first char | ||
auto hostUtf16 = utf16_from_utf8(uri.Host()); | ||
http_internal_wstring expected = hostUtf16; | ||
if (!uri.IsPortDefault() && uri.Port() > 0) | ||
{ | ||
expected.push_back(L':'); | ||
expected.append(std::to_wstring(uri.Port())); | ||
} | ||
VERIFY_ARE_EQUAL_STR(expected.c_str(), proxyName.c_str()); | ||
} | ||
|
||
DEFINE_TEST_CASE(NamedProxyUnicodeHost) | ||
{ | ||
DEFINE_TEST_CASE_PROPERTIES(NamedProxyUnicodeHost); | ||
// Internationalized domain name in punycode should round-trip; here we just ensure it's copied | ||
xbox::httpclient::Uri uri{"http://xn--bcher-kva.example:8080"}; // bücher.example punycode label | ||
auto proxyName = WinHttpProvider::BuildNamedProxyString(uri); | ||
VERIFY_ARE_EQUAL_STR(L"xn--bcher-kva.example:8080", proxyName.c_str()); | ||
} | ||
}; | ||
|
||
NAMESPACE_XBOX_HTTP_CLIENT_TEST_END |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.