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
30 changes: 25 additions & 5 deletions src/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1659,7 +1659,7 @@ await LoopbackServer.CreateServerAsync(async (server, 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.

i don't know why...in my vs diff tool these changes weren't visible, should i remove?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, please remove any changes that aren't part of the PR.

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

[Fact]
public async Task GetAsync_InvalidChunkTerminator_ThrowsHttpRequestException()
{
Expand All @@ -1675,8 +1675,8 @@ await LoopbackServer.CreateClientAndServerAsync(async url =>
"\r\n" +
"5\r\n" +
"hello" + // missing \r\n terminator
//"5\r\n" +
//"world" + // missing \r\n terminator
//"5\r\n" +
//"world" + // missing \r\n terminator
"0\r\n" +
"\r\n"));
}
Expand Down Expand Up @@ -3035,8 +3035,8 @@ await LoopbackServer.CreateServerAsync(async (server, url) =>
HttpResponseMessage response = await client.GetAsync(url);
Assert.True(response.StatusCode == HttpStatusCode.OK);
}
}
await serverTask;
}
await serverTask;
}, options);
await proxy;
}
Expand Down Expand Up @@ -3137,5 +3137,25 @@ await LoopbackServer.CreateServerAsync(async (server, rootUrl) =>
});
}
#endregion

[OuterLoop]
[Fact]
public async Task GetAsync_IdnHostName()
{
HttpClientHandler handler = CreateHttpClientHandler();
using (var client = new HttpClient(handler))
{
/*
international version of the Starbucks website
Punnycode: xn--oy2b35ckwhba574atvuzkc.com
*/
string idn = "\uc2a4\ud0c0\ubc85\uc2a4\ucf54\ub9ac\uc544.com";
using (HttpResponseMessage response = await client.GetAsync("http://" + idn))
{
response.EnsureSuccessStatusCode();
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.

@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.

In System.Net.Http.FunctionalTest project, we have abstract base test class, that's where you want to your test. The current location System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.cs is correct. Since the base class is abstract, those test cases will only be invoked by derived types (explained below).

There are two files which will actually invoke all the test cases. PlatformHandlerTest.cs, which will run the test against platform specific handlers (WinHttpHandler on Windows, and CurlHandler on Unix), and SocketsHttpHandler, which will run the test using our managed SocketsHttpHandler.

Even though you only modified the WinHttpHandler's code, we want to make sure the test you added is not specific to WinHttpHandler, and will pass with other handlers. To do so, you will help us detect/avoid platform specific behavior difference.

Copy link
Member Author

Choose a reason for hiding this comment

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

@Caesar1995 understood TYVM!

}
}
}

}
}