Commit 8bae9415 authored by Tobias Liebig's avatar Tobias Liebig Committed by Bas de Nooijer

Support HTTPS Solr server

Fixes: #267
parent bd1df690
......@@ -54,6 +54,7 @@ class Endpoint extends Configurable
* @var array
*/
protected $options = array(
'scheme' => 'http',
'host' => '127.0.0.1',
'port' => 8983,
'path' => '/solr',
......@@ -210,6 +211,27 @@ class Endpoint extends Configurable
return $this->getOption('timeout');
}
/**
* Set scheme option
*
* @param string $scheme
* @return self Provides fluent interface
*/
public function setScheme($scheme)
{
return $this->setOption('scheme', $scheme);
}
/**
* Get scheme option
*
* @return string
*/
public function getScheme()
{
return $this->getOption('scheme');
}
/**
* Get the base url for all requests
*
......@@ -219,7 +241,7 @@ class Endpoint extends Configurable
*/
public function getBaseUri()
{
$uri = 'http://' . $this->getHost() . ':' . $this->getPort() . $this->getPath() . '/';
$uri = $this->getScheme() . '://' . $this->getHost() . ':' . $this->getPort() . $this->getPath() . '/';
$core = $this->getCore();
if (!empty($core)) {
......
......@@ -48,6 +48,7 @@ class EndpointTest extends \PHPUnit_Framework_TestCase
public function testConfigMode()
{
$options = array(
'scheme' => 'http',
'host' => '192.168.0.1',
'port' => 123,
'path' => '/mysolr/',
......@@ -99,6 +100,12 @@ class EndpointTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(7, $this->endpoint->getTimeout());
}
public function testSetAndGetScheme()
{
$this->endpoint->setScheme('https');
$this->assertEquals('https', $this->endpoint->getScheme());
}
public function testGetBaseUri()
{
$this->endpoint->setHost('myserver')->setPath('/mypath')->setPort(123);
......@@ -106,6 +113,13 @@ class EndpointTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('http://myserver:123/mypath/', $this->endpoint->getBaseUri());
}
public function testGetBaseUriWithHttps()
{
$this->endpoint->setScheme('https')->setHost('myserver')->setPath('/mypath')->setPort(123);
$this->assertEquals('https://myserver:123/mypath/', $this->endpoint->getBaseUri());
}
public function testGetBaseUriWithCore()
{
$this->endpoint->setHost('myserver')->setPath('/mypath')->setPort(123)->setCore('mycore');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment