From 6e3ae0067f1432b831fd90edc4e8d0531fade796 Mon Sep 17 00:00:00 2001 From: Honfika Date: Wed, 24 Apr 2019 22:14:17 +0200 Subject: [PATCH 1/4] call the event handlers from http/2 code --- src/Titanium.Web.Proxy/Http2/Http2Helper.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Titanium.Web.Proxy/Http2/Http2Helper.cs b/src/Titanium.Web.Proxy/Http2/Http2Helper.cs index fe3c7e28e..a5c6af8f2 100644 --- a/src/Titanium.Web.Proxy/Http2/Http2Helper.cs +++ b/src/Titanium.Web.Proxy/Http2/Http2Helper.cs @@ -63,6 +63,7 @@ private static async Task CopyHttp2FrameAsync(Stream input, Stream output, Actio while (true) { int read = await ForceRead(input, headerBuffer, 0, 9, cancellationToken); + onCopy(headerBuffer, 0, read); if (read != 9) { return; @@ -75,6 +76,7 @@ private static async Task CopyHttp2FrameAsync(Stream input, Stream output, Actio headerBuffer[8]; read = await ForceRead(input, buffer, 0, length, cancellationToken); + onCopy(buffer, 0, read); if (read != length) { return; @@ -138,7 +140,7 @@ private static async Task ForceRead(Stream input, byte[] buffer, int offset while (bytesToRead > 0) { int read = await input.ReadAsync(buffer, offset, bytesToRead, cancellationToken); - if (read == -1) + if (read == 0) { break; } From 56c835cb43acff88bda8a9a53ef738918c453de9 Mon Sep 17 00:00:00 2001 From: Honfika Date: Wed, 24 Apr 2019 22:19:39 +0200 Subject: [PATCH 2/4] typo fix, http2 enabled flag added --- src/Titanium.Web.Proxy/ExplicitClientHandler.cs | 6 +++--- src/Titanium.Web.Proxy/Models/ExplicitProxyEndPoint.cs | 2 +- src/Titanium.Web.Proxy/ProxyServer.cs | 6 ++++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Titanium.Web.Proxy/ExplicitClientHandler.cs b/src/Titanium.Web.Proxy/ExplicitClientHandler.cs index 0d1ce0776..d47ab5e40 100644 --- a/src/Titanium.Web.Proxy/ExplicitClientHandler.cs +++ b/src/Titanium.Web.Proxy/ExplicitClientHandler.cs @@ -103,7 +103,7 @@ await clientStreamWriter.WriteResponseAsync(connectArgs.HttpClient.Response, if (await checkAuthorization(connectArgs) == false) { - await endPoint.InvokeBeforeTunnectConnectResponse(this, connectArgs, ExceptionFunc); + await endPoint.InvokeBeforeTunnelConnectResponse(this, connectArgs, ExceptionFunc); // send the response await clientStreamWriter.WriteResponseAsync(connectArgs.HttpClient.Response, @@ -129,7 +129,7 @@ await clientStreamWriter.WriteResponseAsync(connectArgs.HttpClient.Response, connectRequest.ClientHelloInfo = clientHelloInfo; } - await endPoint.InvokeBeforeTunnectConnectResponse(this, connectArgs, ExceptionFunc, isClientHello); + await endPoint.InvokeBeforeTunnelConnectResponse(this, connectArgs, ExceptionFunc, isClientHello); if (decryptSsl && isClientHello) { @@ -183,7 +183,7 @@ await clientStreamWriter.WriteResponseAsync(connectArgs.HttpClient.Response, // Successfully managed to authenticate the client using the fake certificate var options = new SslServerAuthenticationOptions(); - if (http2Supported) + if (EnableHttp2 && http2Supported) { options.ApplicationProtocols = clientHelloInfo.GetAlpn(); if (options.ApplicationProtocols == null || options.ApplicationProtocols.Count == 0) diff --git a/src/Titanium.Web.Proxy/Models/ExplicitProxyEndPoint.cs b/src/Titanium.Web.Proxy/Models/ExplicitProxyEndPoint.cs index af4a6fb29..84ca63448 100644 --- a/src/Titanium.Web.Proxy/Models/ExplicitProxyEndPoint.cs +++ b/src/Titanium.Web.Proxy/Models/ExplicitProxyEndPoint.cs @@ -50,7 +50,7 @@ internal async Task InvokeBeforeTunnelConnectRequest(ProxyServer proxyServer, } } - internal async Task InvokeBeforeTunnectConnectResponse(ProxyServer proxyServer, + internal async Task InvokeBeforeTunnelConnectResponse(ProxyServer proxyServer, TunnelConnectSessionEventArgs connectArgs, ExceptionHandler exceptionFunc, bool isClientHello = false) { if (BeforeTunnelConnectResponse != null) diff --git a/src/Titanium.Web.Proxy/ProxyServer.cs b/src/Titanium.Web.Proxy/ProxyServer.cs index 45d56f1f6..d8de74d8f 100644 --- a/src/Titanium.Web.Proxy/ProxyServer.cs +++ b/src/Titanium.Web.Proxy/ProxyServer.cs @@ -144,6 +144,12 @@ public ProxyServer(string rootCertificateName, string rootCertificateIssuerName, /// Defaults to false. /// public bool EnableWinAuth { get; set; } + + /// + /// Enable disable HTTP/2 support. This setting is internal, + /// because the implementation is not finished + /// + internal bool EnableHttp2 { get; set; } = false; /// /// Should we check for certificate revocation during SSL authentication to servers From 1a33a5dba512f500a3c1ccbbc4184b8f6f1e25f3 Mon Sep 17 00:00:00 2001 From: Honfika Date: Wed, 24 Apr 2019 22:20:16 +0200 Subject: [PATCH 3/4] nuget packages updated in NetCore project file, too --- src/Titanium.Web.Proxy/Titanium.Web.Proxy.NetCore.csproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Titanium.Web.Proxy/Titanium.Web.Proxy.NetCore.csproj b/src/Titanium.Web.Proxy/Titanium.Web.Proxy.NetCore.csproj index 86b3387eb..8da49ea49 100644 --- a/src/Titanium.Web.Proxy/Titanium.Web.Proxy.NetCore.csproj +++ b/src/Titanium.Web.Proxy/Titanium.Web.Proxy.NetCore.csproj @@ -12,9 +12,9 @@ - - - + + + From b3a486fb1766d71db1a393155289ec9d2e456dd9 Mon Sep 17 00:00:00 2001 From: Honfika Date: Wed, 24 Apr 2019 22:23:02 +0200 Subject: [PATCH 4/4] netcoreapp2.1 target added (needed for ALPN support) --- src/Titanium.Web.Proxy/Titanium.Web.Proxy.csproj | 2 +- src/Titanium.Web.Proxy/Titanium.Web.Proxy.nuspec | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Titanium.Web.Proxy/Titanium.Web.Proxy.csproj b/src/Titanium.Web.Proxy/Titanium.Web.Proxy.csproj index 755d80122..fab5c20f9 100644 --- a/src/Titanium.Web.Proxy/Titanium.Web.Proxy.csproj +++ b/src/Titanium.Web.Proxy/Titanium.Web.Proxy.csproj @@ -1,7 +1,7 @@  - net45;netstandard2.0 + net45;netstandard2.0;netcoreapp2.1 Titanium.Web.Proxy false True diff --git a/src/Titanium.Web.Proxy/Titanium.Web.Proxy.nuspec b/src/Titanium.Web.Proxy/Titanium.Web.Proxy.nuspec index ac4b0a219..c08d30d82 100644 --- a/src/Titanium.Web.Proxy/Titanium.Web.Proxy.nuspec +++ b/src/Titanium.Web.Proxy/Titanium.Web.Proxy.nuspec @@ -26,6 +26,13 @@ + + + + + + +