Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Commit 0bfe7a7

Browse files
committed
netstandard 2.1 added
1 parent bac300f commit 0bfe7a7

File tree

11 files changed

+52
-68
lines changed

11 files changed

+52
-68
lines changed

examples/Titanium.Web.Proxy.Examples.Wpf/Titanium.Web.Proxy.Examples.Wpf.csproj

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
<UseWPF>true</UseWPF>
77
</PropertyGroup>
88

9-
<!--<ItemGroup>
9+
<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
1010
<Reference Include="PresentationCore" />
1111
<Reference Include="PresentationFramework" />
1212
<Reference Include="WindowsBase" />
13-
</ItemGroup>-->
13+
</ItemGroup>
1414

1515
<ItemGroup>
1616
<Compile Remove="Properties\AssemblyInfo.cs" />
@@ -20,23 +20,6 @@
2020
<ProjectReference Include="..\..\src\Titanium.Web.Proxy\Titanium.Web.Proxy.csproj" />
2121
</ItemGroup>
2222

23-
<!--<ItemGroup>
24-
<ApplicationDefinition Include="App.xaml">
25-
<Generator>MSBuild:Compile</Generator>
26-
<SubType>Designer</SubType>
27-
</ApplicationDefinition>
28-
<Page Include="MainWindow.xaml">
29-
<Generator>MSBuild:Compile</Generator>
30-
<SubType>Designer</SubType>
31-
</Page>
32-
<Compile Update="App.xaml.cs">
33-
<DependentUpon>App.xaml</DependentUpon>
34-
</Compile>
35-
<Compile Update="MainWindow.xaml.cs">
36-
<DependentUpon>MainWindow.xaml</DependentUpon>
37-
</Compile>
38-
</ItemGroup>
39-
4023
<ItemGroup>
4124
<Compile Update="Properties\Resources.Designer.cs">
4225
<AutoGen>True</AutoGen>
@@ -52,16 +35,6 @@
5235
<Generator>ResXFileCodeGenerator</Generator>
5336
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
5437
</EmbeddedResource>
55-
<None Update="App.xaml">
56-
<Generator>MSBuild:Compile</Generator>
57-
</None>
58-
<None Update="MainWindow.xaml">
59-
<Generator>MSBuild:Compile</Generator>
60-
</None>
61-
<None Update="Properties\Settings.settings">
62-
<Generator>SettingsSingleFileGenerator</Generator>
63-
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
64-
</None>
65-
</ItemGroup>-->
38+
</ItemGroup>
6639

6740
</Project>

src/Titanium.Web.Proxy/ExplicitClientHandler.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,7 @@ await clientStreamWriter.WriteResponseAsync(connectArgs.HttpClient.Response,
288288
if (!clientStream.IsClosed && !connection.Stream.IsClosed)
289289
{
290290
await TcpHelper.SendRaw(clientStream, connection.Stream, BufferPool,
291-
null, null,
292-
connectArgs.CancellationTokenSource, ExceptionFunc);
291+
null, null, connectArgs.CancellationTokenSource, ExceptionFunc);
293292
}
294293
}
295294
finally
@@ -338,17 +337,15 @@ await TcpHelper.SendRaw(clientStream, connection.Stream, BufferPool,
338337
await connection.StreamWriter.WriteLineAsync("SM", cancellationToken);
339338
await connection.StreamWriter.WriteLineAsync(cancellationToken);
340339
#if NETCOREAPP2_1
341-
await Http2Helper.SendHttp2(clientStream, connection.Stream, BufferPool.BufferSize,
342-
(buffer, offset, count) => { connectArgs.OnDecryptedDataSent(buffer, offset, count); },
343-
(buffer, offset, count) => { connectArgs.OnDecryptedDataReceived(buffer, offset, count); },
340+
await Http2Helper.SendHttp2(clientStream, connection.Stream,
344341
() => new SessionEventArgs(this, endPoint, cancellationTokenSource)
345342
{
346343
ProxyClient = { Connection = clientConnection },
347344
HttpClient = { ConnectRequest = connectArgs?.HttpClient.ConnectRequest },
348345
UserData = connectArgs?.UserData
349346
},
350-
async args => { await invokeBeforeRequest(args); },
351-
async args => { await invokeBeforeResponse(args); },
347+
async args => { await onBeforeRequest(args); },
348+
async args => { await onBeforeResponse(args); },
352349
connectArgs.CancellationTokenSource, clientConnection.Id, ExceptionFunc);
353350
#endif
354351
}

src/Titanium.Web.Proxy/Extensions/SslExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ internal static string GetServerName(this ClientHelloInfo clientHelloInfo)
2828
return null;
2929
}
3030

