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

Commit 88a552e

Browse files
committed
.NET 4.5 support removed (.NET 4.6.1 required)
1 parent 1cc485f commit 88a552e

File tree

15 files changed

+94
-205
lines changed

15 files changed

+94
-205
lines changed

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# - Section names should be unique on each level.
88

99
# version format
10-
version: 3.0.{build}
10+
version: 3.1.{build}
1111
image: Visual Studio 2017
1212

1313
shallow_clone: false

examples/Titanium.Web.Proxy.Examples.Basic/Titanium.Web.Proxy.Examples.Basic.Mono.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFrameworks>net45</TargetFrameworks>
5+
<TargetFrameworks>net461</TargetFrameworks>
66
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
77
<LangVersion>7.1</LangVersion>
88
<Platforms>AnyCPU;x64</Platforms>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFrameworks>net45;netcoreapp2.1</TargetFrameworks>
5+
<TargetFrameworks>net461;netcoreapp2.1</TargetFrameworks>
66
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
77
<LangVersion>7.1</LangVersion>
88
<Platforms>AnyCPU;x64</Platforms>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<OutputType>WinExe</OutputType>
99
<RootNamespace>Titanium.Web.Proxy.Examples.Wpf</RootNamespace>
1010
<AssemblyName>Titanium.Web.Proxy.Examples.Wpf</AssemblyName>
11-
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
11+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
1212
<FileAlignment>512</FileAlignment>
1313
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
1414
<WarningLevel>4</WarningLevel>

