Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to HTTP web proxy #742

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions QuickFIXn/SocketSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ public class SocketSettings : ICloneable
{
#region Socket Settings

/// <summary>
/// Store the socket host name so we can use it to connect via proxy if required.
/// </summary>
/// <value>
/// The host name (without port number) to send to the proxy server for acl matching.
/// </value>
public string SocketConnectHost { get; internal set; }

/// <summary>
/// Gets a value that specifies whether the <see cref="T:System.Net.Sockets.Socket"/> is using the Nagle algorithm.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion QuickFIXn/Transport/SocketInitiator.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private IPEndPoint GetNextSocketEndPoint(SessionID sessionId, QuickFix.Dictionar
int port = System.Convert.ToInt32(settings.GetLong(portKey));
_sessionToHostNum[sessionId] = ++num;

_socketSettings.ServerCommonName = hostName;
_socketSettings.SocketConnectHost = _socketSettings.ServerCommonName = hostName;
return new IPEndPoint(addrs.First(a => a.AddressFamily == AddressFamily.InterNetwork), port);
}
catch (Exception e)
Expand Down
10 changes: 6 additions & 4 deletions QuickFIXn/Transport/StreamFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ namespace QuickFix.Transport
/// </summary>
public 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 @@ -50,7 +50,9 @@ public 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 = !string.IsNullOrWhiteSpace(destHostName)
IanLeeClaxton marked this conversation as resolved.
Show resolved Hide resolved
? $"CONNECT {destHostName}:{destPort} HTTP/1.1\nHost: {destHostName}:{destPort}\n\n"
: $"CONNECT {destIp}:{destPort} HTTP/1.1\n\n";
byte[] buffer = Encoding.ASCII.GetBytes(proxyMsg);
byte[] buffer12 = new byte[500];
socketThruProxy.Send(buffer, buffer.Length, 0);
Expand Down Expand Up @@ -79,7 +81,7 @@ public static Stream CreateClientStream(IPEndPoint endpoint, SocketSettings sett
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.SocketConnectHost);
IanLeeClaxton marked this conversation as resolved.
Show resolved Hide resolved
}

// No proxy. Set up a regular socket.
Expand Down
Loading