Imported Upstream version 4.8.0.309

Former-commit-id: 5f9c6ae75f295e057a7d2971f3a6df4656fa8850
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2016-11-10 13:04:39 +00:00
parent ee1447783b
commit 94b2861243
4912 changed files with 390737 additions and 49310 deletions

View File

@@ -147,7 +147,7 @@ namespace System.Net.Http.Headers
if (t != Token.Type.Token)
return false;
int nvalue;
long nvalue;
if (!lexer.IsStarStringValue (t)) {
if (!lexer.TryGetNumericValue (t, out nvalue)) {
var s = lexer.GetStringValue (t);
@@ -158,12 +158,12 @@ namespace System.Net.Http.Headers
if (sep.Length != 2)
return false;
if (!int.TryParse (sep[0], NumberStyles.None, CultureInfo.InvariantCulture, out nvalue))
if (!long.TryParse (sep[0], NumberStyles.None, CultureInfo.InvariantCulture, out nvalue))
return false;
value.From = nvalue;
if (!int.TryParse (sep[1], NumberStyles.None, CultureInfo.InvariantCulture, out nvalue))
if (!long.TryParse (sep[1], NumberStyles.None, CultureInfo.InvariantCulture, out nvalue))
return false;
value.To = nvalue;

View File

@@ -70,14 +70,21 @@ namespace System.Net.Http.Headers
return null;
var c = (HttpHeaderValueCollection<U>) collection;
if (c.Count == 0)
return null;
if (c.Count == 0) {
if (c.InvalidValues == null)
return null;
return new List<string> (c.InvalidValues);
}
var list = new List<string> ();
foreach (var item in c) {
list.Add (item.ToString ());
}
if (c.InvalidValues != null)
list.AddRange (c.InvalidValues);
return list;
}

View File

@@ -36,6 +36,7 @@ namespace System.Net.Http.Headers
readonly List<T> list;
readonly HttpHeaders headers;
readonly HeaderInfo headerInfo;
List<string> invalidValues;
internal HttpHeaderValueCollection (HttpHeaders headers, HeaderInfo headerInfo)
{
@@ -50,6 +51,12 @@ namespace System.Net.Http.Headers
}
}
internal List<string> InvalidValues {
get {
return invalidValues;
}
}
public bool IsReadOnly {
get {
return false;
@@ -66,9 +73,18 @@ namespace System.Net.Http.Headers
list.AddRange (values);
}
internal void AddInvalidValue (string invalidValue)
{
if (invalidValues == null)
invalidValues = new List<string> ();
invalidValues.Add (invalidValue);
}
public void Clear ()
{
list.Clear ();
invalidValues = null;
}
public bool Contains (T item)
@@ -93,11 +109,12 @@ namespace System.Net.Http.Headers
public override string ToString ()
{
// This implementation prints different values than
// what .NET does when one of the values is invalid
// But it better represents what is actually hold by
// the collection
return string.Join (headerInfo.Separator, list);
var res = string.Join (headerInfo.Separator, list);
if (invalidValues != null)
res += string.Join (headerInfo.Separator, invalidValues);
return res;
}
public bool TryParseAdd (string input)

View File

@@ -481,23 +481,28 @@ namespace System.Net.Http.Headers
headers.Add (name, value);
}
var col = (HttpHeaderValueCollection<T>) value.Parsed;
if (value.HasStringValues) {
var hinfo = known_headers[name];
if (value.Parsed == null)
value.Parsed = hinfo.CreateCollection (this);
if (col == null) {
value.Parsed = col = new HttpHeaderValueCollection<T> (this, hinfo);
}
object pvalue;
for (int i = 0; i < value.Values.Count; ++i) {
if (!hinfo.TryParse (value.Values[i], out pvalue))
continue;
hinfo.AddToCollection (value.Parsed, pvalue);
value.Values.RemoveAt (i);
--i;
var svalue = value.Values[i];
if (!hinfo.TryParse (svalue, out pvalue)) {
col.AddInvalidValue (svalue);
} else {
hinfo.AddToCollection (col, pvalue);
}
}
value.Values.Clear ();
}
return (HttpHeaderValueCollection<T>) value.Parsed;
return col;
}
internal void SetValue<T> (string name, T value, Func<object, string> toStringConverter = null)