src/Titanium.Web.Proxy/Helpers/RunTime.cs

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,56 +9,38 @@ namespace Titanium.Web.Proxy.Helpers
99
/// </summary>
1010
public static class RunTime
1111
{
12-
/// <summary>
13-
/// cache for mono runtime check
14-
/// </summary>
15-
/// <returns></returns>
1612
private static readonly Lazy<bool> isRunningOnMono = new Lazy<bool>(() => Type.GetType("Mono.Runtime") != null);
1713

1814
/// <summary>
19-
/// cache for mono runtime check
15+
/// cache for Windows platform check
2016
/// </summary>
2117
/// <returns></returns>
22-
private static readonly Lazy<bool> isRunningOnMonoLinux = new Lazy<bool>(() => IsRunningOnMono && (int)Environment.OSVersion.Platform == 4);
18+
private static bool isRunningOnWindows => RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
2319

2420
/// <summary>
2521
/// cache for mono runtime check
2622
/// </summary>
2723
/// <returns></returns>
28-
private static readonly Lazy<bool> isRunningOnMonoMac = new Lazy<bool>(() => IsRunningOnMono && (int)Environment.OSVersion.Platform == 6);
24+
private static bool isRunningOnLinux => RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
2925

30-
#if NETSTANDARD2_0
3126
/// <summary>
32-
/// cache for Windows platform check
27+
/// cache for mac runtime check
3328
/// </summary>
3429
/// <returns></returns>
35-
private static bool isRunningOnWindows => RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
36-
private static bool isRunningOnLinux => RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
3730
private static bool isRunningOnMac => RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
38-
#endif
31+
3932
/// <summary>
4033
/// Is running on Mono?
4134
/// </summary>
4235
internal static bool IsRunningOnMono => isRunningOnMono.Value;
4336

44-
#if NETSTANDARD2_0
4537
public static bool IsLinux => isRunningOnLinux;
46-
#else
47-
public static bool IsLinux => isRunningOnMonoLinux.Value;
48-
#endif
4938

50-
#if NETSTANDARD2_0
5139
public static bool IsWindows => isRunningOnWindows;
52-
#else
53-
public static bool IsWindows => !IsLinux && !IsMac;
54-
#endif
40+
5541
public static bool IsUwpOnWindows => IsWindows && UwpHelper.IsRunningAsUwp();
5642

57-
#if NETSTANDARD2_0
5843
public static bool IsMac => isRunningOnMac;
59-
#else
60-
public static bool IsMac => isRunningOnMonoMac.Value;
61-
#endif
6244

6345
//https://github.com/qmatteoq/DesktopBridgeHelpers/blob/master/DesktopBridge.Helpers/Helpers.cs
6446
private class UwpHelper

src/Titanium.Web.Proxy/Http/Responses/GenericResponse.cs

Lines changed: 74 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Net;
1+
using System.Net;
22
using System.Web;
33

44
namespace Titanium.Web.Proxy.Http.Responses
@@ -15,14 +15,7 @@ public class GenericResponse : Response
1515
public GenericResponse(HttpStatusCode status)
1616
{
1717
StatusCode = (int)status;
18-
19-
#if NET45
20-
StatusDescription = HttpWorkerRequest.GetStatusDescription(StatusCode);
21-
#else
22-
// todo: this is not really correct, status description should contain spaces, too
23-
// see: https://tools.ietf.org/html/rfc7231#section-6.1
24-
StatusDescription = status.ToString();
25-
#endif
18+
StatusDescription = Get(StatusCode);
2619
}
2720

2821
/// <summary>
@@ -35,5 +28,77 @@ public GenericResponse(int statusCode, string statusDescription)
3528
StatusCode = statusCode;
3629
StatusDescription = statusDescription;
3730
}
31+
32+
internal static string Get(int code)
33+
{
34+
switch (code)
35+
{
36+
case 100: return "Continue";
37+
case 101: return "Switching Protocols";
38+
case 102: return "Processing";
39+
case 103: return "Early Hints";
40+
41+
case 200: return "OK";
42+
case 201: return "Created";
43+
case 202: return "Accepted";
44+
case 203: return "Non-Authoritative Information";
45+
case 204: return "No Content";
46+
case 205: return "Reset Content";
47+
case 206: return "Partial Content";
48+
case 207: return "Multi-Status";
49+
case 208: return "Already Reported";
50+
case 226: return "IM Used";
51+
52+
case 300: return "Multiple Choices";
53+
case 301: return "Moved Permanently";
54+
case 302: return "Found";
55+
case 303: return "See Other";
56+
case 304: return "Not Modified";
57+
case 305: return "Use Proxy";
58+
case 307: return "Temporary Redirect";
59+
case 308: return "Permanent Redirect";
60+
61+
case 400: return "Bad Request";
62+
case 401: return "Unauthorized";
63+
case 402: return "Payment Required";
64+
case 403: return "Forbidden";
65+
case 404: return "Not Found";
66+
case 405: return "Method Not Allowed";
67+
case 406: return "Not Acceptable";
68+
case 407: return "Proxy Authentication Required";
69+
case 408: return "Request Timeout";
70+
case 409: return "Conflict";
71+
case 410: return "Gone";
72+
case 411: return "Length Required";
73+
case 412: return "Precondition Failed";
74+
case 413: return "Request Entity Too Large";
75+
case 414: return "Request-Uri Too Long";
76+
case 415: return "Unsupported Media Type";
77+
case 416: return "Requested Range Not Satisfiable";
78+
case 417: return "Expectation Failed";
79+
case 421: return "Misdirected Request";
80+
case 422: return "Unprocessable Entity";
81+
case 423: return "Locked";
82+
case 424: return "Failed Dependency";
83+
case 426: return "Upgrade Required"; // RFC 2817
84+
case 428: return "Precondition Required";
85+
case 429: return "Too Many Requests";
86+
case 431: return "Request Header Fields Too Large";
87+
case 451: return "Unavailable For Legal Reasons";
88+
89+
case 500: return "Internal Server Error";
90+
case 501: return "Not Implemented";
91+
case 502: return "Bad Gateway";
92+
case 503: return "Service Unavailable";
93+
case 504: return "Gateway Timeout";
94+
case 505: return "Http Version Not Supported";
95+
case 506: return "Variant Also Negotiates";
96+
case 507: return "Insufficient Storage";
97+
case 508: return "Loop Detected";
98+
case 510: return "Not Extended";
99+
case 511: return "Network Authentication Required";
100+
}
101+
return null;
102+
}
38103
}
39104
}

src/Titanium.Web.Proxy/Network/Certificate/BCCertificateMaker.cs

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.IO;
33
using System.Security.Cryptography.X509Certificates;
44
using System.Threading;
@@ -141,21 +141,8 @@ private static X509Certificate2 generateCertificate(string hostName,
141141
rsa.Prime1, rsa.Prime2, rsa.Exponent1,
142142
rsa.Exponent2, rsa.Coefficient);
143143

144-
#if NET45
145144
// Set private key onto certificate instance
146-
X509Certificate2 x509Certificate;
147-
if (RunTime.IsRunningOnMono)
148-
{
149-
x509Certificate = withPrivateKey(certificate, rsaparams);
150-
}
151-
else
152-
{
153-
x509Certificate = new X509Certificate2(certificate.GetEncoded());
154-
x509Certificate.PrivateKey = DotNetUtilities.ToRSA(rsaparams);
155-
}
156-
#else
157145
var x509Certificate = withPrivateKey(certificate, rsaparams);
158-
#endif
159146

