Skip to content

Commit 653a925

Browse files
committed
- Fix HTTPS proxies some issues (issue #44)
- Changed target NET Framework to 4.5 now supported (4.5+ now supported) - ProxyClient.AbsoluteUriInStartingLine by default is false now
1 parent fa9d032 commit 653a925

File tree

6 files changed

+33
-24
lines changed

6 files changed

+33
-24
lines changed

Leaf.xNet.Tests/Leaf.xNet.Tests.csproj

Lines changed: 1 addition & 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>net472;netcoreapp3.0</TargetFrameworks>
4+
<TargetFrameworks>net45;netcoreapp3.0</TargetFrameworks>
55

66
<IsPackable>false</IsPackable>
77

Leaf.xNet/Leaf.xNet.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<AppDesignerFolder>Properties</AppDesignerFolder>
1212
<RootNamespace>Leaf.xNet</RootNamespace>
1313
<AssemblyName>Leaf.xNet</AssemblyName>
14-
<TargetFrameworks>net452;net462;net472;net48;netstandard2.0</TargetFrameworks>
14+
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
1515
<FileAlignment>512</FileAlignment>
1616
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1717
<Authors>Grand Silence</Authors>
@@ -49,7 +49,7 @@
4949
<PackageTags>net,http,socks,proxy,cloudflare,xnet,https,stormwall,useragent,parsing,bot,web,crowling</PackageTags>
5050
<PackageIcon>icon.png</PackageIcon>
5151
<NoWarn>1591,1573</NoWarn>
52-
<Description>Improved xNet for .NET Framework 4.5.2+ &amp; .NET Core 2+</Description> <!-- Ignore warinings abound undocumented code -->
52+
<Description>Improved xNet for .NET Framework 4.5+ / .NET Standard 2.0</Description> <!-- Ignore warinings abound undocumented code -->
5353
</PropertyGroup>
5454

5555
<ItemGroup>

Leaf.xNet/~Http/HttpRequest.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,18 @@ public HttpRequest()
735735
{
736736
Init();
737737
}
738+
739+
static HttpRequest()
740+
{
741+
// It's a fix of HTTPs Proxies SSL issue
742+
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
743+
ServicePointManager.ServerCertificateValidationCallback += ServerCertificateValidationCallback;
744+
}
745+
746+
private static bool ServerCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslpolicyerrors)
747+
{
748+
return true;
749+
}
738750

739751
/// <summary>
740752
/// Инициализирует новый экземпляр класса <see cref="HttpRequest"/>.
@@ -3528,7 +3540,12 @@ private void CreateConnection(Uri address)
35283540
private string GenerateStartingLine(HttpMethod method)
35293541
{
35303542
// Fix by Igor Vacil'ev: sometimes proxies returns 404 when used full path.
3531-
string query = _currentProxy != null && _currentProxy.Type == ProxyType.HTTP && _currentProxy.AbsoluteUriInStartingLine
3543+
bool hasHttpProxyWithAbsoluteUriInStartingLine =
3544+
_currentProxy != null &&
3545+
_currentProxy.Type == ProxyType.HTTP &&
3546+
_currentProxy.AbsoluteUriInStartingLine;
3547+
3548+
string query = hasHttpProxyWithAbsoluteUriInStartingLine
35323549
? Address.AbsoluteUri
35333550
: Address.PathAndQuery;
35343551

Leaf.xNet/~Proxy/HttpProxyClient.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,14 @@ private string GenerateAuthorizationHeader()
194194

195195
private void SendConnectionCommand(Stream nStream, string destinationHost, int destinationPort)
196196
{
197-
var commandBuilder = new StringBuilder();
198-
199-
commandBuilder.AppendFormat("CONNECT {0}:{1} HTTP/{2}\r\n", destinationHost, destinationPort, ProtocolVersion);
200-
commandBuilder.AppendFormat(GenerateAuthorizationHeader());
201-
commandBuilder.AppendLine();
202-
203-
var buffer = Encoding.ASCII.GetBytes(commandBuilder.ToString());
204-
197+
var sb = new StringBuilder();
198+
sb.AppendFormat("CONNECT {0}:{1} HTTP/{2}\r\n", destinationHost, destinationPort, ProtocolVersion);
199+
sb.AppendFormat(GenerateAuthorizationHeader());
200+
sb.Append("Host: "); sb.AppendLine(destinationHost);
201+
sb.AppendLine("Proxy-Connection: Keep-Alive");
202+
sb.AppendLine();
203+
204+
var buffer = Encoding.ASCII.GetBytes(sb.ToString());
205205
nStream.Write(buffer, 0, buffer.Length);
206206
}
207207

Leaf.xNet/~Proxy/ProxyClient.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public int ReadWriteTimeout
152152
/// Если задано <see langword="false"/> - всегда будет использован относительный адрес в заголовке запроса.
153153
/// </summary>
154154
// ReSharper disable once MemberCanBePrivate.Global
155-
public bool AbsoluteUriInStartingLine { get; set; } = true;
155+
public bool AbsoluteUriInStartingLine { get; set; }
156156

157157
#endregion
158158

@@ -215,8 +215,6 @@ public static HttpProxyClient DebugHttpProxy {
215215
return _debugHttpProxy;
216216

217217
_debugHttpProxy = HttpProxyClient.Parse("127.0.0.1:8888");
218-
_debugHttpProxy.AbsoluteUriInStartingLine = false; // Fix tree Charles bug
219-
220218
return _debugHttpProxy;
221219
}
222220
}

appveyor.yml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,8 @@ build:
2828
publish_nuget: true
2929
verbosity: minimal
3030
artifacts:
31-
- path: Leaf.xNet\bin\Release\net452
32-
name: Leaf.xNet_v$(appveyor_build_version)__NET_Framework_4.5.2
33-
- path: Leaf.xNet\bin\Release\net462
34-
name: Leaf.xNet_v$(appveyor_build_version)__NET_Framework_4.6.2
35-
- path: Leaf.xNet\bin\Release\net472
36-
name: Leaf.xNet_v$(appveyor_build_version)__NET_Framework_4.7.2
37-
- path: Leaf.xNet\bin\Release\net48
38-
name: Leaf.xNet_v$(appveyor_build_version)__NET_Framework_4.8
31+
- path: Leaf.xNet\bin\Release\net45
32+
name: Leaf.xNet_v$(appveyor_build_version)__NET_Framework_4.5
3933
- path: Leaf.xNet\bin\Release\netstandard2.0
4034
name: Leaf.xNet_v$(appveyor_build_version)__NET_Standard_2.0
4135
deploy:
@@ -50,7 +44,7 @@ deploy:
5044
release: Leaf.xNet v$(appveyor_build_version)
5145
auth_token:
5246
secure: NQtMOO3yB309cDK/pFWRiQ==
53-
artifact: Leaf.xNet_v$(appveyor_build_version)__NET_Framework_4.5.2;Leaf.xNet_v$(appveyor_build_version)__NET_Framework_4.6.2;Leaf.xNet_v$(appveyor_build_version)__NET_Framework_4.7.2;Leaf.xNet_v$(appveyor_build_version)__NET_Framework_4.8;Leaf.xNet_v$(appveyor_build_version)__NET_Standard_2.0
47+
artifact: Leaf.xNet_v$(appveyor_build_version)__NET_Framework_4.5;Leaf.xNet_v$(appveyor_build_version)__NET_Standard_2.0
5448
on:
5549
branch: master
5650
only_commits:

0 commit comments

Comments
 (0)