Skip to content

Commit

Permalink
Http Proxy Improvements
Browse files Browse the repository at this point in the history
Bug: proxy connect packet is malformed due to a space after HTTP/1.1.
Feature: Pass the host name so proxy host acls can be matched.
Feature: Switch to the WebRequest.DefaultWebProxy which allows for overriding in app.settings file and falls back to the system proxy if not configured.
Improvement: Use ordinal comparision for IndexOf on the proxy response.

Resolves #742 (original PR, this is a rebase)
  • Loading branch information
iclaxton authored and gbirchmeier committed Dec 30, 2024
1 parent 1c61bf5 commit 6828787
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 4 additions & 4 deletions QuickFIXn/Transport/StreamFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ namespace QuickFix.Transport
/// </summary>
internal static class StreamFactory
{
private static Socket? CreateTunnelThruProxy(string destIp, int destPort)
private static Socket? CreateTunnelThruProxy(string destIp, int destPort, string destHostName)
{
string destUriWithPort = $"{destIp}:{destPort}";
UriBuilder uriBuilder = new UriBuilder(destUriWithPort);
Uri destUri = uriBuilder.Uri;
IWebProxy webProxy = WebRequest.GetSystemWebProxy();
IWebProxy webProxy = WebRequest.DefaultWebProxy ?? WebRequest.GetSystemWebProxy();

try
{
Expand All @@ -44,7 +44,7 @@ internal static class StreamFactory
Socket socketThruProxy = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socketThruProxy.Connect(proxyEndPoint);

string proxyMsg = $"CONNECT {destIp}:{destPort} HTTP/1.1 \n\n";
string proxyMsg = $"CONNECT {destHostName}:{destPort} HTTP/1.1\nHost: {destHostName}:{destPort}\n\n";
byte[] buffer = Encoding.ASCII.GetBytes(proxyMsg);
byte[] buffer12 = new byte[500];
socketThruProxy.Send(buffer, buffer.Length, 0);
Expand Down Expand Up @@ -73,7 +73,7 @@ internal static Stream CreateClientStream(IPEndPoint endpoint, SocketSettings se
if (!settings.SocketIgnoreProxy)
{
// If system has configured a proxy for this config, use it.
socket = CreateTunnelThruProxy(endpoint.Address.ToString(), endpoint.Port);
socket = CreateTunnelThruProxy(endpoint.Address.ToString(), endpoint.Port, settings.ServerCommonName);

Check warning on line 76 in QuickFIXn/Transport/StreamFactory.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'destHostName' in 'Socket? StreamFactory.CreateTunnelThruProxy(string destIp, int destPort, string destHostName)'.

Check warning on line 76 in QuickFIXn/Transport/StreamFactory.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'destHostName' in 'Socket? StreamFactory.CreateTunnelThruProxy(string destIp, int destPort, string destHostName)'.
}

// No proxy. Set up a regular socket.
Expand Down
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ What's New
* #516 - remove ability to toggle Session-enable via HttpServer because it never really worked (gbirchmeier)
* #913/#741 - new FieldMap.ReadGroups for iterating on groups (NoviProg/gbirchmeier)
* #914 - Optimize MessageCracker.IsHandlerMethod (vasily-balansea)
* #742 - Improvements to HTTP web proxy (IanLeeClaxton)

### v1.12.0

Expand Down

0 comments on commit 6828787

Please sign in to comment.