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

Commit 94e57f7

Browse files
Merge pull request #456 from justcoding121/master
Beta
2 parents 2560b80 + f65cece commit 94e57f7

File tree

47 files changed

+148
-121
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+148
-121
lines changed

PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Doneness:
22
- [ ] Build is okay - I made sure that this change is building successfully.
33
- [ ] No Bugs - I made sure that this change is working properly as expected. It doesn't have any bugs that you are aware of.
4-
- [ ] Branching - If this is not a hotfix, I am making this request against develop branch
4+
- [ ] Branching - If this is not a hotfix, I am making this request against master branch

Titanium.Web.Proxy.sln.DotSettings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
2424
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
2525
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
26+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=a4ab2e69_002D4d9c_002D4345_002Dbcd1_002D5541dacf5d38/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Static, Instance" AccessRightKinds="Private" Description="Method (private)"&gt;&lt;ElementKinds&gt;&lt;Kind Name="METHOD" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;&lt;/Policy&gt;</s:String>
2627
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=dda2ffa1_002D435c_002D4111_002D88eb_002D1a7c93c382f0/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Static, Instance" AccessRightKinds="Private" Description="Property (private)"&gt;&lt;ElementKinds&gt;&lt;Kind Name="PROPERTY" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;&lt;/Policy&gt;</s:String>
2728
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpAttributeForSingleLineMethodUpgrade/@EntryIndexedValue">True</s:Boolean>
2829
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>

Titanium.Web.Proxy/Helpers/Network.cs

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,44 +21,52 @@ internal static bool IsLocalIpAddress(IPAddress address)
2121

2222
// get local IP addresses
2323
var localIPs = Dns.GetHostAddresses(Dns.GetHostName());
24-
24+
2525
// test if any host IP equals to any local IP or to localhost
2626
return localIPs.Contains(address);
2727
}
2828

2929
internal static bool IsLocalIpAddress(string hostName)
3030
{
31-
bool isLocalhost = false;
31+
hostName = hostName.ToLower();
3232

33-
var localhost = Dns.GetHostEntry("127.0.0.1");
34-
if (hostName == localhost.HostName)
33+
if (hostName == "127.0.0.1"
34+
|| hostName == "localhost")
3535
{
36-
var hostEntry = Dns.GetHostEntry(hostName);
37-
isLocalhost = hostEntry.AddressList.Any(IPAddress.IsLoopback);
36+
return true;
3837
}
3938

40-
if (!isLocalhost)
39+
var localhostDnsName = Dns.GetHostName().ToLower();
40+
41+
//if hostname matches current machine DNS name
42+
if (hostName == localhostDnsName)
43+
{
44+
return true;
45+
}
46+
47+
var isLocalhost = false;
48+
IPHostEntry hostEntry = null;
49+
50+
//check if parsable to an IP Address
51+
if (IPAddress.TryParse(hostName, out var ipAddress))
4152
{
42-
localhost = Dns.GetHostEntry(Dns.GetHostName());
53+
hostEntry = Dns.GetHostEntry(localhostDnsName);
54+
isLocalhost = hostEntry.AddressList.Any(x => x.Equals(ipAddress));
55+
}
4356

44-
if (IPAddress.TryParse(hostName, out var ipAddress))
57+
if (!isLocalhost)
58+
{
59+
try
4560
{
46-
isLocalhost = localhost.AddressList.Any(x => x.Equals(ipAddress));
61+
hostEntry = Dns.GetHostEntry(hostName);
62+
isLocalhost = hostEntry.AddressList.Any(x => hostEntry.AddressList.Any(x.Equals));
4763
}
48-
49-
if (!isLocalhost)
64+
catch (SocketException)
5065
{
51-
try
52-
{
53-
var hostEntry = Dns.GetHostEntry(hostName);
54-
isLocalhost = localhost.AddressList.Any(x => hostEntry.AddressList.Any(x.Equals));
55-
}
56-
catch (SocketException)
57-
{
58-
}
5966
}
6067
}
6168

69+
6270
return isLocalhost;
6371
}
6472
}

Titanium.Web.Proxy/Http2/Hpack/Decoder.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public void Decode(BinaryReader input, IHeaderListener headerListener)
173173
break;
174174

175175
case State.ReadMaxDynamicTableSize:
176-
int maxSize = DecodeULE128(input);
176+
int maxSize = decodeULE128(input);
177177
if (maxSize == -1)
178178
{
179179
return;
@@ -190,7 +190,7 @@ public void Decode(BinaryReader input, IHeaderListener headerListener)
190190
break;
191191

192192
case State.ReadIndexedHeader:
193-
int headerIndex = DecodeULE128(input);
193+
int headerIndex = decodeULE128(input);
194194
if (headerIndex == -1)
195195
{
196196
return;
@@ -208,7 +208,7 @@ public void Decode(BinaryReader input, IHeaderListener headerListener)
208208

209209
case State.ReadIndexedHeaderName:
210210
// Header Name matches an entry in the Header Table
211-
int nameIndex = DecodeULE128(input);
211+
int nameIndex = decodeULE128(input);
212212
if (nameIndex == -1)
213213
{
214214
return;
@@ -272,7 +272,7 @@ public void Decode(BinaryReader input, IHeaderListener headerListener)
272272

273273
case State.ReadLiteralHeaderNameLength:
274274
// Header Name is a Literal String
275-
nameLength = DecodeULE128(input);
275+
nameLength = decodeULE128(input);
276276
if (nameLength == -1)
277277
{
278278
return;
@@ -388,7 +388,7 @@ public void Decode(BinaryReader input, IHeaderListener headerListener)
388388

389389
case State.ReadLiteralHeaderValueLength:
390390
// Header Value is a Literal String
391-
valueLength = DecodeULE128(input);
391+
valueLength = decodeULE128(input);
392392
if (valueLength == -1)
393393
{
394394
return;
@@ -612,7 +612,7 @@ private string ReadStringLiteral(BinaryReader input, int length)
612612
}
613613

614614
// Unsigned Little Endian Base 128 Variable-Length Integer Encoding
615-
private static int DecodeULE128(BinaryReader input)
615+
private static int decodeULE128(BinaryReader input)
616616
{
617617
long markedPosition = input.BaseStream.Position;
618618
int result = 0;

0 commit comments

Comments
 (0)