Permalink
Browse files

NCBC-1305: Make bootstrap url default to port 8091

Motivation
----------
If no port is provided, the System.Uri class will default to port 80. To
bootstrap, Couchbase expects port 8091, so we we need to ensure that the
default is port 8091 instead of port 80.

Modifications
-------------
Check for port 80 when ClientConfiguration.Initialize is called and
rewrite the uri to use port 8091.

Results
-------
If no port is provided in the Uri, the sdk will default it to port 8091
instead of port 80.

Change-Id: Iaec736d79388a76ca6f5f7f8cfb8de2d766e1d4c
Reviewed-on: http://review.couchbase.org/73869
Reviewed-by: Mike Goldsmith <goldsmith.mike@gmail.com>
Tested-by: Jeffry Morris <jeffrymorris@gmail.com>
  • Loading branch information...
jeffrymorris committed Feb 18, 2017
1 parent 3c49518 commit 0071f631208fc92ff43ab7a756b63511e4859c3f
@@ -211,6 +211,25 @@ public void When_Defaults_Are_Used_IOServiceFactory_Returns_MultiplexingIOServic
Assert.IsInstanceOf<MultiplexingIOService>(service);
}
[TestCase("http://localhost:80/pools")]
[TestCase("http://localhost/")]
[TestCase("http://localhost")]
[TestCase("http://localhost:8091/")]
[TestCase("http://localhost:8091/pools/")]
[TestCase("http://localhost:8091")]
public void Test_UriValidation(string uriToTest)
{
var config = new ClientConfiguration
{
Servers = new List<Uri>
{
new Uri(uriToTest)
}
};
config.Initialize();
Assert.AreEqual("http://localhost:8091/pools", config.Servers.First().ToString());
}
#if NET45
[Test]
@@ -924,16 +924,14 @@ internal void Initialize()
{
for (var i = 0; i < _servers.Count(); i++)
{
if (_servers[i].OriginalString.EndsWith("/pools"))
if (!_servers[i].OriginalString.EndsWith("/pools") || _servers[i].Port == 80)
{
/*noop*/
}
else
{
var value = _servers[i].ToString();
value = string.Concat(value, value.EndsWith("/") ? "pools" : "/pools");
var uri = new Uri(value);
_servers[i] = uri;
var builder = new UriBuilder(_servers[i])
{
Port = _servers[i].Port == 80 ? 8091 : _servers[i].Port,
Path = _servers[i].OriginalString.EndsWith("/") ? "pools" : "/pools"
};
_servers[i] = builder.Uri;
}
}
}

0 comments on commit 0071f63

Please sign in to comment.