31-
#if NETCOREAPP2_1
31+
#if NETCOREAPP2_1 || NETSTANDARD2_1
3232
internal static List<SslApplicationProtocol> GetAlpn(this ClientHelloInfo clientHelloInfo)
3333
{
3434
if (clientHelloInfo.Extensions != null && clientHelloInfo.Extensions.TryGetValue("ALPN", out var alpnExtension))
@@ -78,7 +78,7 @@ internal static Task AuthenticateAsServerAsync(this SslStream sslStream, SslServ
7878
#endif
7979
}
8080

81-
#if !NETCOREAPP2_1
81+
#if !NETCOREAPP2_1 && !NETSTANDARD2_1
8282
internal enum SslApplicationProtocol
8383
{
8484
Http11,

src/Titanium.Web.Proxy/Http2/Http2Helper.cs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if NETCOREAPP2_1
1+
#if NETCOREAPP2_1 || NETSTANDARD2_1
22
using System;
33
using System.Collections.Concurrent;
44
using System.Collections.Generic;
@@ -24,8 +24,7 @@ internal class Http2Helper
2424
/// Task-based Asynchronous Pattern
2525
/// </summary>
2626
/// <returns></returns>
27-
internal static async Task SendHttp2(Stream clientStream, Stream serverStream, int bufferSize,
28-
Action<byte[], int, int> onDataSend, Action<byte[], int, int> onDataReceive,
27+
internal static async Task SendHttp2(Stream clientStream, Stream serverStream,
2928
Func<SessionEventArgs> sessionFactory,
3029
Func<SessionEventArgs, Task> onBeforeRequest, Func<SessionEventArgs, Task> onBeforeResponse,
3130
CancellationTokenSource cancellationTokenSource, Guid connectionId,
@@ -38,25 +37,25 @@ internal static async Task SendHttp2(Stream clientStream, Stream serverStream, i
3837

3938
// Now async relay all server=>client & client=>server data
4039
var sendRelay =
41-
copyHttp2FrameAsync(clientStream, serverStream, onDataSend, clientSettings, serverSettings,
40+
copyHttp2FrameAsync(clientStream, serverStream, clientSettings, serverSettings,
4241
sessionFactory, sessions, onBeforeRequest,
43-
bufferSize, connectionId, true, cancellationTokenSource.Token, exceptionFunc);
42+
connectionId, true, cancellationTokenSource.Token, exceptionFunc);
4443
var receiveRelay =
45-
copyHttp2FrameAsync(serverStream, clientStream, onDataReceive, serverSettings, clientSettings,
44+
copyHttp2FrameAsync(serverStream, clientStream, serverSettings, clientSettings,
4645
sessionFactory, sessions, onBeforeResponse,
47-
bufferSize, connectionId, false, cancellationTokenSource.Token, exceptionFunc);
46+
connectionId, false, cancellationTokenSource.Token, exceptionFunc);
4847

4948
await Task.WhenAny(sendRelay, receiveRelay);
5049
cancellationTokenSource.Cancel();
5150

5251
await Task.WhenAll(sendRelay, receiveRelay);
5352
}
5453

55-
private static async Task copyHttp2FrameAsync(Stream input, Stream output, Action<byte[], int, int> onCopy,
54+
private static async Task copyHttp2FrameAsync(Stream input, Stream output,
5655
Http2Settings localSettings, Http2Settings remoteSettings,
5756
Func<SessionEventArgs> sessionFactory, ConcurrentDictionary<int, SessionEventArgs> sessions,
5857
Func<SessionEventArgs, Task> onBeforeRequestResponse,
59-
int bufferSize, Guid connectionId, bool isClient, CancellationToken cancellationToken,
58+
Guid connectionId, bool isClient, CancellationToken cancellationToken,
6059
ExceptionHandler exceptionFunc)
6160
{
6261
int headerTableSize = 0;
@@ -69,7 +68,6 @@ private static async Task copyHttp2FrameAsync(Stream input, Stream output, Actio
6968
{
7069
var frameHeaderBuffer = frameHeader.Buffer;
7170
int read = await forceRead(input, frameHeaderBuffer, 0, 9, cancellationToken);
72-
onCopy(frameHeaderBuffer, 0, read);
7371
if (read != 9)
7472
{
7573
return;
@@ -92,7 +90,6 @@ private static async Task copyHttp2FrameAsync(Stream input, Stream output, Actio
9290
}
9391

9492
read = await forceRead(input, buffer, 0, length, cancellationToken);
95-
onCopy(buffer, 0, read);
9693
if (read != length)
9794
{
9895
return;
@@ -127,6 +124,11 @@ private static async Task copyHttp2FrameAsync(Stream input, Stream output, Actio
127124
//System.Diagnostics.Debug.WriteLine("CONN: " + connectionId + ", CLIENT: " + isClient + ", STREAM: " + streamId + ", TYPE: " + type);
128125
if (type == Http2FrameType.Data && args != null)
129126
{
127+
if (isClient)
128+
args.OnDataSent(buffer, 0, read);
129+
else
130+
args.OnDataReceived(buffer, 0, read);
131+
130132
rr = isClient ? (RequestResponseBase)args.HttpClient.Request : args.HttpClient.Response;
131133

132134
bool padded = (flags & Http2FrameFlag.Padded) != 0;
@@ -182,8 +184,10 @@ private static async Task copyHttp2FrameAsync(Stream input, Stream output, Actio
182184
{
183185
args = sessionFactory();
184186
args.IsPromise = true;
185-
sessions.TryAdd(streamId, args);
186-
sessions.TryAdd(promisedStreamId, args);
187+
if (!sessions.TryAdd(streamId, args))
188+
;
189+
if (!sessions.TryAdd(promisedStreamId, args))
190+
;
187191
}
188192

189193
System.Diagnostics.Debug.WriteLine("PROMISE STREAM: " + streamId + ", " + promisedStreamId +
@@ -201,7 +205,8 @@ private static async Task copyHttp2FrameAsync(Stream input, Stream output, Actio
201205
if (!sessions.TryGetValue(streamId, out args))
202206
{
203207
args = sessionFactory();
204-
sessions.TryAdd(streamId, args);
208+
if (!sessions.TryAdd(streamId, args))
209+
;
205210
}
206211

207212
rr = isClient ? (RequestResponseBase)args.HttpClient.Request : args.HttpClient.Response;

src/Titanium.Web.Proxy/Network/Tcp/TcpClientConnection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.IO;
33
using System.Net;
4-
#if NETCOREAPP2_1
4+
#if NETCOREAPP2_1 || NETSTANDARD2_1
55
using System.Net.Security;
66
#endif
77
using System.Net.Sockets;

src/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ private async Task<TcpServerConnection> createServerConnection(string remoteHost
391391
CertificateRevocationCheckMode = proxyServer.CheckCertificateRevocation
392392
};
393393
await sslStream.AuthenticateAsClientAsync(options, cancellationToken);
394-
#if NETCOREAPP2_1
394+
#if NETCOREAPP2_1 || NETSTANDARD2_1
395395
negotiatedApplicationProtocol = sslStream.NegotiatedApplicationProtocol;
396396
#endif
397397

src/Titanium.Web.Proxy/Network/Tcp/TcpServerConnection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
22
using System.Net;
3-
#if NETCOREAPP2_1
3+
#if NETCOREAPP2_1 || NETSTANDARD2_1
44
using System.Net.Security;
55
#endif
66
using System.Net.Sockets;

src/Titanium.Web.Proxy/RequestHandler.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Linq;
44
using System.Net;
55
using System.Net.Sockets;
6-
#if NETCOREAPP2_1
6+
#if NETCOREAPP2_1 || NETSTANDARD2_1
77
using System.Net.Security;
88
#endif
99
using System.Text.RegularExpressions;
@@ -143,7 +143,7 @@ await HeaderParser.ReadHeaders(clientStream, args.HttpClient.Request.Headers,
143143
// proxy authorization check
144144
if (httpsConnectHostname == null && await checkAuthorization(args) == false)
145145
{
146-
await invokeBeforeResponse(args);
146+
await onBeforeResponse(args);
147147

148148
// send the response
149149
await clientStreamWriter.WriteResponseAsync(args.HttpClient.Response,
@@ -166,10 +166,8 @@ await clientStreamWriter.WriteResponseAsync(args.HttpClient.Response,
166166
// we need this to syphon out data from connection if API user changes them.
167167
request.SetOriginalHeaders();
168168

169-
args.TimeLine["Request Received"] = DateTime.Now;
170-
171169
// If user requested interception do it
172-
await invokeBeforeRequest(args);
170+
await onBeforeRequest(args);
173171

174172
var response = args.HttpClient.Response;
175173

@@ -286,7 +284,7 @@ await clientStreamWriter.WriteResponseAsync(args.HttpClient.Response,
286284
}
287285
finally
288286
{
289-
await invokeAfterResponse(args);
287+
await onAfterResponse(args);
290288
args.Dispose();
291289
}
292290
}
@@ -410,8 +408,10 @@ private void prepareRequestHeaders(HeaderCollection requestHeaders)
410408
/// </summary>
411409
/// <param name="args">The session event arguments.</param>
412410
/// <returns></returns>
413-
private async Task invokeBeforeRequest(SessionEventArgs args)
411+
private async Task onBeforeRequest(SessionEventArgs args)
414412
{
413+
args.TimeLine["Request Received"] = DateTime.Now;
414+
415415
if (BeforeRequest != null)
416416
{
417417
await BeforeRequest.InvokeAsync(this, args, ExceptionFunc);

src/Titanium.Web.Proxy/ResponseHandler.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ private async Task handleHttpSessionResponse(SessionEventArgs args)
5858
// if user requested call back then do it
5959
if (!response.Locked)
6060
{
61-
await invokeBeforeResponse(args);
61+
await onBeforeResponse(args);
6262
}
6363

6464
// it may changed in the user event
@@ -132,7 +132,7 @@ await args.CopyResponseBodyAsync(clientStreamWriter, TransformationMode.None,
132132
/// </summary>
133133
/// <param name="args"></param>
134134
/// <returns></returns>
135-
private async Task invokeBeforeResponse(SessionEventArgs args)
135+
private async Task onBeforeResponse(SessionEventArgs args)
136136
{
137137
if (BeforeResponse != null)
138138
{
@@ -145,7 +145,7 @@ private async Task invokeBeforeResponse(SessionEventArgs args)
145145
/// </summary>
146146
/// <param name="args"></param>
147147
/// <returns></returns>
148-
private async Task invokeAfterResponse(SessionEventArgs args)
148+
private async Task onAfterResponse(SessionEventArgs args)
149149
{
150150
if (AfterResponse != null)
151151
{

src/Titanium.Web.Proxy/Titanium.Web.Proxy.csproj

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard2.0;netcoreapp2.1</TargetFrameworks>
4+
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp2.1</TargetFrameworks>
55
<RootNamespace>Titanium.Web.Proxy</RootNamespace>
66
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
77
<SignAssembly>True</SignAssembly>
@@ -26,6 +26,15 @@
2626
</PackageReference>
2727
</ItemGroup>
2828

29+
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
30+
<PackageReference Include="Microsoft.Win32.Registry">
31+
<Version>4.5.0</Version>
32+
</PackageReference>
33+
<PackageReference Include="System.Security.Principal.Windows">
34+
<Version>4.5.1</Version>
35+
</PackageReference>
36+
</ItemGroup>
37+
2938
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
3039
<PackageReference Include="Microsoft.Win32.Registry">
3140
<Version>4.5.0</Version>

src/Titanium.Web.Proxy/WebSocketHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ await clientStreamWriter.WriteResponseAsync(response,
6060
// If user requested call back then do it
6161
if (!args.HttpClient.Response.Locked)
6262
{
63-
await invokeBeforeResponse(args);
63+
await onBeforeResponse(args);
6464
}
6565

6666
await TcpHelper.SendRaw(clientStream, serverConnection.Stream, BufferPool,

0 commit comments

Comments
 (0)