View File

@@ -380,7 +380,9 @@ namespace System.Net.Http
}
} catch (WebException we) {
if (we.Status != WebExceptionStatus.RequestCanceled)
throw;
throw new HttpRequestException ("An error occurred while sending the request", we);
} catch (System.IO.IOException ex) {
throw new HttpRequestException ("An error occurred while sending the request", ex);
}
if (cancellationToken.IsCancellationRequested) {

View File

@@ -0,0 +1,175 @@
//
// System.Net.Http/HttpClientHandler.cs
//
// Author:
// Rolf Bjarne Kvinge <rolf@xamarin.com>
//
// Copyright (C) 2016 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Collections.Generic;
using System.Net.Security;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using System.Threading;
namespace System.Net.Http
{
public class HttpClientHandler : HttpMessageHandler
{
const string EXCEPTION_MESSAGE = "System.Net.Http.HttpClientHandler is not supported on the current platform.";
public HttpClientHandler ()
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public bool AllowAutoRedirect {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public DecompressionMethods AutomaticDecompression {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public ClientCertificateOption ClientCertificateOptions {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public CookieContainer CookieContainer {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public ICredentials Credentials {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public int MaxAutomaticRedirections {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public long MaxRequestContentBufferSize {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public bool PreAuthenticate {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public IWebProxy Proxy {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public virtual bool SupportsAutomaticDecompression {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public virtual bool SupportsProxy {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public virtual bool SupportsRedirectConfiguration {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public bool UseCookies {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public bool UseDefaultCredentials {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public bool UseProxy {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
protected override void Dispose (bool disposing)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
HttpResponseMessage CreateResponseMessage (HttpWebResponse wr, HttpRequestMessage requestMessage, CancellationToken cancellationToken)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
protected internal async override Task<HttpResponseMessage> SendAsync (HttpRequestMessage request, CancellationToken cancellationToken)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
#if NETSTANDARD
public bool CheckCertificateRevocationList {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public X509CertificateCollection ClientCertificates {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public ICredentials DefaultProxyCredentials {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public int MaxConnectionsPerServer {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public int MaxResponseHeadersLength {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public IDictionary<string,object> Properties {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public Func<HttpRequestMessage,X509Certificate2,X509Chain,SslPolicyErrors,bool> ServerCertificateCustomValidationCallback {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public SslProtocols SslProtocols {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
#endif
}
}

View File

@@ -91,5 +91,42 @@ namespace MonoTests.System.Net.Http.Headers
Assert.AreEqual ("kk, ttt", headers.Connection.ToString (), "#3");
}
[Test]
public void AddInvalid ()
{
HttpRequestMessage message = new HttpRequestMessage ();
HttpRequestHeaders headers = message.Headers;
headers.TryAddWithoutValidation ("User-Agent", "user,agent/1.0");
Assert.AreEqual (0, headers.UserAgent.Count, "#1");
Assert.AreEqual ("user,agent/1.0", headers.UserAgent.ToString (), "#2");
Assert.AreEqual ("User-Agent: user,agent/1.0\r\n", headers.ToString (), "#3");
headers.UserAgent.Clear ();
Assert.AreEqual ("", headers.UserAgent.ToString (), "#4");
Assert.AreEqual ("", headers.ToString (), "#5");
}
[Test]
public void AddInvalidAndValid ()
{
HttpRequestMessage message = new HttpRequestMessage ();
HttpRequestHeaders headers = message.Headers;
headers.TryAddWithoutValidation ("User-Agent", "user,agent/1.0");
headers.TryAddWithoutValidation("User-Agent", "agent2/2.0");
Assert.AreEqual (1, headers.UserAgent.Count, "#1");
Assert.AreEqual ("agent2/2.0user,agent/1.0", headers.UserAgent.ToString (), "#2");
Assert.AreEqual ("User-Agent: agent2/2.0 user,agent/1.0\r\n", headers.ToString (), "#3");
headers.UserAgent.Clear ();
Assert.AreEqual ("", headers.UserAgent.ToString (), "#4");
Assert.AreEqual ("", headers.ToString (), "#5");
}
}
}

View File

@@ -61,6 +61,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
#if FEATURE_NO_BSD_SOCKETS
[ExpectedException (typeof (PlatformNotSupportedException))]
#endif
public void Properties_Defaults ()
{
var h = new HttpClientHandler ();
@@ -83,6 +86,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
#if FEATURE_NO_BSD_SOCKETS
[ExpectedException (typeof (PlatformNotSupportedException))]
#endif
public void Properties_Invalid ()
{
var h = new HttpClientHandler ();
@@ -107,6 +113,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
#if FEATURE_NO_BSD_SOCKETS
[ExpectedException (typeof (PlatformNotSupportedException))]
#endif
public void Properties_AfterClientCreation ()
{
var h = new HttpClientHandler ();
@@ -119,6 +128,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
#if FEATURE_NO_BSD_SOCKETS
[ExpectedException (typeof (PlatformNotSupportedException))]
#endif
public void Disposed ()
{
var h = new HttpClientHandler ();

View File

@@ -263,6 +263,10 @@ namespace MonoTests.System.Net.Http
[Test]
#if FEATURE_NO_BSD_SOCKETS
// Using HttpClientHandler, which indirectly requires BSD sockets.
[ExpectedException (typeof (PlatformNotSupportedException))]
#endif
public void CancelRequestViaProxy ()
{
var handler = new HttpClientHandler {
@@ -321,6 +325,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
#if FEATURE_NO_BSD_SOCKETS
[ExpectedException (typeof (PlatformNotSupportedException))]
#endif
public void Proxy_Disabled ()
{
var pp = WebRequest.DefaultWebProxy;
@@ -397,6 +404,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
#if FEATURE_NO_BSD_SOCKETS
[ExpectedException (typeof (PlatformNotSupportedException))]
#endif
public void Send_Complete_Default ()
{
bool? failed = null;
@@ -441,6 +451,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
#if FEATURE_NO_BSD_SOCKETS
[ExpectedException (typeof (PlatformNotSupportedException))]
#endif
public void Send_Complete_Version_1_0 ()
{
bool? failed = null;
@@ -488,6 +501,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
#if FEATURE_NO_BSD_SOCKETS
[ExpectedException (typeof (PlatformNotSupportedException))]
#endif
public void Send_Complete_ClientHandlerSettings ()
{
bool? failed = null;
@@ -552,6 +568,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
#if FEATURE_NO_BSD_SOCKETS
[ExpectedException (typeof (PlatformNotSupportedException))]
#endif
public void Send_Complete_CustomHeaders ()
{
bool? failed = null;
@@ -616,6 +635,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
#if FEATURE_NO_BSD_SOCKETS
[ExpectedException (typeof (PlatformNotSupportedException))]
#endif
public void Send_Complete_CustomHeaders_SpecialSeparators ()
{
bool? failed = null;
@@ -650,6 +672,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
#if FEATURE_NO_BSD_SOCKETS
[ExpectedException (typeof (PlatformNotSupportedException))]
#endif
public void Send_Complete_CustomHeaders_Host ()
{
bool? failed = null;
@@ -683,6 +708,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
#if FEATURE_NO_BSD_SOCKETS
[ExpectedException (typeof (PlatformNotSupportedException))]
#endif
public void Send_Transfer_Encoding_Chunked ()
{
bool? failed = null;
@@ -712,6 +740,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
#if FEATURE_NO_BSD_SOCKETS
[ExpectedException (typeof (PlatformNotSupportedException))]
#endif
public void Send_Transfer_Encoding_Custom ()
{
bool? failed = null;
@@ -740,6 +771,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
#if FEATURE_NO_BSD_SOCKETS
[ExpectedException (typeof (PlatformNotSupportedException))]
#endif
public void Send_Complete_Content ()
{
var listener = CreateListener (l => {
@@ -767,6 +801,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
#if FEATURE_NO_BSD_SOCKETS
[ExpectedException (typeof (PlatformNotSupportedException))]
#endif
public void Send_Complete_Content_MaxResponseContentBufferSize ()
{
var listener = CreateListener (l => {
@@ -789,6 +826,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
#if FEATURE_NO_BSD_SOCKETS
[ExpectedException (typeof (PlatformNotSupportedException))]
#endif
public void Send_Complete_Content_MaxResponseContentBufferSize_Error ()
{
var listener = CreateListener (l => {
@@ -815,6 +855,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
#if FEATURE_NO_BSD_SOCKETS
[ExpectedException (typeof (PlatformNotSupportedException))]
#endif
public void Send_Complete_NoContent ()
{
foreach (var method in new HttpMethod[] { HttpMethod.Post, HttpMethod.Put, HttpMethod.Delete }) {
@@ -847,6 +890,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
#if FEATURE_NO_BSD_SOCKETS
[ExpectedException (typeof (PlatformNotSupportedException))]
#endif
public void Send_Complete_Error ()
{
var listener = CreateListener (l => {
@@ -867,6 +913,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
#if FEATURE_NO_BSD_SOCKETS
[ExpectedException (typeof (PlatformNotSupportedException))]
#endif
public void Send_Content_Get ()
{
var listener = CreateListener (l => {
@@ -886,6 +935,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
#if FEATURE_NO_BSD_SOCKETS
[ExpectedException (typeof (PlatformNotSupportedException))]
#endif
public void Send_Content_BomEncoding ()
{
var listener = CreateListener (l => {
@@ -910,6 +962,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
#if FEATURE_NO_BSD_SOCKETS
[ExpectedException (typeof (PlatformNotSupportedException))]
#endif
public void Send_Content_Put ()
{
bool passed = false;
@@ -935,6 +990,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
#if FEATURE_NO_BSD_SOCKETS
[ExpectedException (typeof (PlatformNotSupportedException))]
#endif
public void Send_Content_Put_CustomStream ()
{
bool passed = false;
@@ -1037,6 +1095,9 @@ namespace MonoTests.System.Net.Http
[Test]
[Category ("MobileNotWorking")] // Missing encoding
#if FEATURE_NO_BSD_SOCKETS
[ExpectedException (typeof (PlatformNotSupportedException))]
#endif
public void GetString_Many ()
{
Action<HttpListenerContext> context = (HttpListenerContext l) => {
@@ -1066,6 +1127,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
#if FEATURE_NO_BSD_SOCKETS
[ExpectedException (typeof (PlatformNotSupportedException))]
#endif
public void GetByteArray_ServerError ()
{
var listener = CreateListener (l => {
@@ -1088,6 +1152,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
#if FEATURE_NO_BSD_SOCKETS
[ExpectedException (typeof (PlatformNotSupportedException))]
#endif
public void DisallowAutoRedirect ()
{
var listener = CreateListener (l => {
@@ -1116,6 +1183,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
#if FEATURE_NO_BSD_SOCKETS
[ExpectedException (typeof (PlatformNotSupportedException))]
#endif
public void RequestUriAfterRedirect ()
{
var listener = CreateListener (l => {
@@ -1156,6 +1226,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
#if FEATURE_NO_BSD_SOCKETS
[ExpectedException (typeof (PlatformNotSupportedException))]
#endif
/*
* Properties may only be modified before sending the first request.
*/
@@ -1186,6 +1259,10 @@ namespace MonoTests.System.Net.Http
}
[Test]
#if FEATURE_NO_BSD_SOCKETS
// Using HttpClientHandler, which indirectly requires BSD sockets.
[ExpectedException (typeof (PlatformNotSupportedException))]
#endif
/*
* However, this policy is not enforced for custom handlers and there
* is also no way a derived class could tell its HttpClientHandler parent

View File

@@ -0,0 +1 @@
System.Net.Http/HttpClientHandler.cs

View File

@@ -0,0 +1,2 @@
#include System.Net.Http.dll.sources
System.Net.Http/HttpClientHandler.platformnotsupported.cs