Skip to content

Commit

Permalink
Avoid redundant null checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-ludwig committed Feb 9, 2016
1 parent be6562d commit 70b4cc5
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions source/vibe/http/client.d
Original file line number Diff line number Diff line change
Expand Up @@ -168,22 +168,23 @@ unittest {
usually requestHTTP should be used for making requests instead of manually using a
HTTPClient to do so.
*/
auto connectHTTP(string host, ushort port = 0, bool use_tls = false, HTTPClientSettings settings = defaultSettings)
auto connectHTTP(string host, ushort port = 0, bool use_tls = false, HTTPClientSettings settings = null)
{
static struct ConnInfo { string host; ushort port; bool useTLS; string proxyIP; ushort proxyPort; NetworkAddress bind_addr; }
static FixedRingBuffer!(Tuple!(ConnInfo, ConnectionPool!HTTPClient), 16) s_connections;

if (!settings) settings = defaultSettings;

if( port == 0 ) port = use_tls ? 443 : 80;
auto ckey = ConnInfo(host, port, use_tls,
settings?settings.proxyURL.host:null, settings?settings.proxyURL.port:0,
settings ? settings.networkInterface : anyAddress);
auto ckey = ConnInfo(host, port, use_tls, settings.proxyURL.host, settings.proxyURL.port, settings.networkInterface);

ConnectionPool!HTTPClient pool;
foreach (c; s_connections)
if (c[0] == ckey)
pool = c[1];

if (!pool) {
logDebug("Create HTTP client pool %s:%s %s proxy %s:%d", host, port, use_tls, ( settings ) ? settings.proxyURL.host : string.init, ( settings ) ? settings.proxyURL.port : 0);
logDebug("Create HTTP client pool %s:%s %s proxy %s:%d", host, port, use_tls, settings.proxyURL.host, settings.proxyURL.port);
pool = new ConnectionPool!HTTPClient({
auto ret = new HTTPClient;
ret.connect(host, port, use_tls, settings);
Expand Down

0 comments on commit 70b4cc5

Please sign in to comment.