160147
if (!doNotSetFriendlyName)
161148
{
@@ -248,36 +235,6 @@ private X509Certificate2 makeCertificateInternal(string subject, bool isRoot,
248235
bool switchToMtaIfNeeded, X509Certificate2 signingCert = null,
249236
CancellationToken cancellationToken = default)
250237
{
251-
#if NET45
252-
if (switchToMtaIfNeeded && Thread.CurrentThread.GetApartmentState() != ApartmentState.MTA)
253-
{
254-
X509Certificate2 certificate = null;
255-
using (var manualResetEvent = new ManualResetEventSlim(false))
256-
{
257-
ThreadPool.QueueUserWorkItem(o =>
258-
{
259-
try
260-
{
261-
certificate = makeCertificateInternal(subject, isRoot, false, signingCert);
262-
}
263-
catch (Exception ex)
264-
{
265-
exceptionFunc(new Exception("Failed to create BC certificate", ex));
266-
}
267-
268-
if (!cancellationToken.IsCancellationRequested)
269-
{
270-
manualResetEvent.Set();
271-
}
272-
});
273-
274-
manualResetEvent.Wait(TimeSpan.FromMinutes(1), cancellationToken);
275-
}
276-
277-
return certificate;
278-
}
279-
#endif
280-
281238
return makeCertificateInternal(isRoot, subject, $"CN={subject}",
282239
DateTime.UtcNow.AddDays(-certificateGraceDays), DateTime.UtcNow.AddDays(certificateValidDays),
283240
isRoot ? null : signingCert);

src/Titanium.Web.Proxy/ProxyServer.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,7 @@ public ProxyServer(string rootCertificateName, string rootCertificateIssuerName,
238238
/// <summary>
239239
/// List of supported Ssl versions.
240240
/// </summary>
241-
public SslProtocols SupportedSslProtocols { get; set; } =
242-
#if NET45
243-
SslProtocols.Ssl3 |
244-
#endif
245-
SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12;
241+
public SslProtocols SupportedSslProtocols { get; set; } = SslProtocols.Ssl3 | SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12;
246242

247243
/// <summary>
248244
/// The buffer pool used throughout this proxy instance.

src/Titanium.Web.Proxy/StreamExtended/Network/CustomBufferedStream.cs

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -609,64 +609,5 @@ private static void ResizeBuffer(ref byte[] buffer, long size)
609609
Buffer.BlockCopy(buffer, 0, newBuffer, 0, buffer.Length);
610610
buffer = newBuffer;
611611
}
612-
613-
#if NET45 || NETSTANDARD2_0
614-
615-
/// <summary>
616-
/// Base Stream.BeginRead will call this.Read and block thread (we don't want this, Network stream handles async)
617-
/// In order to really async Reading Launch this.ReadAsync as Task will fire NetworkStream.ReadAsync
618-
/// See Threads here :
619-
/// https://github.com/justcoding121/Stream-Extended/pull/43
620-
/// https://github.com/justcoding121/Titanium-Web-Proxy/issues/575
621-
/// </summary>
622-
/// <returns></returns>
623-
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
624-
{
625-
var vAsyncResult = this.ReadAsync(buffer, offset, count);
626-
627-
vAsyncResult.ContinueWith(pAsyncResult =>
628-
{
629-
//use TaskExtended to pass State as AsyncObject
630-
//callback will call EndRead (otherwise, it will block)
631-
callback?.Invoke(new TaskResult<int>(pAsyncResult, state));
632-
});
633-
634-
return vAsyncResult;
635-
}
636-
637-
/// <summary>
638-
/// override EndRead to handle async Reading (see BeginRead comment)
639-
/// </summary>
640-
/// <returns></returns>
641-
public override int EndRead(IAsyncResult asyncResult)
642-
{
643-
return ((TaskResult<int>)asyncResult).Result;
644-
}
645-
646-
647-
/// <summary>
648-
/// Fix the .net bug with SslStream slow WriteAsync
649-
/// https://github.com/justcoding121/Titanium-Web-Proxy/issues/495
650-
/// Stream.BeginWrite + Stream.BeginRead uses the same SemaphoreSlim(1)
651-
/// That's why we need to call NetworkStream.BeginWrite only (while read is waiting SemaphoreSlim)
652-
/// </summary>
653-
/// <returns></returns>
654-
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
655-
{
656-
var vAsyncResult = this.WriteAsync(buffer, offset, count);
657-
658-
vAsyncResult.ContinueWith(pAsyncResult =>
659-
{
660-
callback?.Invoke(new TaskResult(pAsyncResult, state));
661-
});
662-
663-
return vAsyncResult;
664-
}
665-
public override void EndWrite(IAsyncResult asyncResult)
666-
{
667-
((TaskResult)asyncResult).GetResult();
668-
}
669-
670-
#endif
671612
}
672613
}

src/Titanium.Web.Proxy/StreamExtended/TaskExtended.cs

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)