Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Titanium-Web-Proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Titanium-Web-Proxy
Commits
88a552e2
Commit
88a552e2
authored
Jul 20, 2019
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.NET 4.5 support removed (.NET 4.6.1 required)
parent
1cc485fa
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
94 additions
and
205 deletions
+94
-205
appveyor.yml
appveyor.yml
+1
-1
Titanium.Web.Proxy.Examples.Basic.Mono.csproj
...mples.Basic/Titanium.Web.Proxy.Examples.Basic.Mono.csproj
+1
-1
Titanium.Web.Proxy.Examples.Basic.csproj
...y.Examples.Basic/Titanium.Web.Proxy.Examples.Basic.csproj
+1
-1
Titanium.Web.Proxy.Examples.Wpf.csproj
...Proxy.Examples.Wpf/Titanium.Web.Proxy.Examples.Wpf.csproj
+1
-1
RunTime.cs
src/Titanium.Web.Proxy/Helpers/RunTime.cs
+6
-24
GenericResponse.cs
src/Titanium.Web.Proxy/Http/Responses/GenericResponse.cs
+74
-9
BCCertificateMaker.cs
...anium.Web.Proxy/Network/Certificate/BCCertificateMaker.cs
+1
-44
ProxyServer.cs
src/Titanium.Web.Proxy/ProxyServer.cs
+1
-5
CustomBufferedStream.cs
....Web.Proxy/StreamExtended/Network/CustomBufferedStream.cs
+0
-59
TaskExtended.cs
src/Titanium.Web.Proxy/StreamExtended/TaskExtended.cs
+0
-52
Titanium.Web.Proxy.Mono.csproj
src/Titanium.Web.Proxy/Titanium.Web.Proxy.Mono.csproj
+2
-2
Titanium.Web.Proxy.NetCore.csproj
src/Titanium.Web.Proxy/Titanium.Web.Proxy.NetCore.csproj
+1
-1
Titanium.Web.Proxy.csproj
src/Titanium.Web.Proxy/Titanium.Web.Proxy.csproj
+2
-2
Titanium.Web.Proxy.nuspec
src/Titanium.Web.Proxy/Titanium.Web.Proxy.nuspec
+2
-2
Titanium.Web.Proxy.UnitTests.csproj
...m.Web.Proxy.UnitTests/Titanium.Web.Proxy.UnitTests.csproj
+1
-1
No files found.
appveyor.yml
View file @
88a552e2
...
...
@@ -7,7 +7,7 @@
# - Section names should be unique on each level.
# version format
version
:
3.
0
.{build}
version
:
3.
1
.{build}
image
:
Visual Studio 2017
shallow_clone
:
false
...
...
examples/Titanium.Web.Proxy.Examples.Basic/Titanium.Web.Proxy.Examples.Basic.Mono.csproj
View file @
88a552e2
...
...
@@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net4
5
</TargetFrameworks>
<TargetFrameworks>net4
61
</TargetFrameworks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<LangVersion>7.1</LangVersion>
<Platforms>AnyCPU;x64</Platforms>
...
...
examples/Titanium.Web.Proxy.Examples.Basic/Titanium.Web.Proxy.Examples.Basic.csproj
View file @
88a552e2
...
...
@@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net4
5
;netcoreapp2.1</TargetFrameworks>
<TargetFrameworks>net4
61
;netcoreapp2.1</TargetFrameworks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<LangVersion>7.1</LangVersion>
<Platforms>AnyCPU;x64</Platforms>
...
...
examples/Titanium.Web.Proxy.Examples.Wpf/Titanium.Web.Proxy.Examples.Wpf.csproj
View file @
88a552e2
...
...
@@ -8,7 +8,7 @@
<OutputType>
WinExe
</OutputType>
<RootNamespace>
Titanium.Web.Proxy.Examples.Wpf
</RootNamespace>
<AssemblyName>
Titanium.Web.Proxy.Examples.Wpf
</AssemblyName>
<TargetFrameworkVersion>
v4.
5
</TargetFrameworkVersion>
<TargetFrameworkVersion>
v4.
6.1
</TargetFrameworkVersion>
<FileAlignment>
512
</FileAlignment>
<ProjectTypeGuids>
{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
</ProjectTypeGuids>
<WarningLevel>
4
</WarningLevel>
...
...
src/Titanium.Web.Proxy/Helpers/RunTime.cs
View file @
88a552e2
...
...
@@ -9,56 +9,38 @@ namespace Titanium.Web.Proxy.Helpers
/// </summary>
public
static
class
RunTime
{
/// <summary>
/// cache for mono runtime check
/// </summary>
/// <returns></returns>
private
static
readonly
Lazy
<
bool
>
isRunningOnMono
=
new
Lazy
<
bool
>(()
=>
Type
.
GetType
(
"Mono.Runtime"
)
!=
null
);
/// <summary>
///
cache for mono runtime
check
///
cache for Windows platform
check
/// </summary>
/// <returns></returns>
private
static
readonly
Lazy
<
bool
>
isRunningOnMonoLinux
=
new
Lazy
<
bool
>(()
=>
IsRunningOnMono
&&
(
int
)
Environment
.
OSVersion
.
Platform
==
4
);
private
static
bool
isRunningOnWindows
=>
RuntimeInformation
.
IsOSPlatform
(
OSPlatform
.
Windows
);
/// <summary>
/// cache for mono runtime check
/// </summary>
/// <returns></returns>
private
static
readonly
Lazy
<
bool
>
isRunningOnMonoMac
=
new
Lazy
<
bool
>(()
=>
IsRunningOnMono
&&
(
int
)
Environment
.
OSVersion
.
Platform
==
6
);
private
static
bool
isRunningOnLinux
=>
RuntimeInformation
.
IsOSPlatform
(
OSPlatform
.
Linux
);
#if NETSTANDARD2_0
/// <summary>
///
cache for Windows platform
check
///
cache for mac runtime
check
/// </summary>
/// <returns></returns>
private
static
bool
isRunningOnWindows
=>
RuntimeInformation
.
IsOSPlatform
(
OSPlatform
.
Windows
);
private
static
bool
isRunningOnLinux
=>
RuntimeInformation
.
IsOSPlatform
(
OSPlatform
.
Linux
);
private
static
bool
isRunningOnMac
=>
RuntimeInformation
.
IsOSPlatform
(
OSPlatform
.
OSX
);
#endif
/// <summary>
/// Is running on Mono?
/// </summary>
internal
static
bool
IsRunningOnMono
=>
isRunningOnMono
.
Value
;
#if NETSTANDARD2_0
public
static
bool
IsLinux
=>
isRunningOnLinux
;
#else
public
static
bool
IsLinux
=>
isRunningOnMonoLinux
.
Value
;
#endif
#if NETSTANDARD2_0
public
static
bool
IsWindows
=>
isRunningOnWindows
;
#else
public
static
bool
IsWindows
=>
!
IsLinux
&&
!
IsMac
;
#endif
public
static
bool
IsUwpOnWindows
=>
IsWindows
&&
UwpHelper
.
IsRunningAsUwp
();
#if NETSTANDARD2_0
public
static
bool
IsMac
=>
isRunningOnMac
;
#else
public
static
bool
IsMac
=>
isRunningOnMonoMac
.
Value
;
#endif
//https://github.com/qmatteoq/DesktopBridgeHelpers/blob/master/DesktopBridge.Helpers/Helpers.cs
private
class
UwpHelper
...
...
src/Titanium.Web.Proxy/Http/Responses/GenericResponse.cs
View file @
88a552e2
using
System.Net
;
using
System.Net
;
using
System.Web
;
namespace
Titanium.Web.Proxy.Http.Responses
...
...
@@ -15,14 +15,7 @@ namespace Titanium.Web.Proxy.Http.Responses
public
GenericResponse
(
HttpStatusCode
status
)
{
StatusCode
=
(
int
)
status
;
#if NET45
StatusDescription
=
HttpWorkerRequest
.
GetStatusDescription
(
StatusCode
);
#else
// todo: this is not really correct, status description should contain spaces, too
// see: https://tools.ietf.org/html/rfc7231#section-6.1
StatusDescription
=
status
.
ToString
();
#endif
StatusDescription
=
Get
(
StatusCode
);
}
/// <summary>
...
...
@@ -35,5 +28,77 @@ namespace Titanium.Web.Proxy.Http.Responses
StatusCode
=
statusCode
;
StatusDescription
=
statusDescription
;
}
internal
static
string
Get
(
int
code
)
{
switch
(
code
)
{
case
100
:
return
"Continue"
;
case
101
:
return
"Switching Protocols"
;
case
102
:
return
"Processing"
;
case
103
:
return
"Early Hints"
;
case
200
:
return
"OK"
;
case
201
:
return
"Created"
;
case
202
:
return
"Accepted"
;
case
203
:
return
"Non-Authoritative Information"
;
case
204
:
return
"No Content"
;
case
205
:
return
"Reset Content"
;
case
206
:
return
"Partial Content"
;
case
207
:
return
"Multi-Status"
;
case
208
:
return
"Already Reported"
;
case
226
:
return
"IM Used"
;
case
300
:
return
"Multiple Choices"
;
case
301
:
return
"Moved Permanently"
;
case
302
:
return
"Found"
;
case
303
:
return
"See Other"
;
case
304
:
return
"Not Modified"
;
case
305
:
return
"Use Proxy"
;
case
307
:
return
"Temporary Redirect"
;
case
308
:
return
"Permanent Redirect"
;
case
400
:
return
"Bad Request"
;
case
401
:
return
"Unauthorized"
;
case
402
:
return
"Payment Required"
;
case
403
:
return
"Forbidden"
;
case
404
:
return
"Not Found"
;
case
405
:
return
"Method Not Allowed"
;
case
406
:
return
"Not Acceptable"
;
case
407
:
return
"Proxy Authentication Required"
;
case
408
:
return
"Request Timeout"
;
case
409
:
return
"Conflict"
;
case
410
:
return
"Gone"
;
case
411
:
return
"Length Required"
;
case
412
:
return
"Precondition Failed"
;
case
413
:
return
"Request Entity Too Large"
;
case
414
:
return
"Request-Uri Too Long"
;
case
415
:
return
"Unsupported Media Type"
;
case
416
:
return
"Requested Range Not Satisfiable"
;
case
417
:
return
"Expectation Failed"
;
case
421
:
return
"Misdirected Request"
;
case
422
:
return
"Unprocessable Entity"
;
case
423
:
return
"Locked"
;
case
424
:
return
"Failed Dependency"
;
case
426
:
return
"Upgrade Required"
;
// RFC 2817
case
428
:
return
"Precondition Required"
;
case
429
:
return
"Too Many Requests"
;
case
431
:
return
"Request Header Fields Too Large"
;
case
451
:
return
"Unavailable For Legal Reasons"
;
case
500
:
return
"Internal Server Error"
;
case
501
:
return
"Not Implemented"
;
case
502
:
return
"Bad Gateway"
;
case
503
:
return
"Service Unavailable"
;
case
504
:
return
"Gateway Timeout"
;
case
505
:
return
"Http Version Not Supported"
;
case
506
:
return
"Variant Also Negotiates"
;
case
507
:
return
"Insufficient Storage"
;
case
508
:
return
"Loop Detected"
;
case
510
:
return
"Not Extended"
;
case
511
:
return
"Network Authentication Required"
;
}
return
null
;
}
}
}
src/Titanium.Web.Proxy/Network/Certificate/BCCertificateMaker.cs
View file @
88a552e2
using
System
;
using
System
;
using
System.IO
;
using
System.Security.Cryptography.X509Certificates
;
using
System.Threading
;
...
...
@@ -141,21 +141,8 @@ namespace Titanium.Web.Proxy.Network.Certificate
rsa
.
Prime1
,
rsa
.
Prime2
,
rsa
.
Exponent1
,
rsa
.
Exponent2
,
rsa
.
Coefficient
);
#if NET45
// Set private key onto certificate instance
X509Certificate2
x509Certificate
;
if
(
RunTime
.
IsRunningOnMono
)
{
x509Certificate
=
withPrivateKey
(
certificate
,
rsaparams
);
}
else
{
x509Certificate
=
new
X509Certificate2
(
certificate
.
GetEncoded
());
x509Certificate
.
PrivateKey
=
DotNetUtilities
.
ToRSA
(
rsaparams
);
}
#else
var
x509Certificate
=
withPrivateKey
(
certificate
,
rsaparams
);
#endif
if
(!
doNotSetFriendlyName
)
{
...
...
@@ -248,36 +235,6 @@ namespace Titanium.Web.Proxy.Network.Certificate
bool
switchToMtaIfNeeded
,
X509Certificate2
signingCert
=
null
,
CancellationToken
cancellationToken
=
default
)
{
#if NET45
if
(
switchToMtaIfNeeded
&&
Thread
.
CurrentThread
.
GetApartmentState
()
!=
ApartmentState
.
MTA
)
{
X509Certificate2
certificate
=
null
;
using
(
var
manualResetEvent
=
new
ManualResetEventSlim
(
false
))
{
ThreadPool
.
QueueUserWorkItem
(
o
=>
{
try
{
certificate
=
makeCertificateInternal
(
subject
,
isRoot
,
false
,
signingCert
);
}
catch
(
Exception
ex
)
{
exceptionFunc
(
new
Exception
(
"Failed to create BC certificate"
,
ex
));
}
if
(!
cancellationToken
.
IsCancellationRequested
)
{
manualResetEvent
.
Set
();
}
});
manualResetEvent
.
Wait
(
TimeSpan
.
FromMinutes
(
1
),
cancellationToken
);
}
return
certificate
;
}
#endif
return
makeCertificateInternal
(
isRoot
,
subject
,
$"CN=
{
subject
}
"
,
DateTime
.
UtcNow
.
AddDays
(-
certificateGraceDays
),
DateTime
.
UtcNow
.
AddDays
(
certificateValidDays
),
isRoot
?
null
:
signingCert
);
...
...
src/Titanium.Web.Proxy/ProxyServer.cs
View file @
88a552e2
...
...
@@ -238,11 +238,7 @@ namespace Titanium.Web.Proxy
/// <summary>
/// List of supported Ssl versions.
/// </summary>
public
SslProtocols
SupportedSslProtocols
{
get
;
set
;
}
=
#if NET45
SslProtocols
.
Ssl3
|
#endif
SslProtocols
.
Tls
|
SslProtocols
.
Tls11
|
SslProtocols
.
Tls12
;
public
SslProtocols
SupportedSslProtocols
{
get
;
set
;
}
=
SslProtocols
.
Ssl3
|
SslProtocols
.
Tls
|
SslProtocols
.
Tls11
|
SslProtocols
.
Tls12
;
/// <summary>
/// The buffer pool used throughout this proxy instance.
...
...
src/Titanium.Web.Proxy/StreamExtended/Network/CustomBufferedStream.cs
View file @
88a552e2
...
...
@@ -609,64 +609,5 @@ namespace Titanium.Web.Proxy.StreamExtended.Network
Buffer
.
BlockCopy
(
buffer
,
0
,
newBuffer
,
0
,
buffer
.
Length
);
buffer
=
newBuffer
;
}
#if NET45 || NETSTANDARD2_0
/// <summary>
/// Base Stream.BeginRead will call this.Read and block thread (we don't want this, Network stream handles async)
/// In order to really async Reading Launch this.ReadAsync as Task will fire NetworkStream.ReadAsync
/// See Threads here :
/// https://github.com/justcoding121/Stream-Extended/pull/43
/// https://github.com/justcoding121/Titanium-Web-Proxy/issues/575
/// </summary>
/// <returns></returns>
public
override
IAsyncResult
BeginRead
(
byte
[]
buffer
,
int
offset
,
int
count
,
AsyncCallback
callback
,
object
state
)
{
var
vAsyncResult
=
this
.
ReadAsync
(
buffer
,
offset
,
count
);
vAsyncResult
.
ContinueWith
(
pAsyncResult
=>
{
//use TaskExtended to pass State as AsyncObject
//callback will call EndRead (otherwise, it will block)
callback
?.
Invoke
(
new
TaskResult
<
int
>(
pAsyncResult
,
state
));
});
return
vAsyncResult
;
}
/// <summary>
/// override EndRead to handle async Reading (see BeginRead comment)
/// </summary>
/// <returns></returns>
public
override
int
EndRead
(
IAsyncResult
asyncResult
)
{
return
((
TaskResult
<
int
>)
asyncResult
).
Result
;
}
/// <summary>
/// Fix the .net bug with SslStream slow WriteAsync
/// https://github.com/justcoding121/Titanium-Web-Proxy/issues/495
/// Stream.BeginWrite + Stream.BeginRead uses the same SemaphoreSlim(1)
/// That's why we need to call NetworkStream.BeginWrite only (while read is waiting SemaphoreSlim)
/// </summary>
/// <returns></returns>
public
override
IAsyncResult
BeginWrite
(
byte
[]
buffer
,
int
offset
,
int
count
,
AsyncCallback
callback
,
object
state
)
{
var
vAsyncResult
=
this
.
WriteAsync
(
buffer
,
offset
,
count
);
vAsyncResult
.
ContinueWith
(
pAsyncResult
=>
{
callback
?.
Invoke
(
new
TaskResult
(
pAsyncResult
,
state
));
});
return
vAsyncResult
;
}
public
override
void
EndWrite
(
IAsyncResult
asyncResult
)
{
((
TaskResult
)
asyncResult
).
GetResult
();
}
#endif
}
}
src/Titanium.Web.Proxy/StreamExtended/TaskExtended.cs
deleted
100644 → 0
View file @
1cc485fa
using
System
;
using
System.Threading
;
using
System.Threading.Tasks
;
namespace
Titanium.Web.Proxy.StreamExtended
{
/// <summary>
/// Mimic a Task but you can set AsyncState
/// </summary>
/// <typeparam name="T"></typeparam>
public
class
TaskResult
:
IAsyncResult
{
Task
Task
;
object
mAsyncState
;
public
TaskResult
(
Task
pTask
,
object
state
)
{
Task
=
pTask
;
mAsyncState
=
state
;
}
public
object
AsyncState
=>
mAsyncState
;
public
WaitHandle
AsyncWaitHandle
=>
((
IAsyncResult
)
Task
).
AsyncWaitHandle
;
public
bool
CompletedSynchronously
=>
((
IAsyncResult
)
Task
).
CompletedSynchronously
;
public
bool
IsCompleted
=>
Task
.
IsCompleted
;
public
void
GetResult
()
{
this
.
Task
.
GetAwaiter
().
GetResult
();
}
}
/// <summary>
/// Mimic a Task<T> but you can set AsyncState
/// </summary>
/// <typeparam name="T"></typeparam>
public
class
TaskResult
<
T
>
:
IAsyncResult
{
Task
<
T
>
Task
;
object
mAsyncState
;
public
TaskResult
(
Task
<
T
>
pTask
,
object
state
)
{
Task
=
pTask
;
mAsyncState
=
state
;
}
public
object
AsyncState
=>
mAsyncState
;
public
WaitHandle
AsyncWaitHandle
=>
((
IAsyncResult
)
Task
).
AsyncWaitHandle
;
public
bool
CompletedSynchronously
=>
((
IAsyncResult
)
Task
).
CompletedSynchronously
;
public
bool
IsCompleted
=>
Task
.
IsCompleted
;
public
T
Result
=>
Task
.
Result
;
}
}
src/Titanium.Web.Proxy/Titanium.Web.Proxy.Mono.csproj
View file @
88a552e2
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net4
5
</TargetFrameworks>
<TargetFrameworks>net4
61
</TargetFrameworks>
<RootNamespace>Titanium.Web.Proxy</RootNamespace>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<SignAssembly>True</SignAssembly>
...
...
@@ -16,7 +16,7 @@
<PackageReference Include="Portable.BouncyCastle" Version="1.8.5" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net4
5
'">
<ItemGroup Condition="'$(TargetFramework)' == 'net4
61
'">
<Reference Include="System.Web" />
</ItemGroup>
...
...
src/Titanium.Web.Proxy/Titanium.Web.Proxy.NetCore.csproj
View file @
88a552e2
...
...
@@ -34,7 +34,7 @@
</PackageReference>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net4
5
'">
<ItemGroup Condition="'$(TargetFramework)' == 'net4
61
'">
<Reference Include="System.Web" />
</ItemGroup>
...
...
src/Titanium.Web.Proxy/Titanium.Web.Proxy.csproj
View file @
88a552e2
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net4
5
;netstandard2.0;netcoreapp2.1</TargetFrameworks>
<TargetFrameworks>net4
61
;netstandard2.0;netcoreapp2.1</TargetFrameworks>
<RootNamespace>Titanium.Web.Proxy</RootNamespace>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<SignAssembly>True</SignAssembly>
...
...
@@ -35,7 +35,7 @@
</PackageReference>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net4
5
'">
<ItemGroup Condition="'$(TargetFramework)' == 'net4
61
'">
<Reference Include="System.Web" />
</ItemGroup>
...
...
src/Titanium.Web.Proxy/Titanium.Web.Proxy.nuspec
View file @
88a552e2
...
...
@@ -14,7 +14,7 @@
<copyright>
Copyright
©
Titanium. All rights reserved.
</copyright>
<tags></tags>
<dependencies>
<group
targetFramework=
"net4
5
"
>
<group
targetFramework=
"net4
61
"
>
<dependency
id=
"Portable.BouncyCastle"
version=
"1.8.5"
/>
<dependency
id=
"BrotliSharpLib"
version=
"0.3.3"
/>
</group>
...
...
@@ -33,7 +33,7 @@
</dependencies>
</metadata>
<files>
<file
src=
"bin\$configuration$\net4
5\Titanium.Web.Proxy.dll"
target=
"lib\net45
"
/>
<file
src=
"bin\$configuration$\net4
61\Titanium.Web.Proxy.dll"
target=
"lib\net461
"
/>
<file
src=
"bin\$configuration$\netstandard2.0\Titanium.Web.Proxy.dll"
target=
"lib\netstandard2.0"
/>
</files>
</package>
tests/Titanium.Web.Proxy.UnitTests/Titanium.Web.Proxy.UnitTests.csproj
View file @
88a552e2
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net4
5
</TargetFramework>
<TargetFramework>net4
61
</TargetFramework>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>StrongNameKey.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment