Skip to content
This repository has been archived by the owner on Jun 8, 2022. It is now read-only.

Commit

Permalink
Misc cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaZupan committed Apr 6, 2019
1 parent 548f428 commit 2d7b612
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -13,10 +13,10 @@ var proxy = new HttpToSocks5Proxy("127.0.0.1", 1080);
var handler = new HttpClientHandler { Proxy = proxy };
HttpClient httpClient = new HttpClient(handler, true);

var httpsGet = httpClient.SendAsync(
var result = await httpClient.SendAsync(
new HttpRequestMessage(HttpMethod.Get, "https://httpbin.org/ip"));

Console.WriteLine("HTTPS GET: " + httpsGet.Result.Content.ReadAsStringAsync().Result);
Console.WriteLine("HTTPS GET: " + await result.Content.ReadAsStringAsync());
```

## Usage with Telegram.Bot library
Expand Down
4 changes: 2 additions & 2 deletions src/HttpToSocks5Proxy/Helpers.cs
Expand Up @@ -19,13 +19,13 @@ public static SocketConnectionResult ToConnectionResult(this SocketException exc
return SocketConnectionResult.ConnectionError;
}

public static bool ContainsDoubleNewLine(this byte[] buffer, int offset, out int endOfHeader)
public static bool ContainsDoubleNewLine(this byte[] buffer, int offset, int limit, out int endOfHeader)
{
const byte R = (byte)'\r';
const byte N = (byte)'\n';

bool foundOne = false;
for (endOfHeader = offset; endOfHeader < buffer.Length; endOfHeader++)
for (endOfHeader = offset; endOfHeader < limit; endOfHeader++)
{
if (buffer[endOfHeader] == N)
{
Expand Down
10 changes: 5 additions & 5 deletions src/HttpToSocks5Proxy/HttpToSocks5Proxy.cs
Expand Up @@ -333,13 +333,13 @@ private static bool TryReadTarget(Socket clientSocket, out string hostname, out

return true;
}
private static bool TryReadHeaders(Socket clientSocket, out byte[] headesrBuffer, out int received, out int endOfHeader)
private static bool TryReadHeaders(Socket clientSocket, out byte[] headersBuffer, out int received, out int endOfHeader)
{
received = 0;
endOfHeader = 0;
int offset = 0;
headesrBuffer = new byte[8192];
headersBuffer = new byte[8192];
int left = 8192;
int offset;
// According to https://stackoverflow.com/a/686243/6845657 even Apache gives up after 8KB

do
Expand All @@ -350,12 +350,12 @@ private static bool TryReadHeaders(Socket clientSocket, out byte[] headesrBuffer
return false;
}
offset = received;
int read = clientSocket.Receive(headesrBuffer, received, left, SocketFlags.None);
int read = clientSocket.Receive(headersBuffer, received, left, SocketFlags.None);
received += read;
left -= read;
}
// received - 3 is used because we could have read the start of the double new line in the previous read
while (!headesrBuffer.ContainsDoubleNewLine(Math.Max(0, received - 3), out endOfHeader));
while (!headersBuffer.ContainsDoubleNewLine(Math.Max(0, offset - 3), received, out endOfHeader));

return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/HttpToSocks5Proxy/HttpToSocks5Proxy.csproj
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
Expand All @@ -9,8 +9,8 @@
<Company>MihaZupan</Company>
<Description>This is a class that implements the IWebProxy interface to act as an HTTP(S) proxy while connecting to a SOCKS5 server behind the scenes.</Description>
<Copyright>Copyright © Miha Zupan 2018</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/MihaZupan/HttpToSocks5Proxy</PackageProjectUrl>
<PackageLicenseUrl>https://raw.githubusercontent.com/MihaZupan/HttpToSocks5Proxy/master/LICENSE</PackageLicenseUrl>
<PackageIconUrl>https://telegram.org/img/tl_card_decentralized.gif</PackageIconUrl>
<RepositoryUrl>https://github.com/MihaZupan/HttpToSocks5Proxy.git</RepositoryUrl>
<PackageTags>Proxy;Socks5;Socks;Http;Telegram;Bot</PackageTags>
Expand Down
2 changes: 1 addition & 1 deletion src/HttpToSocks5Proxy/Socks5.cs
Expand Up @@ -129,7 +129,7 @@ private static byte[] BuildRequestMessage(Command command, AddressType addressTy
byte[] domainBytes = Encoding.UTF8.GetBytes(address);
addressLength = 1 + domainBytes.Length;
addressBytes = new byte[addressLength];
addressBytes[0] = (byte)address.Length;
addressBytes[0] = (byte)domainBytes.Length;
Array.Copy(domainBytes, 0, addressBytes, 1, domainBytes.Length);
break;

Expand Down

0 comments on commit 2d7b612

Please sign in to comment.