Imported Upstream version 5.10.0.47

Former-commit-id: d0813289fa2d35e1f8ed77530acb4fb1df441bc0
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-01-24 17:04:36 +00:00
parent 88ff76fe28
commit e46a49ecf1
5927 changed files with 226314 additions and 129848 deletions

View File

@@ -177,9 +177,9 @@ namespace System.Net
}
}
/// Pipelined command resoluton.
/// Pipelined command resolution.
/// How this works:
/// A list of commands that need to be sent to the FTP server are spliced together into a array,
/// A list of commands that need to be sent to the FTP server are spliced together into an array,
/// each command such STOR, PORT, etc, is sent to the server, then the response is parsed into a string,
/// with the response, the delegate is called, which returns an instruction (either continue, stop, or read additional
/// responses from server).

View File

@@ -1234,7 +1234,7 @@ namespace System.Net
}
/// <summary>
/// <para>Determnines whether the stream we return is Writeable or Readable</para>
/// <para>Determines whether the stream we return is Writeable or Readable</para>
/// </summary>
private TriState IsFtpDataStreamWriteable()
{

View File

@@ -141,7 +141,7 @@ namespace System.Net
}
/// <summary>
/// <para>Last status code retrived</para>
/// <para>Last status code retrieved</para>
/// </summary>
public FtpStatusCode StatusCode
{
@@ -152,7 +152,7 @@ namespace System.Net
}
/// <summary>
/// <para>Last status line retrived</para>
/// <para>Last status line retrieved</para>
/// </summary>
public string StatusDescription
{
@@ -163,7 +163,7 @@ namespace System.Net
}
/// <summary>
/// <para>Returns last modified date time for given file (null if not relavant/avail)</para>
/// <para>Returns last modified date time for given file (null if not relevant/avail)</para>
/// </summary>
public DateTime LastModified
{

View File

@@ -34,7 +34,6 @@ namespace System.Net
[Serializable]
private sealed class EmptyWebProxy : IWebProxy
{
[NonSerialized]
private ICredentials _credentials;
public EmptyWebProxy()

View File

@@ -1,9 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
//--------------------------------------------------------------------------
using System.Globalization;
namespace System.Net
{
@@ -14,7 +11,7 @@ namespace System.Net
//
// Date indicies used to figure out what each entry is.
//
private const int DATE_INDEX_DAY_OF_WEEK = 0;
private const int DATE_1123_INDEX_DAY = 1;
@@ -71,56 +68,25 @@ namespace System.Net
private const int DATE_TOKEN_ERROR = (DATE_TOKEN_LAST+1);
//
// MAKE_UPPER - takes an assumed lower character and bit manipulates into a upper.
// (make sure the character is Lower case alpha char to begin,
// otherwise it corrupts)
//
private
static
char
MAKE_UPPER(char c) {
return(Char.ToUpper(c));
}
/*++
Routine Description:
Looks at the first three bytes of string to determine if we're looking
at a Day of the Week, or Month, or "GMT" string. Is inlined so that
the compiler can optimize this code into the caller FInternalParseHttpDate.
Arguments:
lpszDay - a string ptr to the first byte of the string in question.
Return Value:
DWORD
Success - The Correct date token, 0-6 for day of the week, 1-14 for month, etc
Failure - DATE_TOKEN_ERROR
--*/
private
static
int
MapDayMonthToDword(
char [] lpszDay,
int index
) {
switch (MAKE_UPPER(lpszDay[index])) { // make uppercase
/// <summary>
/// Looks at the first three chars of a string at the index to determine if we're looking
/// at a Day of the Week, or Month, or "GMT" string.
/// </summary>
/// <returns>
/// The correct date token (0-6 for day of the week, 1-14 for month, etc.) if successful,
/// otherwise, DATE_TOKEN_ERROR.
/// </returns>
private static int MapDayMonthToDword(string day, int index)
{
switch (char.ToUpper(day[index]))
{
case 'A':
switch (MAKE_UPPER(lpszDay[index+1])) {
switch (char.ToUpper(day[index + 1]))
{
case 'P':
return DATE_TOKEN_APRIL;
case 'U':
return DATE_TOKEN_AUGUST;
}
return DATE_TOKEN_ERROR;
@@ -128,25 +94,26 @@ namespace System.Net
return DATE_TOKEN_DECEMBER;
case 'F':
switch (MAKE_UPPER(lpszDay[index+1])) {
switch (char.ToUpper(day[index + 1]))
{
case 'R':
return DATE_TOKEN_FRIDAY;
case 'E':
return DATE_TOKEN_FEBRUARY;
}
return DATE_TOKEN_ERROR;
case 'G':
return DATE_TOKEN_GMT;
case 'M':
switch (MAKE_UPPER(lpszDay[index+1])) {
switch (char.ToUpper(day[index + 1]))
{
case 'O':
return DATE_TOKEN_MONDAY;
case 'A':
switch (MAKE_UPPER(lpszDay[index+2])) {
switch (char.ToUpper(day[index + 2]))
{
case 'R':
return DATE_TOKEN_MARCH;
case 'Y':
@@ -156,20 +123,20 @@ namespace System.Net
// fall through to error
break;
}
return DATE_TOKEN_ERROR;
case 'N':
return DATE_TOKEN_NOVEMBER;
case 'J':
switch (MAKE_UPPER(lpszDay[index+1])) {
switch (char.ToUpper(day[index + 1]))
{
case 'A':
return DATE_TOKEN_JANUARY;
case 'U':
switch (MAKE_UPPER(lpszDay[index+2])) {
switch (char.ToUpper(day[index + 2]))
{
case 'N':
return DATE_TOKEN_JUNE;
case 'L':
@@ -179,15 +146,14 @@ namespace System.Net
// fall through to error
break;
}
return DATE_TOKEN_ERROR;
case 'O':
return DATE_TOKEN_OCTOBER;
case 'S':
switch (MAKE_UPPER(lpszDay[index+1])) {
switch (char.ToUpper(day[index + 1]))
{
case 'A':
return DATE_TOKEN_SATURDAY;
case 'U':
@@ -195,18 +161,16 @@ namespace System.Net
case 'E':
return DATE_TOKEN_SEPTEMBER;
}
return DATE_TOKEN_ERROR;
case 'T':
switch (MAKE_UPPER(lpszDay[index+1])) {
switch (char.ToUpper(day[index + 1]))
{
case 'U':
return DATE_TOKEN_TUESDAY;
case 'H':
return DATE_TOKEN_THURSDAY;
}
return DATE_TOKEN_ERROR;
case 'U':
@@ -214,54 +178,22 @@ namespace System.Net
case 'W':
return DATE_TOKEN_WEDNESDAY;
}
return DATE_TOKEN_ERROR;
}
/*++
Routine Description:
Parses through a ANSI, RFC850, or RFC1123 date format and covents it into
a FILETIME/SYSTEMTIME time format.
Important this a time-critical function and should only be changed
with the intention of optimizing or a critical need work item.
Arguments:
lpft - Ptr to FILETIME structure. Used to store converted result.
Must be NULL if not intended to be used !!!
lpSysTime - Ptr to SYSTEMTIME struture. Used to return Systime if needed.
lpcszDateStr - Const Date string to parse.
Return Value:
BOOL
Success - TRUE
Failure - FALSE
--*/
public
static
bool
ParseHttpDate(
String DateString,
out DateTime dtOut
) {
/// <summary>
/// Parses through an ANSI, RFC850, or RFC1123 date format and converts it to a <see cref="DateTime"/>.
/// </summary>
public static bool ParseHttpDate(string dateString, out DateTime result)
{
int index = 0;
int i = 0, iLastLettered = -1;
bool fIsANSIDateFormat = false;
int [] rgdwDateParseResults = new int[MAX_FIELD_DATE_ENTRIES];
bool fRet = true;
char [] lpInputBuffer = DateString.ToCharArray();
bool isANSIDateFormat = false;
int[] dateParseResults = new int[MAX_FIELD_DATE_ENTRIES];
dtOut = new DateTime();
result = new DateTime();
//
// Date Parsing v2 (1 more to go), and here is how it works...
@@ -269,53 +201,53 @@ namespace System.Net
// integers to integers, Month,Day, and GMT strings into integers,
// and all is then placed IN order in a temp array.
//
// At the completetion of the parse stage, we simple look at
// the data, and then map the results into the correct
// places in the SYSTIME structure. Simple, No allocations, and
// No dirting the data.
// At the completion of the parse stage, we simple look at
// the data, and then map the results into a new DateTime.
//
// The end of the function does something munging and pretting
// up of the results to handle the year 2000, and TZ offsets
// Note: do we need to fully handle TZs anymore?
//
while (index < DateString.Length && i < MAX_FIELD_DATE_ENTRIES) {
if (lpInputBuffer[index] >= '0' && lpInputBuffer[index] <= '9') {
while (index < dateString.Length && i < MAX_FIELD_DATE_ENTRIES)
{
if (dateString[index] >= '0' && dateString[index] <= '9')
{
//
// we have a numerical entry, scan through it and convent to DWORD
//
rgdwDateParseResults[i] = 0;
dateParseResults[i] = 0;
do {
rgdwDateParseResults[i] *= BASE_DEC;
rgdwDateParseResults[i] += (lpInputBuffer[index] - '0');
do
{
dateParseResults[i] *= BASE_DEC;
dateParseResults[i] += (dateString[index] - '0');
index++;
} while (index < DateString.Length &&
lpInputBuffer[index] >= '0' &&
lpInputBuffer[index] <= '9');
} while (index < dateString.Length &&
dateString[index] >= '0' &&
dateString[index] <= '9');
i++; // next token
}
else if ((lpInputBuffer[index] >= 'A' && lpInputBuffer[index] <= 'Z') ||
(lpInputBuffer[index] >= 'a' && lpInputBuffer[index] <= 'z')) {
else if ((dateString[index] >= 'A' && dateString[index] <= 'Z') ||
(dateString[index] >= 'a' && dateString[index] <= 'z'))
{
//
// we have a string, should be a day, month, or GMT
// lets skim to the end of the string
//
rgdwDateParseResults[i] =
MapDayMonthToDword(lpInputBuffer, index);
dateParseResults[i] = MapDayMonthToDword(dateString, index);
iLastLettered = i;
// We want to ignore the possibility of a time zone such as PST or EST in a non-standard
// date format such as "Thu Dec 17 16:01:28 PST 1998" (Notice that the year is _after_ the time zone
if ((rgdwDateParseResults[i] == DATE_TOKEN_ERROR)
&&
!(fIsANSIDateFormat && (i==DATE_ANSI_INDEX_YEAR))) {
fRet = false;
goto quit;
if ((dateParseResults[i] == DATE_TOKEN_ERROR) &&
!(isANSIDateFormat && (i == DATE_ANSI_INDEX_YEAR)))
{
return false;
}
//
@@ -324,8 +256,9 @@ namespace System.Net
// looking at a ANSI type DATE format.
//
if (i == DATE_ANSI_INDEX_MONTH) {
fIsANSIDateFormat = true;
if (i == DATE_ANSI_INDEX_MONTH)
{
isANSIDateFormat = true;
}
//
@@ -333,15 +266,17 @@ namespace System.Net
// as MapDayMonthToDword only peeks at a few characters
//
do {
do
{
index++;
} while (index < DateString.Length &&
( (lpInputBuffer[index] >= 'A' && lpInputBuffer[index] <= 'Z') ||
(lpInputBuffer[index] >= 'a' && lpInputBuffer[index] <= 'z') ));
} while ((index < dateString.Length) &&
((dateString[index] >= 'A' && dateString[index] <= 'Z') ||
(dateString[index] >= 'a' && dateString[index] <= 'z')));
i++; // next token
}
else {
else
{
//
// For the generic case its either a space, comma, semi-colon, etc.
// the point is we really don't care, nor do we need to waste time
@@ -368,30 +303,34 @@ namespace System.Net
int second;
int millisecond;
millisecond = 0;
millisecond = 0;
if (fIsANSIDateFormat) {
day = rgdwDateParseResults[DATE_ANSI_INDEX_DAY];
month = rgdwDateParseResults[DATE_ANSI_INDEX_MONTH];
hour = rgdwDateParseResults[DATE_ANSI_INDEX_HRS];
minute = rgdwDateParseResults[DATE_ANSI_INDEX_MINS];
second = rgdwDateParseResults[DATE_ANSI_INDEX_SECS];
if (iLastLettered != DATE_ANSI_INDEX_YEAR) {
year = rgdwDateParseResults[DATE_ANSI_INDEX_YEAR];
if (isANSIDateFormat)
{
day = dateParseResults[DATE_ANSI_INDEX_DAY];
month = dateParseResults[DATE_ANSI_INDEX_MONTH];
hour = dateParseResults[DATE_ANSI_INDEX_HRS];
minute = dateParseResults[DATE_ANSI_INDEX_MINS];
second = dateParseResults[DATE_ANSI_INDEX_SECS];
if (iLastLettered != DATE_ANSI_INDEX_YEAR)
{
year = dateParseResults[DATE_ANSI_INDEX_YEAR];
}
else {
else
{
// This is a fix to get around toString/toGMTstring (where the timezone is
// appended at the end. (See above)
year = rgdwDateParseResults[DATE_INDEX_TZ];
year = dateParseResults[DATE_INDEX_TZ];
}
}
else {
day = rgdwDateParseResults[DATE_1123_INDEX_DAY];
month = rgdwDateParseResults[DATE_1123_INDEX_MONTH];
year = rgdwDateParseResults[DATE_1123_INDEX_YEAR];
hour = rgdwDateParseResults[DATE_1123_INDEX_HRS];
minute = rgdwDateParseResults[DATE_1123_INDEX_MINS];
second = rgdwDateParseResults[DATE_1123_INDEX_SECS];
else
{
day = dateParseResults[DATE_1123_INDEX_DAY];
month = dateParseResults[DATE_1123_INDEX_MONTH];
year = dateParseResults[DATE_1123_INDEX_YEAR];
hour = dateParseResults[DATE_1123_INDEX_HRS];
minute = dateParseResults[DATE_1123_INDEX_MINS];
second = dateParseResults[DATE_1123_INDEX_SECS];
}
//
@@ -400,7 +339,8 @@ namespace System.Net
// we all look bad.
//
if (year < 100) {
if (year < 100)
{
year += ((year < 80) ? 2000 : 1900);
}
@@ -409,29 +349,30 @@ namespace System.Net
// !lpszHrs || !lpszMins || !lpszSec
//
if ((i < 4)
|| (day > 31)
|| (hour > 23)
|| (minute > 59)
|| (second > 59)) {
fRet = false;
goto quit;
if ((i < 4) ||
(day > 31) ||
(hour > 23) ||
(minute > 59) ||
(second > 59))
{
return false;
}
//
// Now do the DateTime conversion
//
dtOut = new DateTime (year, month, day, hour, minute, second, millisecond);
result = new DateTime(year, month, day, hour, minute, second, millisecond);
//
// we want the system time to be accurate. This is _suhlow_
// The time passed in is in the local time zone; we have to convert this into GMT.
//
if (iLastLettered==DATE_ANSI_INDEX_YEAR) {
if (iLastLettered == DATE_ANSI_INDEX_YEAR)
{
// this should be an unusual case.
dtOut = dtOut.ToUniversalTime();
result = result.ToUniversalTime();
}
//
@@ -439,27 +380,23 @@ namespace System.Net
// then convert to appropriate GMT time
//
if ((i > DATE_INDEX_TZ &&
rgdwDateParseResults[DATE_INDEX_TZ] != DATE_TOKEN_GMT)) {
if (i > DATE_INDEX_TZ &&
dateParseResults[DATE_INDEX_TZ] != DATE_TOKEN_GMT)
{
//
// if we received +/-nnnn as offset (hhmm), modify the output FILETIME
//
double offset;
offset = (double) rgdwDateParseResults[DATE_INDEX_TZ];
dtOut.AddHours(offset);
double offset = dateParseResults[DATE_INDEX_TZ];
result.AddHours(offset);
}
// In the end, we leave it all in LocalTime
dtOut = dtOut.ToLocalTime();
result = result.ToLocalTime();
quit:
return fRet;
return true;
}
}
} // namespace System.Net
}

View File

@@ -1201,6 +1201,8 @@ namespace System.Net
request.Headers.ConnectionClose = true;
}
request.Version = ProtocolVersion;
_sendRequestTask = client.SendAsync(
request,
_allowReadStreamBuffering ? HttpCompletionOption.ResponseContentRead : HttpCompletionOption.ResponseHeadersRead,

View File

@@ -574,6 +574,7 @@ namespace System.Net
lock (s_internalSyncObject)
{
s_DefaultWebProxy = value;
s_DefaultWebProxyInitialized = true;
}
}
}

View File

@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net.Cache;
@@ -279,6 +280,7 @@ namespace System.Net.Tests
Assert.Equal(int.MaxValue, request.Timeout);
}
[ActiveIssue(22627)]
[Fact]
public async Task Timeout_SetTenMillisecondsOnLoopback_ThrowsWebException()
{
@@ -734,6 +736,44 @@ namespace System.Net.Tests
Assert.Equal(HttpVersion.Version11, request.ProtocolVersion);
}
[SkipOnTargetFramework(TargetFrameworkMonikers.Uap, "UAP does not allow HTTP/1.0 requests.")]
[OuterLoop]
[Theory]
[InlineData(false)]
[InlineData(true)]
public async Task ProtocolVersion_SetThenSendRequest_CorrectHttpRequestVersionSent(bool isVersion10)
{
Version requestVersion = isVersion10 ? HttpVersion.Version10 : HttpVersion.Version11;
Version receivedRequestVersion = null;
await LoopbackServer.CreateServerAsync(async (server, url) =>
{
HttpWebRequest request = WebRequest.CreateHttp(url);
request.ProtocolVersion = requestVersion;
Task<WebResponse> getResponse = request.GetResponseAsync();
Task<List<string>> serverTask = LoopbackServer.ReadRequestAndSendResponseAsync(server);
using (HttpWebResponse response = (HttpWebResponse) await getResponse)
{
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
List<string> receivedRequest = await serverTask;
string statusLine = receivedRequest[0];
if (statusLine.Contains("/1.0"))
{
receivedRequestVersion = HttpVersion.Version10;
}
else if (statusLine.Contains("/1.1"))
{
receivedRequestVersion = HttpVersion.Version11;
}
});
Assert.Equal(requestVersion, receivedRequestVersion);
}
[Fact]
public void ReadWriteTimeout_SetThenGet_ValuesMatch()
{

View File

@@ -12,9 +12,6 @@
<Compile Include="HttpWebResponseTest.cs" />
<Compile Include="RequestStreamTest.cs" />
<Compile Include="WebRequestTest.cs" />
<Compile Include="$(CommonTestPath)\System\PlatformDetection.cs">
<Link>Common\System\PlatformDetection.cs</Link>
</Compile>
<Compile Include="$(CommonTestPath)\System\Net\Configuration.cs">
<Link>Common\System\Net\Configuration.cs</Link>
</Compile>

View File

@@ -2,11 +2,12 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Diagnostics;
using Xunit;
namespace System.Net.Tests
{
public class WebRequestTest
public class WebRequestTest : RemoteExecutorTestBase
{
static WebRequestTest()
{
@@ -28,6 +29,20 @@ namespace System.Net.Tests
Assert.Null(initialDefaultWebProxyCredentials);
}
[Fact]
public void DefaultWebProxy_SetThenGet_ValuesMatch()
{
RemoteInvoke(() =>
{
IWebProxy p = new WebProxy();
WebRequest.DefaultWebProxy = p;
Assert.Same(p, WebRequest.DefaultWebProxy);
return SuccessExitCode;
}).Dispose();
}
[Fact]
public void DefaultWebProxy_SetCredentialsToNullThenGet_ValuesMatch()