Skip to content

Commit a0fe4b5

Browse files
author
Christiaan baes
committed
Added AutomaticProxyDetection to Connectionconfiguration
So that we can set proxy to nul an avoid Automaticproxudection when there is nothing to detect, looking for automatic proxy setting can slow down the first call by 5 seconds.
1 parent 621f1cb commit a0fe4b5

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

Diff for: src/Elasticsearch.Net/Connection/ConnectionConfiguration.cs

+14
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ public class ConnectionConfiguration<T> : IConnectionConfigurationValues, IHideO
8282
#endif
8383
bool IConnectionConfigurationValues.KeepRawResponse { get{ return _keepRawResponse; } }
8484

85+
private bool _automatixProxyDetection;
86+
bool IConnectionConfigurationValues.AutomaticProxyDetection { get { return _automatixProxyDetection} }
87+
8588
private int _maximumAsyncConnections;
8689
int IConnectionConfigurationValues.MaximumAsyncConnections { get{ return _maximumAsyncConnections; } }
8790

@@ -290,6 +293,17 @@ public T SetConnectionStatusHandler(Action<IElasticsearchResponse> handler)
290293
this._connectionStatusHandler = handler;
291294
return (T) this;
292295
}
296+
297+
/// <summary>
298+
/// Sometimes automatic proxydection can be very slow when there is no proxy that can be detected.
299+
/// </summary>
300+
/// <param name="enabled">defaults to true</param>
301+
/// <returns></returns>
302+
public T AutomatixProxyDetection(bool b = true)
303+
{
304+
this._automatixProxyDetection = b;
305+
return (T)this;
306+
}
293307
}
294308
}
295309

Diff for: src/Elasticsearch.Net/Connection/HttpConnection.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,10 @@ private void SetProxyIfNeeded(HttpWebRequest myReq)
146146
proxy.Credentials = credentials;
147147
myReq.Proxy = proxy;
148148
}
149-
//myReq.Proxy = null;
149+
if(!this.ConnectionSettings.AutomatixProxyDetection)
150+
{
151+
myReq.Proxy = null;
152+
}
150153
}
151154

152155
private void SetBasicAuthorizationIfNeeded(HttpWebRequest myReq)

Diff for: src/Elasticsearch.Net/Connection/IConnectionConfiguration.cs

+7
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,12 @@ public interface IConnectionConfiguration<out T> : IHideObjectMembers
6565
/// Global callback for every response that NEST receives, useful for custom logging.
6666
/// </summary>
6767
T SetConnectionStatusHandler(Action<IElasticsearchResponse> handler);
68+
69+
/// <summary>
70+
/// Sometimes automatic proxydection can be very slow when there is no proxy that can be detected.
71+
/// </summary>
72+
/// <param name="enabled">defaults to true</param>
73+
/// <returns></returns>
74+
T AutomatixProxyDetection(bool enabled = true)
6875
}
6976
}

Diff for: src/Elasticsearch.Net/Connection/IConnectionConfigurationValues.cs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public interface IConnectionConfigurationValues
2424
bool TraceEnabled { get; }
2525
bool UsesPrettyResponses { get; }
2626
bool KeepRawResponse { get; }
27+
bool AutomaticProxyDetection { get; }
2728

2829
/// <summary>
2930
/// Instead of following a c/go like error checking on response.IsValid always throw an ElasticsearchServerException

0 commit comments

Comments
 (0)