Skip to content

Commit fc9a14b

Browse files
committed
added missing changes
1 parent 061011c commit fc9a14b

File tree

6 files changed

+39
-45
lines changed

6 files changed

+39
-45
lines changed

src/Nest.Tests.Integration/Nest.Tests.Integration.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
<Compile Include="Integration\Query\TermQueryDynamic.cs" />
106106
<Compile Include="Mapping\NotAnalyzedTest.cs" />
107107
<Compile Include="Reproduce\ReproduceTests.cs" />
108+
<Compile Include="Search\NamedFilter\NamedFilterTests.cs" />
108109
<Compile Include="Search\PercolateTests.cs" />
109110
<Compile Include="Search\CountTests.cs" />
110111
<Compile Include="Facet\GeoDistanceFacetResponseTests.cs" />

src/Nest.Tests.Unit/Core/Domain/Connection/ConnectionTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ public void CanCreateConnectionWithCustomQueryStringParameters()
2626
// Arrange
2727
var uri = new Uri("http://localhost");
2828
var query = new NameValueCollection { { "authToken", "ABCDEFGHIJK" } };
29-
var connectionSettings = new ConnectionSettings(uri, query);
29+
var connectionSettings = new ConnectionSettings(uri).SetGlobalQueryStringParameters(query);
3030
var connection = new TestConnection(connectionSettings);
3131

3232
// Act
3333
var req = connection.GetConnection("/", "GET");
3434

3535
// Assert
36-
Assert.IsTrue(string.Compare(req.Address.ToString(), "http://localhost/?authToken=ABCDEFGHIJK", StringComparison.OrdinalIgnoreCase) == 0);
36+
Assert.AreEqual(req.Address.ToString(), "http://localhost/?authToken=ABCDEFGHIJK");
3737
}
3838

3939
[Test]
@@ -42,14 +42,14 @@ public void CanCreateConnectionWithPathAndCustomQueryStringParameters()
4242
// Arrange
4343
var uri = new Uri("http://localhost:9000");
4444
var query = new NameValueCollection { { "authToken", "ABCDEFGHIJK" } };
45-
var connectionSettings = new ConnectionSettings(uri, query);
45+
var connectionSettings = new ConnectionSettings(uri).SetGlobalQueryStringParameters(query);
4646
var connection = new TestConnection(connectionSettings);
4747

4848
// Act
4949
var req = connection.GetConnection("/index/", "GET");
5050

5151
// Assert
52-
Assert.IsTrue(string.Compare(req.Address.ToString(), "http://localhost:9000/index/?authToken=ABCDEFGHIJK", StringComparison.OrdinalIgnoreCase) == 0);
52+
Assert.AreEqual(req.Address.ToString(), "http://localhost:9000/index/?authToken=ABCDEFGHIJK");
5353
}
5454
}
5555
}

src/Nest/Domain/Connection/Connection.cs

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,7 @@ private void SetBasicAuthorizationIfNeeded(HttpWebRequest myReq)
148148
private HttpWebRequest CreateWebRequest(string path, string method)
149149
{
150150
var url = this._CreateUriString(path);
151-
if (this._ConnectionSettings.UsesPrettyResponses)
152-
{
153-
var uri = new Uri(url);
154-
url += (string.IsNullOrEmpty(uri.Query) ? "?" : "&") + "pretty=true";
155-
}
151+
156152
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url);
157153
myReq.Accept = "application/json";
158154
myReq.ContentType = "application/json";
@@ -209,12 +205,7 @@ protected virtual ConnectionStatus DoSynchronousRequest(HttpWebRequest request,
209205
return cs;
210206
}
211207
}
212-
catch (WebException webException)
213-
{
214-
var cs = new ConnectionStatus(webException) { Request = data, RequestUrl = request.RequestUri.ToString(), RequestMethod = request.Method };
215-
_ConnectionSettings.ConnectionStatusHandler(cs);
216-
return cs;
217-
}
208+
218209
}
219210

220211
protected virtual Task<ConnectionStatus> DoAsyncRequest(HttpWebRequest request, string data = null)
@@ -344,19 +335,20 @@ private string _CreateUriString(string path)
344335
var uri = new Uri(s.Uri, path);
345336
var url = uri.ToString();
346337

347-
if (s.QueryStringParameters != null)
348-
{
349-
var existingParams = uri.Query.ToNameValueCollection();
350-
var appendedParams = new NameValueCollection();
351-
appendedParams.CopyKeyValues(existingParams);
352-
appendedParams.CopyKeyValues(s.QueryStringParameters);
338+
if (s.QueryStringParameters == null)
339+
return url;
340+
341+
var appendedParams = new NameValueCollection();
342+
var existingParams = uri.Query.ToNameValueCollection();
343+
344+
existingParams.CopyKeyValues(appendedParams);
345+
s.QueryStringParameters.CopyKeyValues(appendedParams);
353346

354-
var queryString = appendedParams.ToQueryString();
347+
var queryString = appendedParams.ToQueryString();
355348

356-
url = uri.ToUrlAndOverridePath(uri.PathAndQuery + queryString);
357-
}
349+
url = uri.ToUrlAndOverridePath(uri.PathAndQuery + queryString);
358350

