Commit 0bfe7a74 authored by Honfika's avatar Honfika

netstandard 2.1 added

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