Commit 4562e132 authored by Honfika's avatar Honfika

net4.5 support is back

parent 9b4e3dca
......@@ -589,7 +589,11 @@ namespace Titanium.Web.Proxy.EventArguments
var response = new RedirectResponse();
response.HttpVersion = HttpClient.Request.HttpVersion;
response.Headers.AddHeader(KnownHeaders.Location, url);
#if NET45
response.Body = Net45Compatibility.EmptyArray;
#else
response.Body = Array.Empty<byte>();
#endif
Respond(response, closeServerConnection);
}
......
using System;
using System;
using System.Reflection;
using System.Text;
using System.Runtime.InteropServices;
......@@ -13,6 +13,25 @@ namespace Titanium.Web.Proxy.Helpers
{
private static readonly Lazy<bool> isRunningOnMono = new Lazy<bool>(() => Type.GetType("Mono.Runtime") != null);
#if NET45
/// <summary>
/// cache for Windows platform check
/// </summary>
/// <returns></returns>
private static bool isRunningOnWindows => true;
/// <summary>
/// cache for mono runtime check
/// </summary>
/// <returns></returns>
private static bool isRunningOnLinux => false;
/// <summary>
/// cache for mac runtime check
/// </summary>
/// <returns></returns>
private static bool isRunningOnMac => false;
#else
/// <summary>
/// cache for Windows platform check
/// </summary>
......@@ -30,7 +49,8 @@ namespace Titanium.Web.Proxy.Helpers
/// </summary>
/// <returns></returns>
private static bool isRunningOnMac => RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
#endif
/// <summary>
/// Is running on Mono?
/// </summary>
......
......@@ -85,14 +85,22 @@ namespace Titanium.Web.Proxy.Http
public ArraySegment<byte> GetBuffer()
{
#if NET45
return new ArraySegment<byte>(stream.ToArray());
#else
stream.TryGetBuffer(out var buffer);
return buffer;
#endif
}
public string GetString(Encoding encoding)
{
#if NET45
return encoding.GetString(stream.ToArray());
#else
stream.TryGetBuffer(out var buffer);
return encoding.GetString(buffer.Array, buffer.Offset, buffer.Count);
#endif
}
}
}
......@@ -258,7 +258,11 @@ namespace Titanium.Web.Proxy.Http2.Hpack
if (nameLength + HttpHeader.HttpHeaderOverhead > dynamicTable.Capacity)
{
dynamicTable.Clear();
#if NET45
name = Net45Compatibility.EmptyArray;
#else
name = Array.Empty<byte>();
#endif
skipLength = nameLength;
state = State.SkipLiteralHeaderName;
break;
......@@ -375,7 +379,11 @@ namespace Titanium.Web.Proxy.Http2.Hpack
if (valueLength == 0)
{
InsertHeader(headerListener, name, Array.Empty<byte>(), indexType);
#if NET45
InsertHeader(headerListener, name, Net45Compatibility.EmptyArray, indexType);
#else
name = Array.Empty<byte>();
#endif
state = State.ReadHeaderRepresentation;
}
else
......
......@@ -23,7 +23,11 @@ namespace Titanium.Web.Proxy.Http2.Hpack
public class DynamicTable
{
// a circular queue of header fields
#if NET45
HttpHeader[] headerFields = new HttpHeader[0];
#else
HttpHeader[] headerFields = Array.Empty<HttpHeader>();
#endif
int head;
int tail;
......
#if NET45
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Titanium.Web.Proxy
{
class Net45Compatibility
{
public static byte[] EmptyArray = new byte[0];
}
}
#endif
......@@ -355,7 +355,11 @@ retry:
{
// dispose the current TcpClient and try the next address
lastException = e;
#if NET45
tcpClient?.Close();
#else
tcpClient?.Dispose();
#endif
tcpClient = null;
}
}
......
......@@ -51,7 +51,7 @@ namespace Titanium.Web.Proxy
// Loop through each subsequent request on this particular client connection
// (assuming HTTP connection is kept alive by client)
while (true)
{
{
if (clientStream.IsClosed)
{
return;
......
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>net45;net461;netstandard2.0;netstandard2.1</TargetFrameworks>
<RootNamespace>Titanium.Web.Proxy</RootNamespace>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<SignAssembly>True</SignAssembly>
......@@ -15,21 +15,15 @@
<ItemGroup>
<PackageReference Include="BrotliSharpLib" Version="0.3.3" />
<PackageReference Include="Portable.BouncyCastle" Version="1.8.5.2" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'netstandard2.1'">
<PackageReference Include="System.Buffers" Version="4.5.0" />
<PackageReference Include="System.Memory" Version="4.5.3" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.3" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.Win32.Registry">
<Version>4.6.0</Version>
</PackageReference>
<PackageReference Include="System.Security.Principal.Windows">
<Version>4.6.0</Version>
</PackageReference>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
<ItemGroup Condition="'$(TargetFramework)' != 'net45'">
<PackageReference Include="Microsoft.Win32.Registry">
<Version>4.6.0</Version>
</PackageReference>
......
......@@ -14,27 +14,42 @@
<copyright>Copyright &#x00A9; Titanium. All rights reserved.</copyright>
<tags></tags>
<dependencies>
<group targetFramework="netstandard2.0">
<group targetFramework="net45">
<dependency id="BrotliSharpLib" version="0.3.3" />
<dependency id="Portable.BouncyCastle" version="1.8.5.2" />
<dependency id="System.Buffers" version="4.5.0" />
<dependency id="System.Memory" version="4.5.3" />
<dependency id="System.Threading.Tasks.Extensions" version="4.5.3" />
</group>
<group targetFramework="net461">
<dependency id="BrotliSharpLib" version="0.3.3" />
<dependency id="Portable.BouncyCastle" version="1.8.5.2" />
<dependency id="Microsoft.Win32.Registry" version="4.6.0" />
<dependency id="System.Buffers" version="4.5.0" />
<dependency id="System.Memory" version="4.5.3" />
<dependency id="System.Threading.Tasks.Extensions" version="4.5.3" />
<dependency id="System.Security.Principal.Windows" version="4.6.0" />
</group>
<group targetFramework="netstandard2.1">
<dependency id="Portable.BouncyCastle" version="1.8.5.2" />
<group targetFramework="netstandard2.0">
<dependency id="BrotliSharpLib" version="0.3.3" />
<dependency id="Portable.BouncyCastle" version="1.8.5.2" />
<dependency id="Microsoft.Win32.Registry" version="4.6.0" />
<dependency id="System.Buffers" version="4.5.0" />
<dependency id="System.Memory" version="4.5.3" />
<dependency id="System.Threading.Tasks.Extensions" version="4.5.3" />
<dependency id="System.Security.Principal.Windows" version="4.6.0" />
</group>
<group targetFramework="netstandard2.1">
<dependency id="BrotliSharpLib" version="0.3.3" />
<dependency id="Portable.BouncyCastle" version="1.8.5.2" />
<dependency id="Microsoft.Win32.Registry" version="4.6.0" />
<dependency id="System.Security.Principal.Windows" version="4.6.0" />
</group>
</dependencies>
</metadata>
<files>
<file src="bin\$configuration$\net45\Titanium.Web.Proxy.dll" target="lib\net45" />
<file src="bin\$configuration$\net461\Titanium.Web.Proxy.dll" target="lib\net461" />
<file src="bin\$configuration$\netstandard2.0\Titanium.Web.Proxy.dll" target="lib\netstandard2.0" />
<file src="bin\$configuration$\netstandard2.1\Titanium.Web.Proxy.dll" target="lib\netstandard2.1" />
</files>
......
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