Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Pass Uri.IdnHost to WinHttpConnect #28849

Merged
merged 13 commits into from
Apr 17, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ private async void StartRequest(WinHttpRequestState state)
// Specify an HTTP server.
connectHandle = Interop.WinHttp.WinHttpConnect(
_sessionHandle,
state.RequestMessage.RequestUri.Host,
state.RequestMessage.RequestUri.HostNameType == UriHostNameType.IPv6 ? $"[{state.RequestMessage.RequestUri.IdnHost}]" : state.RequestMessage.RequestUri.IdnHost,
Copy link
Member Author

Choose a reason for hiding this comment

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

With regard to this i'm writing a manual test.

Copy link
Member Author

@MarcoRossignoli MarcoRossignoli Apr 5, 2018

Choose a reason for hiding this comment

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

@davidsh @rmkerr @Caesar1995 without [] ipv6 http://[::1234]:8080 and http://[::1234] tests fails with ERROR_INTERNET_INVALID_URL.

Copy link
Member Author

@MarcoRossignoli MarcoRossignoli Apr 6, 2018

Choose a reason for hiding this comment

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

@Caesar1995 related to https://github.com/dotnet/corefx/issues/28863#issue-311719169 if this PR will be merged i think we'll need to remove workaround also here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, thanks for bringing this up! I will update that issue with this PR.

(ushort)state.RequestMessage.RequestUri.Port,
0);
ThrowOnInvalidHandle(connectHandle, nameof(Interop.WinHttp.WinHttpConnect));
Expand Down
19 changes: 19 additions & 0 deletions src/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2138,6 +2138,25 @@ await server.AcceptConnectionSendCustomResponseAndCloseAsync(
});
}

[OuterLoop]
[Fact]
public async Task GetAsync_IdnHostName()
Copy link
Contributor

Choose a reason for hiding this comment

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

Usually the naming for the test function should be like: A_B_C, A is the attribute what we are testing about, B is the condition to trigger the attribute, and C is the behavior outcome.

You can change to something like GetAsync_IdnHostName_SuccessStatusCodeInResponse.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

{
HttpClientHandler handler = CreateHttpClientHandler();
using (var client = new HttpClient(handler))
{
/*
international version of the Starbucks website
Punnycode: xn--oy2b35ckwhba574atvuzkc.com
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

In corefx, we usually do comment like this:

// Here is the comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

string idn = "\uc2a4\ud0c0\ubc85\uc2a4\ucf54\ub9ac\uc544.com";
Copy link
Contributor

Choose a reason for hiding this comment

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

I would name this variable to something like "server". "idn" implies that this string consists of punnycode character which it doesn't. It is simply a hostname of a endpoint that just happens to have Unicode characters in the name.

And I would simplify this by bringing in the "http://" portion of the string here as well, i.e.

string server = "http://\uc2a4\ud0c0\ubc85\uc2a4\ucf54\ub9ac\uc544.com";

using (HttpResponseMessage response = await client.GetAsync("http://" + idn))
{
response.EnsureSuccessStatusCode();
Copy link
Member Author

Choose a reason for hiding this comment

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

@davidsh i added response.EnsureSuccessStatusCode(); as assertion.
Question on tests, i want to understand how do we test all handlers, I've noticed that test run two times, one for every handler, how it works?

Copy link
Contributor

Choose a reason for hiding this comment

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

Explained in one of the comments above.

}
}
}

#region Post Methods Tests

[OuterLoop] // TODO: Issue #11345
Expand Down