Commit 0bfe7a74 authored by Honfika's avatar Honfika

netstandard 2.1 added

parent bac300f3
...@@ -6,11 +6,11 @@ ...@@ -6,11 +6,11 @@
<UseWPF>true</UseWPF> <UseWPF>true</UseWPF>
</PropertyGroup> </PropertyGroup>
<!--<ItemGroup> <ItemGroup Condition="'$(TargetFramework)' == 'net461'">
<Reference Include="PresentationCore" /> <Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" /> <Reference Include="PresentationFramework" />
<Reference Include="WindowsBase" /> <Reference Include="WindowsBase" />
</ItemGroup>--> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Remove="Properties\AssemblyInfo.cs" /> <Compile Remove="Properties\AssemblyInfo.cs" />
...@@ -20,23 +20,6 @@ ...@@ -20,23 +20,6 @@
<ProjectReference Include="..\..\src\Titanium.Web.Proxy\Titanium.Web.Proxy.csproj" /> <ProjectReference Include="..\..\src\Titanium.Web.Proxy\Titanium.Web.Proxy.csproj" />
</ItemGroup> </ItemGroup>
<!--<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Compile Update="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Update="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Update="Properties\Resources.Designer.cs"> <Compile Update="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>
...@@ -52,16 +35,6 @@ ...@@ -52,16 +35,6 @@
<Generator>ResXFileCodeGenerator</Generator> <Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput> <LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource> </EmbeddedResource>
<None Update="App.xaml"> </ItemGroup>
<Generator>MSBuild:Compile</Generator>
</None>
<None Update="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
</None>
<None Update="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>-->
</Project> </Project>
\ No newline at end of file
...@@ -288,8 +288,7 @@ namespace Titanium.Web.Proxy ...@@ -288,8 +288,7 @@ namespace Titanium.Web.Proxy
if (!clientStream.IsClosed && !connection.Stream.IsClosed) if (!clientStream.IsClosed && !connection.Stream.IsClosed)
{ {
await TcpHelper.SendRaw(clientStream, connection.Stream, BufferPool, await TcpHelper.SendRaw(clientStream, connection.Stream, BufferPool,
null, null, null, null, connectArgs.CancellationTokenSource, ExceptionFunc);
connectArgs.CancellationTokenSource, ExceptionFunc);
} }
} }
finally finally
...@@ -338,17 +337,15 @@ namespace Titanium.Web.Proxy ...@@ -338,17 +337,15 @@ namespace Titanium.Web.Proxy
await connection.StreamWriter.WriteLineAsync("SM", cancellationToken); await connection.StreamWriter.WriteLineAsync("SM", cancellationToken);
await connection.StreamWriter.WriteLineAsync(cancellationToken); await connection.StreamWriter.WriteLineAsync(cancellationToken);
#if NETCOREAPP2_1 #if NETCOREAPP2_1
await Http2Helper.SendHttp2(clientStream, connection.Stream, BufferPool.BufferSize, await Http2Helper.SendHttp2(clientStream, connection.Stream,
(buffer, offset, count) => { connectArgs.OnDecryptedDataSent(buffer, offset, count); },
(buffer, offset, count) => { connectArgs.OnDecryptedDataReceived(buffer, offset, count); },
() => new SessionEventArgs(this, endPoint, cancellationTokenSource) () => new SessionEventArgs(this, endPoint, cancellationTokenSource)
{ {
ProxyClient = { Connection = clientConnection }, ProxyClient = { Connection = clientConnection },
HttpClient = { ConnectRequest = connectArgs?.HttpClient.ConnectRequest }, HttpClient = { ConnectRequest = connectArgs?.HttpClient.ConnectRequest },
UserData = connectArgs?.UserData UserData = connectArgs?.UserData
}, },
async args => { await invokeBeforeRequest(args); }, async args => { await onBeforeRequest(args); },
async args => { await invokeBeforeResponse(args); }, async args => { await onBeforeResponse(args); },
connectArgs.CancellationTokenSource, clientConnection.Id, ExceptionFunc); connectArgs.CancellationTokenSource, clientConnection.Id, ExceptionFunc);
#endif #endif
} }
......
...@@ -28,7 +28,7 @@ namespace Titanium.Web.Proxy.Extensions ...@@ -28,7 +28,7 @@ namespace Titanium.Web.Proxy.Extensions
return null; return null;
} }
#if NETCOREAPP2_1 #if NETCOREAPP2_1 || NETSTANDARD2_1
internal static List<SslApplicationProtocol> GetAlpn(this ClientHelloInfo clientHelloInfo) internal static List<SslApplicationProtocol> GetAlpn(this ClientHelloInfo clientHelloInfo)
{ {
if (clientHelloInfo.Extensions != null && clientHelloInfo.Extensions.TryGetValue("ALPN", out var alpnExtension)) if (clientHelloInfo.Extensions != null && clientHelloInfo.Extensions.TryGetValue("ALPN", out var alpnExtension))
...@@ -78,7 +78,7 @@ namespace Titanium.Web.Proxy.Extensions ...@@ -78,7 +78,7 @@ namespace Titanium.Web.Proxy.Extensions
#endif #endif
} }
#if !NETCOREAPP2_1 #if !NETCOREAPP2_1 && !NETSTANDARD2_1
internal enum SslApplicationProtocol internal enum SslApplicationProtocol
{ {
Http11, Http11,
......
#if NETCOREAPP2_1 #if NETCOREAPP2_1 || NETSTANDARD2_1
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
...@@ -24,8 +24,7 @@ namespace Titanium.Web.Proxy.Http2 ...@@ -24,8 +24,7 @@ namespace Titanium.Web.Proxy.Http2
/// Task-based Asynchronous Pattern /// Task-based Asynchronous Pattern
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
internal static async Task SendHttp2(Stream clientStream, Stream serverStream, int bufferSize, internal static async Task SendHttp2(Stream clientStream, Stream serverStream,
Action<byte[], int, int> onDataSend, Action<byte[], int, int> onDataReceive,
Func<SessionEventArgs> sessionFactory, Func<SessionEventArgs> sessionFactory,
Func<SessionEventArgs, Task> onBeforeRequest, Func<SessionEventArgs, Task> onBeforeResponse, Func<SessionEventArgs, Task> onBeforeRequest, Func<SessionEventArgs, Task> onBeforeResponse,
CancellationTokenSource cancellationTokenSource, Guid connectionId, CancellationTokenSource cancellationTokenSource, Guid connectionId,
...@@ -38,13 +37,13 @@ namespace Titanium.Web.Proxy.Http2 ...@@ -38,13 +37,13 @@ namespace Titanium.Web.Proxy.Http2
// Now async relay all server=>client & client=>server data // Now async relay all server=>client & client=>server data
var sendRelay = var sendRelay =
copyHttp2FrameAsync(clientStream, serverStream, onDataSend, clientSettings, serverSettings, copyHttp2FrameAsync(clientStream, serverStream, clientSettings, serverSettings,
sessionFactory, sessions, onBeforeRequest, sessionFactory, sessions, onBeforeRequest,
bufferSize, connectionId, true, cancellationTokenSource.Token, exceptionFunc); connectionId, true, cancellationTokenSource.Token, exceptionFunc);
var receiveRelay = var receiveRelay =
copyHttp2FrameAsync(serverStream, clientStream, onDataReceive, serverSettings, clientSettings, copyHttp2FrameAsync(serverStream, clientStream, serverSettings, clientSettings,
sessionFactory, sessions, onBeforeResponse, sessionFactory, sessions, onBeforeResponse,
bufferSize, connectionId, false, cancellationTokenSource.Token, exceptionFunc); connectionId, false, cancellationTokenSource.Token, exceptionFunc);
await Task.WhenAny(sendRelay, receiveRelay); await Task.WhenAny(sendRelay, receiveRelay);
cancellationTokenSource.Cancel(); cancellationTokenSource.Cancel();
...@@ -52,11 +51,11 @@ namespace Titanium.Web.Proxy.Http2 ...@@ -52,11 +51,11 @@ namespace Titanium.Web.Proxy.Http2
await Task.WhenAll(sendRelay, receiveRelay); await Task.WhenAll(sendRelay, receiveRelay);
} }
private static async Task copyHttp2FrameAsync(Stream input, Stream output, Action<byte[], int, int> onCopy, private static async Task copyHttp2FrameAsync(Stream input, Stream output,
Http2Settings localSettings, Http2Settings remoteSettings, Http2Settings localSettings, Http2Settings remoteSettings,
Func<SessionEventArgs> sessionFactory, ConcurrentDictionary<int, SessionEventArgs> sessions, Func<SessionEventArgs> sessionFactory, ConcurrentDictionary<int, SessionEventArgs> sessions,
Func<SessionEventArgs, Task> onBeforeRequestResponse, Func<SessionEventArgs, Task> onBeforeRequestResponse,
int bufferSize, Guid connectionId, bool isClient, CancellationToken cancellationToken, Guid connectionId, bool isClient, CancellationToken cancellationToken,
ExceptionHandler exceptionFunc) ExceptionHandler exceptionFunc)
{ {
int headerTableSize = 0; int headerTableSize = 0;
...@@ -69,7 +68,6 @@ namespace Titanium.Web.Proxy.Http2 ...@@ -69,7 +68,6 @@ namespace Titanium.Web.Proxy.Http2
{ {
var frameHeaderBuffer = frameHeader.Buffer; var frameHeaderBuffer = frameHeader.Buffer;
int read = await forceRead(input, frameHeaderBuffer, 0, 9, cancellationToken); int read = await forceRead(input, frameHeaderBuffer, 0, 9, cancellationToken);
onCopy(frameHeaderBuffer, 0, read);
if (read != 9) if (read != 9)
{ {
return; return;
...@@ -92,7 +90,6 @@ namespace Titanium.Web.Proxy.Http2 ...@@ -92,7 +90,6 @@ namespace Titanium.Web.Proxy.Http2
} }
read = await forceRead(input, buffer, 0, length, cancellationToken); read = await forceRead(input, buffer, 0, length, cancellationToken);
onCopy(buffer, 0, read);
if (read != length) if (read != length)
{ {
return; return;
...@@ -127,6 +124,11 @@ namespace Titanium.Web.Proxy.Http2 ...@@ -127,6 +124,11 @@ namespace Titanium.Web.Proxy.Http2
//System.Diagnostics.Debug.WriteLine("CONN: " + connectionId + ", CLIENT: " + isClient + ", STREAM: " + streamId + ", TYPE: " + type); //System.Diagnostics.Debug.WriteLine("CONN: " + connectionId + ", CLIENT: " + isClient + ", STREAM: " + streamId + ", TYPE: " + type);
if (type == Http2FrameType.Data && args != null) if (type == Http2FrameType.Data && args != null)
{ {
if (isClient)
args.OnDataSent(buffer, 0, read);
else
args.OnDataReceived(buffer, 0, read);
rr = isClient ? (RequestResponseBase)args.HttpClient.Request : args.HttpClient.Response; rr = isClient ? (RequestResponseBase)args.HttpClient.Request : args.HttpClient.Response;
bool padded = (flags & Http2FrameFlag.Padded) != 0; bool padded = (flags & Http2FrameFlag.Padded) != 0;
...@@ -182,8 +184,10 @@ namespace Titanium.Web.Proxy.Http2 ...@@ -182,8 +184,10 @@ namespace Titanium.Web.Proxy.Http2
{ {
args = sessionFactory(); args = sessionFactory();
args.IsPromise = true; args.IsPromise = true;
sessions.TryAdd(streamId, args); if (!sessions.TryAdd(streamId, args))
sessions.TryAdd(promisedStreamId, args); ;
if (!sessions.TryAdd(promisedStreamId, args))
;
} }
System.Diagnostics.Debug.WriteLine("PROMISE STREAM: " + streamId + ", " + promisedStreamId + System.Diagnostics.Debug.WriteLine("PROMISE STREAM: " + streamId + ", " + promisedStreamId +
...@@ -201,7 +205,8 @@ namespace Titanium.Web.Proxy.Http2 ...@@ -201,7 +205,8 @@ namespace Titanium.Web.Proxy.Http2
if (!sessions.TryGetValue(streamId, out args)) if (!sessions.TryGetValue(streamId, out args))
{ {
args = sessionFactory(); args = sessionFactory();
sessions.TryAdd(streamId, args); if (!sessions.TryAdd(streamId, args))
;
} }
rr = isClient ? (RequestResponseBase)args.HttpClient.Request : args.HttpClient.Response; rr = isClient ? (RequestResponseBase)args.HttpClient.Request : args.HttpClient.Response;
......
using System; using System;
using System.IO; using System.IO;
using System.Net; using System.Net;
#if NETCOREAPP2_1 #if NETCOREAPP2_1 || NETSTANDARD2_1
using System.Net.Security; using System.Net.Security;
#endif #endif
using System.Net.Sockets; using System.Net.Sockets;
......
...@@ -391,7 +391,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -391,7 +391,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
CertificateRevocationCheckMode = proxyServer.CheckCertificateRevocation CertificateRevocationCheckMode = proxyServer.CheckCertificateRevocation
}; };
await sslStream.AuthenticateAsClientAsync(options, cancellationToken); await sslStream.AuthenticateAsClientAsync(options, cancellationToken);
#if NETCOREAPP2_1 #if NETCOREAPP2_1 || NETSTANDARD2_1
negotiatedApplicationProtocol = sslStream.NegotiatedApplicationProtocol; negotiatedApplicationProtocol = sslStream.NegotiatedApplicationProtocol;
#endif #endif
......
using System; using System;
using System.Net; using System.Net;
#if NETCOREAPP2_1 #if NETCOREAPP2_1 || NETSTANDARD2_1
using System.Net.Security; using System.Net.Security;
#endif #endif
using System.Net.Sockets; using System.Net.Sockets;
......
...@@ -3,7 +3,7 @@ using System.Collections.Generic; ...@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
#if NETCOREAPP2_1 #if NETCOREAPP2_1 || NETSTANDARD2_1
using System.Net.Security; using System.Net.Security;
#endif #endif
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
...@@ -143,7 +143,7 @@ namespace Titanium.Web.Proxy ...@@ -143,7 +143,7 @@ namespace Titanium.Web.Proxy
// proxy authorization check // proxy authorization check
if (httpsConnectHostname == null && await checkAuthorization(args) == false) if (httpsConnectHostname == null && await checkAuthorization(args) == false)
{ {
await invokeBeforeResponse(args); await onBeforeResponse(args);
// send the response // send the response
await clientStreamWriter.WriteResponseAsync(args.HttpClient.Response, await clientStreamWriter.WriteResponseAsync(args.HttpClient.Response,
...@@ -166,10 +166,8 @@ namespace Titanium.Web.Proxy ...@@ -166,10 +166,8 @@ namespace Titanium.Web.Proxy
// we need this to syphon out data from connection if API user changes them. // we need this to syphon out data from connection if API user changes them.
request.SetOriginalHeaders(); request.SetOriginalHeaders();
args.TimeLine["Request Received"] = DateTime.Now;
// If user requested interception do it // If user requested interception do it
await invokeBeforeRequest(args); await onBeforeRequest(args);
var response = args.HttpClient.Response; var response = args.HttpClient.Response;
...@@ -286,7 +284,7 @@ namespace Titanium.Web.Proxy ...@@ -286,7 +284,7 @@ namespace Titanium.Web.Proxy
} }
finally finally
{ {
await invokeAfterResponse(args); await onAfterResponse(args);
args.Dispose(); args.Dispose();
} }
} }
...@@ -410,8 +408,10 @@ namespace Titanium.Web.Proxy ...@@ -410,8 +408,10 @@ namespace Titanium.Web.Proxy
/// </summary> /// </summary>
/// <param name="args">The session event arguments.</param> /// <param name="args">The session event arguments.</param>
/// <returns></returns> /// <returns></returns>
private async Task invokeBeforeRequest(SessionEventArgs args) private async Task onBeforeRequest(SessionEventArgs args)
{ {
args.TimeLine["Request Received"] = DateTime.Now;
if (BeforeRequest != null) if (BeforeRequest != null)
{ {
await BeforeRequest.InvokeAsync(this, args, ExceptionFunc); await BeforeRequest.InvokeAsync(this, args, ExceptionFunc);
......
...@@ -58,7 +58,7 @@ namespace Titanium.Web.Proxy ...@@ -58,7 +58,7 @@ namespace Titanium.Web.Proxy
// if user requested call back then do it // if user requested call back then do it
if (!response.Locked) if (!response.Locked)
{ {
await invokeBeforeResponse(args); await onBeforeResponse(args);
} }
// it may changed in the user event // it may changed in the user event
...@@ -132,7 +132,7 @@ namespace Titanium.Web.Proxy ...@@ -132,7 +132,7 @@ namespace Titanium.Web.Proxy
/// </summary> /// </summary>
/// <param name="args"></param> /// <param name="args"></param>
/// <returns></returns> /// <returns></returns>
private async Task invokeBeforeResponse(SessionEventArgs args) private async Task onBeforeResponse(SessionEventArgs args)
{ {
if (BeforeResponse != null) if (BeforeResponse != null)
{ {
...@@ -145,7 +145,7 @@ namespace Titanium.Web.Proxy ...@@ -145,7 +145,7 @@ namespace Titanium.Web.Proxy
/// </summary> /// </summary>
/// <param name="args"></param> /// <param name="args"></param>
/// <returns></returns> /// <returns></returns>
private async Task invokeAfterResponse(SessionEventArgs args) private async Task onAfterResponse(SessionEventArgs args)
{ {
if (AfterResponse != null) if (AfterResponse != null)
{ {
......
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>netstandard2.0;netcoreapp2.1</TargetFrameworks> <TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp2.1</TargetFrameworks>
<RootNamespace>Titanium.Web.Proxy</RootNamespace> <RootNamespace>Titanium.Web.Proxy</RootNamespace>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo> <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<SignAssembly>True</SignAssembly> <SignAssembly>True</SignAssembly>
...@@ -26,6 +26,15 @@ ...@@ -26,6 +26,15 @@
</PackageReference> </PackageReference>
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
<PackageReference Include="Microsoft.Win32.Registry">
<Version>4.5.0</Version>
</PackageReference>
<PackageReference Include="System.Security.Principal.Windows">
<Version>4.5.1</Version>
</PackageReference>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'"> <ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
<PackageReference Include="Microsoft.Win32.Registry"> <PackageReference Include="Microsoft.Win32.Registry">
<Version>4.5.0</Version> <Version>4.5.0</Version>
......
...@@ -60,7 +60,7 @@ namespace Titanium.Web.Proxy ...@@ -60,7 +60,7 @@ namespace Titanium.Web.Proxy
// If user requested call back then do it // If user requested call back then do it
if (!args.HttpClient.Response.Locked) if (!args.HttpClient.Response.Locked)
{ {
await invokeBeforeResponse(args); await onBeforeResponse(args);
} }
await TcpHelper.SendRaw(clientStream, serverConnection.Stream, BufferPool, await TcpHelper.SendRaw(clientStream, serverConnection.Stream, BufferPool,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment