Imported Upstream version 4.6.0.125

Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2016-08-03 10:59:49 +00:00
parent a569aebcfd
commit e79aa3c0ed
17047 changed files with 3137615 additions and 392334 deletions

View File

@ -155,7 +155,7 @@ namespace System.Net
this.requestUri = uri;
this.actualUri = uri;
this.proxy = GlobalProxySelection.Select;
this.webHeaders = new WebHeaderCollection (WebHeaderCollection.HeaderInfo.Request);
this.webHeaders = new WebHeaderCollection (WebHeaderCollectionType.HttpWebRequest);
ThrowOnError = true;
ResetAuthorization ();
}
@ -205,11 +205,19 @@ namespace System.Net
// Properties
void SetSpecialHeaders(string HeaderName, string value) {
value = WebHeaderCollection.CheckBadChars(value, true);
webHeaders.RemoveInternal(HeaderName);
if (value.Length != 0) {
webHeaders.AddInternal(HeaderName, value);
}
}
public string Accept {
get { return webHeaders ["Accept"]; }
set {
CheckRequestStarted ();
webHeaders.RemoveAndAdd ("Accept", value);
SetSpecialHeaders ("Accept", value);
}
}
@ -306,7 +314,7 @@ namespace System.Net
if (keepAlive)
value = value + ", Keep-Alive";
webHeaders.RemoveAndAdd ("Connection", value);
webHeaders.CheckUpdate ("Connection", value);
}
}
@ -336,11 +344,7 @@ namespace System.Net
public override string ContentType {
get { return webHeaders ["Content-Type"]; }
set {
if (value == null || value.Trim().Length == 0) {
webHeaders.RemoveInternal ("Content-Type");
return;
}
webHeaders.RemoveAndAdd ("Content-Type", value);
SetSpecialHeaders ("Content-Type", value);
}
}
@ -367,13 +371,17 @@ namespace System.Net
return DateTime.ParseExact (date, "r", CultureInfo.InvariantCulture).ToLocalTime ();
}
set {
if (value.Equals (DateTime.MinValue))
webHeaders.RemoveInternal ("Date");
else
webHeaders.RemoveAndAdd ("Date", value.ToUniversalTime ().ToString ("r", CultureInfo.InvariantCulture));
SetDateHeaderHelper ("Date", value);
}
}
void SetDateHeaderHelper(string headerName, DateTime dateTime) {
if (dateTime == DateTime.MinValue)
SetSpecialHeaders(headerName, null); // remove header
else
SetSpecialHeaders(headerName, HttpProtocolUtils.date2string(dateTime));
}
#if !NET_2_1
[MonoTODO]
public static new RequestCachePolicy DefaultCachePolicy
@ -414,7 +422,8 @@ namespace System.Net
if (val == "100-continue")
throw new ArgumentException ("100-Continue cannot be set with this property.",
"value");
webHeaders.RemoveAndAdd ("Expect", value);
webHeaders.CheckUpdate ("Expect", value);
}
}
@ -427,12 +436,21 @@ namespace System.Net
get { return webHeaders; }
set {
CheckRequestStarted ();
WebHeaderCollection newHeaders = new WebHeaderCollection (WebHeaderCollection.HeaderInfo.Request);
int count = value.Count;
for (int i = 0; i < count; i++)
newHeaders.Add (value.GetKey (i), value.Get (i));
webHeaders = newHeaders;
WebHeaderCollection webHeaders = value;
WebHeaderCollection newWebHeaders = new WebHeaderCollection(WebHeaderCollectionType.HttpWebRequest);
// Copy And Validate -
// Handle the case where their object tries to change
// name, value pairs after they call set, so therefore,
// we need to clone their headers.
//
foreach (String headerName in webHeaders.AllKeys ) {
newWebHeaders.Add(headerName,webHeaders[headerName]);
}
webHeaders = newWebHeaders;
}
}
@ -664,7 +682,7 @@ namespace System.Net
if (!sendChunked)
throw new ArgumentException ("SendChunked must be True", "value");
webHeaders.RemoveAndAdd ("Transfer-Encoding", value);
webHeaders.CheckUpdate ("Transfer-Encoding", value);
}
}
@ -772,7 +790,7 @@ namespace System.Net
{
if (rangeSpecifier == null)
throw new ArgumentNullException ("rangeSpecifier");
if (!WebHeaderCollection.IsHeaderValue (rangeSpecifier))
if (!WebHeaderCollection.IsValidToken (rangeSpecifier))
throw new ArgumentException ("Invalid range specifier", "rangeSpecifier");
string r = webHeaders ["Range"];
@ -790,7 +808,7 @@ namespace System.Net
r = r + "0" + n;
else
r = r + n + "-";
webHeaders.RemoveAndAdd ("Range", r);
webHeaders.ChangeInternal ("Range", r);
}
public
@ -798,7 +816,7 @@ namespace System.Net
{
if (rangeSpecifier == null)
throw new ArgumentNullException ("rangeSpecifier");
if (!WebHeaderCollection.IsHeaderValue (rangeSpecifier))
if (!WebHeaderCollection.IsValidToken (rangeSpecifier))
throw new ArgumentException ("Invalid range specifier", "rangeSpecifier");
if (from > to || from < 0)
throw new ArgumentOutOfRangeException ("from");
@ -812,7 +830,7 @@ namespace System.Net
r += ",";
r = String.Format ("{0}{1}-{2}", r, from, to);
webHeaders.RemoveAndAdd ("Range", r);
webHeaders.ChangeInternal ("Range", r);
}
@ -1198,7 +1216,7 @@ namespace System.Net
bool continue100 = false;
if (sendChunked) {
continue100 = true;
webHeaders.RemoveAndAdd ("Transfer-Encoding", "chunked");
webHeaders.ChangeInternal ("Transfer-Encoding", "chunked");
webHeaders.RemoveInternal ("Content-Length");
} else if (contentLength != -1) {
if (auth_state.NtlmAuthState == NtlmAuthState.Challenge || proxy_auth_state.NtlmAuthState == NtlmAuthState.Challenge) {
@ -1221,7 +1239,7 @@ namespace System.Net
if (actualVersion == HttpVersion.Version11 && continue100 &&
servicePoint.SendContinue) { // RFC2616 8.2.3
webHeaders.RemoveAndAdd ("Expect" , "100-continue");
webHeaders.ChangeInternal ("Expect" , "100-continue");
expectContinue = true;
} else {
webHeaders.RemoveInternal ("Expect");
@ -1237,16 +1255,16 @@ namespace System.Net
if (keepAlive && (version == HttpVersion.Version10 || spoint10)) {
if (webHeaders[connectionHeader] == null
|| webHeaders[connectionHeader].IndexOf ("keep-alive", StringComparison.OrdinalIgnoreCase) == -1)
webHeaders.RemoveAndAdd (connectionHeader, "keep-alive");
webHeaders.ChangeInternal (connectionHeader, "keep-alive");
} else if (!keepAlive && version == HttpVersion.Version11) {
webHeaders.RemoveAndAdd (connectionHeader, "close");
webHeaders.ChangeInternal (connectionHeader, "close");
}
webHeaders.SetInternal ("Host", Host);
if (cookieContainer != null) {
string cookieHeader = cookieContainer.GetCookieHeader (actualUri);
if (cookieHeader != "")
webHeaders.RemoveAndAdd ("Cookie", cookieHeader);
webHeaders.ChangeInternal ("Cookie", cookieHeader);
else
webHeaders.RemoveInternal ("Cookie");
}
@ -1257,7 +1275,7 @@ namespace System.Net
if ((auto_decomp & DecompressionMethods.Deflate) != 0)
accept_encoding = accept_encoding != null ? "gzip, deflate" : "deflate";
if (accept_encoding != null)
webHeaders.RemoveAndAdd ("Accept-Encoding", accept_encoding);
webHeaders.ChangeInternal ("Accept-Encoding", accept_encoding);
if (!usedPreAuth && preAuthenticate)
DoPreAuthenticate ();
@ -1297,7 +1315,7 @@ namespace System.Net
wex = new WebException (msg, status);
} else {
msg = String.Format ("Error: {0} ({1})", status, exc.Message);
wex = new WebException (msg, exc, status);
wex = new WebException (msg, status, WebExceptionInternalStatus.RequestFatal, exc);
}
r.SetCompleted (false, wex);
r.DoCallback ();
@ -1616,7 +1634,7 @@ namespace System.Net
if (isProxy && (request.proxy == null || request.proxy.Credentials == null))
return false;
string [] authHeaders = response.Headers.GetValues_internal (isProxy ? "Proxy-Authenticate" : "WWW-Authenticate", false);
string [] authHeaders = response.Headers.GetValues (isProxy ? "Proxy-Authenticate" : "WWW-Authenticate");
if (authHeaders == null || authHeaders.Length == 0)
return false;
@ -1631,7 +1649,7 @@ namespace System.Net
return false;
request.webHeaders [isProxy ? "Proxy-Authorization" : "Authorization"] = auth.Message;
isCompleted = auth.Complete;
bool is_ntlm = (auth.Module.AuthenticationType == "NTLM");
bool is_ntlm = (auth.ModuleAuthenticationType == "NTLM");
if (is_ntlm)
ntlm_auth_state = (NtlmAuthState)((int) ntlm_auth_state + 1);
return true;