Skip to content

Commit

Permalink
New PR for the new web stack (mono#6125)
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Baulig authored and UnityAlex committed Aug 29, 2019
1 parent b73fd4a commit c847b46
Show file tree
Hide file tree
Showing 23 changed files with 3,425 additions and 3,408 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ protected async internal override Task<HttpResponseMessage> SendAsync (HttpReque
}
}

wrequest.ResendContentFactory = content.CopyTo;
wrequest.ResendContentFactory = content.CopyToAsync;

using (var stream = await wrequest.GetRequestStreamAsync ().ConfigureAwait (false)) {
await request.Content.CopyToAsync (stream).ConfigureAwait (false);
Expand Down
23 changes: 15 additions & 8 deletions mcs/class/System/Mono.Net.Security/MonoTlsStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace Mono.Net.Security
{
class MonoTlsStream
{
#if SECURITY_DEP
#if SECURITY_DEP
readonly MonoTlsProvider provider;
readonly NetworkStream networkStream;
readonly HttpWebRequest request;
Expand Down Expand Up @@ -99,9 +99,11 @@ public MonoTlsStream (HttpWebRequest request, NetworkStream networkStream)
#endif
}

internal Stream CreateStream (byte[] buffer)
internal async Task<Stream> CreateStream (WebConnectionTunnel tunnel, CancellationToken cancellationToken)
{
#if SECURITY_DEP
var socket = networkStream.InternalSocket;
WebConnection.Debug ($"MONO TLS STREAM CREATE STREAM: {socket.ID}");
sslStream = provider.CreateSslStream (networkStream, false, settings);

try {
Expand All @@ -112,16 +114,21 @@ internal Stream CreateStream (byte[] buffer)
host = host.Substring (0, pos);
}

sslStream.AuthenticateAsClient (
await sslStream.AuthenticateAsClientAsync (
host, request.ClientCertificates,
(SslProtocols)ServicePointManager.SecurityProtocol,
ServicePointManager.CheckCertificateRevocationList);
ServicePointManager.CheckCertificateRevocationList).ConfigureAwait (false);

status = WebExceptionStatus.Success;
} catch {
status = WebExceptionStatus.SecureChannelFailure;
} catch (Exception ex) {
WebConnection.Debug ($"MONO TLS STREAM ERROR: {socket.ID} {socket.CleanedUp} {ex.Message}");
if (socket.CleanedUp)
status = WebExceptionStatus.RequestCanceled;
else
status = WebExceptionStatus.SecureChannelFailure;
throw;
} finally {
WebConnection.Debug ($"MONO TLS STREAM CREATE STREAM DONE: {socket.ID} {socket.CleanedUp}");
if (CertificateValidationFailed)
status = WebExceptionStatus.TrustFailure;

Expand All @@ -134,8 +141,8 @@ internal Stream CreateStream (byte[] buffer)
}

try {
if (buffer != null)
sslStream.Write (buffer, 0, buffer.Length);
if (tunnel?.Data != null)
await sslStream.WriteAsync (tunnel.Data, 0, tunnel.Data.Length, cancellationToken).ConfigureAwait (false);
} catch {
status = WebExceptionStatus.SendFailure;
sslStream = null;
Expand Down
2 changes: 2 additions & 0 deletions mcs/class/System/ReferenceSources/SR2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ partial class SR
public const string net_log_set_socketoption_reuseport_default_on = "net_log_set_socketoption_reuseport_default_on";
public const string net_log_set_socketoption_reuseport_not_supported = "net_log_set_socketoption_reuseport_not_supported";
public const string net_log_set_socketoption_reuseport = "net_log_set_socketoption_reuseport";

public const string net_reqaborted = "The request was aborted: The request was canceled.";
}
11 changes: 9 additions & 2 deletions mcs/class/System/System.Net.Sockets/Socket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
using System.Timers;
using System.Net.NetworkInformation;

namespace System.Net.Sockets
namespace System.Net.Sockets
{
public partial class Socket : IDisposable
{
Expand Down Expand Up @@ -91,7 +91,14 @@ public partial class Socket : IDisposable
int m_IntCleanedUp;
internal bool connect_in_progress;

#region Constructors
#if MONO_WEB_DEBUG
static int nextId;
internal readonly int ID = ++nextId;
#else
internal readonly int ID;
#endif

#region Constructors


public Socket (SocketInformation socketInformation)
Expand Down
Loading

0 comments on commit c847b46

Please sign in to comment.