Skip to content

Commit

Permalink
fixed thenunit tests for proxy protocol v1
Browse files Browse the repository at this point in the history
  • Loading branch information
kerryjiang committed Aug 18, 2024
1 parent b6a6487 commit b592d70
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceRoot}/test/Test/bin/Debug/net7.0/Test.dll",
"program": "${workspaceRoot}/test/Test/bin/Debug/net8.0/Test.dll",
"args": [],
"cwd": "${workspaceRoot}/test/Test",
// For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public override bool Process(TPackageInfo package, object filterContext, ref Seq

var proxyInfo = filterContext as ProxyInfo;

LoadProxyInfo(proxyInfo, proxyLine, 12, 13);
// "PROXY TCP4 X", start look for next segment from X(@11)
LoadProxyInfo(proxyInfo, proxyLine, 11, 12);

proxyInfo.Version = 1;
proxyInfo.Command = ProxyCommand.PROXY;
Expand All @@ -54,13 +55,19 @@ private void LoadProxyInfo(ProxyInfo proxyInfo, string line, int startPos, int l
{
var spacePos = line.IndexOf(' ', lookForOffet);

if (spacePos < 0)
break;

startPos = spacePos + 1;
lookForOffet = startPos + 1;

var segment = span.Slice(startPos, spacePos - startPos);
ReadOnlySpan<char> segment;

if (spacePos >= 0)
{
segment = span.Slice(startPos, spacePos - startPos);
startPos = spacePos + 1;
lookForOffet = startPos + 1;
}
else
{
segment = span.Slice(startPos);
lookForOffet = line.Length;
}

PROXY_SEGMENT_PARSERS[segmentIndex++].Process(segment, proxyInfo);
}
Expand Down Expand Up @@ -99,7 +106,7 @@ class DestinationPortProcessor : IProxySgementProcessor
{
public void Process(ReadOnlySpan<char> segment, ProxyInfo proxyInfo)
{
proxyInfo.SourcePort = int.Parse(segment);
proxyInfo.DestinationPort = int.Parse(segment);
}
}
}
Expand Down

0 comments on commit b592d70

Please sign in to comment.