359-
return url;
351+
return url;
360352
}
361353
}
362354
}

src/Nest/Domain/Connection/ConnectionSettings.cs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public string DefaultIndex
3434
public FluentDictionary<Type, string> DefaultTypeNames { get; private set; }
3535
public NameValueCollection QueryStringParameters { get; private set; }
3636

37-
public ConnectionSettings(Uri uri, NameValueCollection queryStringParamaters)
37+
public ConnectionSettings(Uri uri)
3838
{
3939
uri.ThrowIfNull("uri");
4040

@@ -51,11 +51,8 @@ public ConnectionSettings(Uri uri, NameValueCollection queryStringParamaters)
5151
this.DefaultIndices = new FluentDictionary<Type, string>();
5252
this.DefaultTypeNames = new FluentDictionary<Type, string>();
5353
this.ConnectionStatusHandler = this.ConnectionStatusDefaultHandler;
54-
this.QueryStringParameters = queryStringParamaters;
5554
}
5655

57-
public ConnectionSettings(Uri uri) : this(uri, null) { }
58-
5956
/// <summary>
6057
/// Enable Trace signals to the IConnection that it should put debug information on the Trace.
6158
/// </summary>
@@ -65,6 +62,19 @@ public ConnectionSettings EnableTrace(bool enabled = true)
6562
return this;
6663
}
6764

65+
66+
/// <summary>
67+
/// This NameValueCollection will be appended to every url NEST calls, great if you need to pass i.e an API key.
68+
/// </summary>
69+
/// <param name="queryStringParameters"></param>
70+
/// <returns></returns>
71+
public ConnectionSettings SetGlobalQueryStringParameters(NameValueCollection queryStringParameters)
72+
{
73+
this.QueryStringParameters = queryStringParameters;
74+
return this;
75+
}
76+
77+
6878
/// <summary>
6979
/// Timeout in milliseconds when the .NET webrquest should abort the request, note that you can set this to a high value here,
7080
/// and specify the timeout in various calls on Elasticsearch's side.
@@ -113,17 +123,6 @@ public ConnectionSettings SetProxy(Uri proxyAdress, string username, string pass
113123
return this;
114124
}
115125

116-
/// <summary>
117-
/// Timeout in milliseconds when the .NET webrquest should abort the request, note that you can set this to a high value here,
118-
/// and specify the timeout in various calls on Elasticsearch's side.
119-
/// </summary>
120-
/// <param name="timeout">time out in milliseconds</param>
121-
public ConnectionSettings SetTimeout(int timeout)
122-
{
123-
this.Timeout = timeout;
124-
return this;
125-
}
126-
127126
/// <summary>
128127
/// Append ?pretty=true to requests, this helps to debug send and received json.
129128
/// </summary>

src/Nest/Domain/Connection/IConnectionSettings.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ public interface IConnectionSettings
88
FluentDictionary<Type, string> DefaultIndices { get; }
99
FluentDictionary<Type, string> DefaultTypeNames { get; }
1010
string DefaultIndex { get; }
11-
11+
12+
Uri Uri { get; }
13+
int MaximumAsyncConnections { get; }
1214
string Host { get; }
1315
int Port { get; }
1416
int Timeout { get; }
@@ -20,6 +22,6 @@ public interface IConnectionSettings
2022
NameValueCollection QueryStringParameters { get; }
2123
Action<ConnectionStatus> ConnectionStatusHandler { get; }
2224

23-
Func<Type, string> DefaultTypeNameInferrer { get; }
25+
Func<Type, string> DefaultTypeNameInferrer { get; }
2426
}
2527
}

src/Nest/Extensions/NameValueCollectionExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ namespace Nest
55
{
66
public static class NameValueCollectionExtensions
77
{
8-
public static void CopyKeyValues(this NameValueCollection self, NameValueCollection source)
8+
public static void CopyKeyValues(this NameValueCollection source, NameValueCollection dest)
99
{
1010
foreach (var key in source.AllKeys)
1111
{
12-
if (self[key] != null) throw new ApplicationException(string.Format("Attempted to add duplicate key '{0}'", key));
12+
if (dest[key] != null) throw new ApplicationException(string.Format("Attempted to add duplicate key '{0}'", key));
1313

14-
self.Add(key, source[key]);
14+
dest.Add(key, source[key]);
1515
}
1616
}
1717

0 commit comments

Comments
 (0)