namespacing: move HTTP utilities along \Shaarli\Http\ classes
Signed-off-by: VirtualTam <virtualtam@flibidi.net>
This commit is contained in:
parent
fb1b182fbf
commit
51753e403f
16 changed files with 56 additions and 35 deletions
|
@ -41,7 +41,7 @@ function get_http_response($url, $timeout = 30, $maxBytes = 4194304, $curlWriteF
|
||||||
$cleanUrl = $urlObj->idnToAscii();
|
$cleanUrl = $urlObj->idnToAscii();
|
||||||
|
|
||||||
if (!filter_var($cleanUrl, FILTER_VALIDATE_URL) || !$urlObj->isHttp()) {
|
if (!filter_var($cleanUrl, FILTER_VALIDATE_URL) || !$urlObj->isHttp()) {
|
||||||
return array(array(0 => 'Invalid HTTP Url'), false);
|
return array(array(0 => 'Invalid HTTP UrlUtils'), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
$userAgent =
|
$userAgent =
|
|
@ -206,7 +206,7 @@ public function getHost()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if the Url is an HTTP one.
|
* Test if the UrlUtils is an HTTP one.
|
||||||
*
|
*
|
||||||
* @return true is HTTP, false otherwise.
|
* @return true is HTTP, false otherwise.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -28,7 +28,7 @@ function unparse_url($parsedUrl)
|
||||||
/**
|
/**
|
||||||
* Removes undesired query parameters and fragments
|
* Removes undesired query parameters and fragments
|
||||||
*
|
*
|
||||||
* @param string url Url to be cleaned
|
* @param string url UrlUtils to be cleaned
|
||||||
*
|
*
|
||||||
* @return string the string representation of this URL after cleanup
|
* @return string the string representation of this URL after cleanup
|
||||||
*/
|
*/
|
||||||
|
@ -41,7 +41,7 @@ function cleanup_url($url)
|
||||||
/**
|
/**
|
||||||
* Get URL scheme.
|
* Get URL scheme.
|
||||||
*
|
*
|
||||||
* @param string url Url for which the scheme is requested
|
* @param string url UrlUtils for which the scheme is requested
|
||||||
*
|
*
|
||||||
* @return mixed the URL scheme or false if none is provided.
|
* @return mixed the URL scheme or false if none is provided.
|
||||||
*/
|
*/
|
|
@ -59,16 +59,16 @@
|
||||||
require_once 'application/ApplicationUtils.php';
|
require_once 'application/ApplicationUtils.php';
|
||||||
require_once 'application/config/ConfigPlugin.php';
|
require_once 'application/config/ConfigPlugin.php';
|
||||||
require_once 'application/feed/Cache.php';
|
require_once 'application/feed/Cache.php';
|
||||||
|
require_once 'application/http/HttpUtils.php';
|
||||||
|
require_once 'application/http/UrlUtils.php';
|
||||||
require_once 'application/FileUtils.php';
|
require_once 'application/FileUtils.php';
|
||||||
require_once 'application/History.php';
|
require_once 'application/History.php';
|
||||||
require_once 'application/HttpUtils.php';
|
|
||||||
require_once 'application/LinkDB.php';
|
require_once 'application/LinkDB.php';
|
||||||
require_once 'application/LinkFilter.php';
|
require_once 'application/LinkFilter.php';
|
||||||
require_once 'application/LinkUtils.php';
|
require_once 'application/LinkUtils.php';
|
||||||
require_once 'application/NetscapeBookmarkUtils.php';
|
require_once 'application/NetscapeBookmarkUtils.php';
|
||||||
require_once 'application/PageBuilder.php';
|
require_once 'application/PageBuilder.php';
|
||||||
require_once 'application/TimeZone.php';
|
require_once 'application/TimeZone.php';
|
||||||
require_once 'application/Url.php';
|
|
||||||
require_once 'application/Utils.php';
|
require_once 'application/Utils.php';
|
||||||
require_once 'application/PluginManager.php';
|
require_once 'application/PluginManager.php';
|
||||||
require_once 'application/Router.php';
|
require_once 'application/Router.php';
|
||||||
|
|
|
@ -3,12 +3,14 @@
|
||||||
* HttpUtils' tests
|
* HttpUtils' tests
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once 'application/HttpUtils.php';
|
namespace Shaarli\Http;
|
||||||
|
|
||||||
|
require_once 'application/http/HttpUtils.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unitary tests for client_ip_id()
|
* Unitary tests for client_ip_id()
|
||||||
*/
|
*/
|
||||||
class ClientIpIdTest extends PHPUnit_Framework_TestCase
|
class ClientIpIdTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Get a remote client ID based on its IP
|
* Get a remote client ID based on its IP
|
|
@ -3,12 +3,14 @@
|
||||||
* HttpUtils' tests
|
* HttpUtils' tests
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once 'application/HttpUtils.php';
|
namespace Shaarli\Http;
|
||||||
|
|
||||||
|
require_once 'application/http/HttpUtils.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unitary tests for get_http_response()
|
* Unitary tests for get_http_response()
|
||||||
*/
|
*/
|
||||||
class GetHttpUrlTest extends PHPUnit_Framework_TestCase
|
class GetHttpUrlTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Get an invalid local URL
|
* Get an invalid local URL
|
||||||
|
@ -17,12 +19,12 @@ public function testGetInvalidLocalUrl()
|
||||||
{
|
{
|
||||||
// Local
|
// Local
|
||||||
list($headers, $content) = get_http_response('/non/existent', 1);
|
list($headers, $content) = get_http_response('/non/existent', 1);
|
||||||
$this->assertEquals('Invalid HTTP Url', $headers[0]);
|
$this->assertEquals('Invalid HTTP UrlUtils', $headers[0]);
|
||||||
$this->assertFalse($content);
|
$this->assertFalse($content);
|
||||||
|
|
||||||
// Non HTTP
|
// Non HTTP
|
||||||
list($headers, $content) = get_http_response('ftp://save.tld/mysave', 1);
|
list($headers, $content) = get_http_response('ftp://save.tld/mysave', 1);
|
||||||
$this->assertEquals('Invalid HTTP Url', $headers[0]);
|
$this->assertEquals('Invalid HTTP UrlUtils', $headers[0]);
|
||||||
$this->assertFalse($content);
|
$this->assertFalse($content);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once 'application/HttpUtils.php';
|
namespace Shaarli\Http;
|
||||||
|
|
||||||
|
require_once 'application/http/HttpUtils.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unitary tests for getIpAddressFromProxy()
|
* Unitary tests for getIpAddressFromProxy()
|
||||||
*/
|
*/
|
||||||
class GetIpAdressFromProxyTest extends PHPUnit_Framework_TestCase
|
class GetIpAdressFromProxyTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
|
@ -3,12 +3,14 @@
|
||||||
* HttpUtils' tests
|
* HttpUtils' tests
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once 'application/HttpUtils.php';
|
namespace Shaarli\Http;
|
||||||
|
|
||||||
|
require_once 'application/http/HttpUtils.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unitary tests for index_url()
|
* Unitary tests for index_url()
|
||||||
*/
|
*/
|
||||||
class IndexUrlTest extends PHPUnit_Framework_TestCase
|
class IndexUrlTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* If on the main page, remove "index.php" from the URL resource
|
* If on the main page, remove "index.php" from the URL resource
|
|
@ -1,12 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace Shaarli\Http;
|
||||||
|
|
||||||
|
require_once 'application/http/HttpUtils.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class IsHttpsTest
|
* Class IsHttpsTest
|
||||||
*
|
*
|
||||||
* Test class for is_https() function.
|
* Test class for is_https() function.
|
||||||
*/
|
*/
|
||||||
class IsHttpsTest extends PHPUnit_Framework_TestCase
|
class IsHttpsTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
|
@ -3,12 +3,14 @@
|
||||||
* HttpUtils' tests
|
* HttpUtils' tests
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once 'application/HttpUtils.php';
|
namespace Shaarli\Http;
|
||||||
|
|
||||||
|
require_once 'application/http/HttpUtils.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unitary tests for page_url()
|
* Unitary tests for page_url()
|
||||||
*/
|
*/
|
||||||
class PageUrlTest extends PHPUnit_Framework_TestCase
|
class PageUrlTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* If on the main page, remove "index.php" from the URL resource
|
* If on the main page, remove "index.php" from the URL resource
|
|
@ -3,12 +3,14 @@
|
||||||
* HttpUtils' tests
|
* HttpUtils' tests
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once 'application/HttpUtils.php';
|
namespace Shaarli\Http;
|
||||||
|
|
||||||
|
require_once 'application/http/HttpUtils.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unitary tests for server_url()
|
* Unitary tests for server_url()
|
||||||
*/
|
*/
|
||||||
class ServerUrlTest extends PHPUnit_Framework_TestCase
|
class ServerUrlTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Detect if the server uses SSL
|
* Detect if the server uses SSL
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Url's tests
|
* UrlUtils's tests
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Shaarli\Http;
|
namespace Shaarli\Http;
|
||||||
|
|
|
@ -3,9 +3,11 @@
|
||||||
* Unitary tests for cleanup_url()
|
* Unitary tests for cleanup_url()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once 'application/Url.php';
|
namespace Shaarli\Http;
|
||||||
|
|
||||||
class CleanupUrlTest extends PHPUnit_Framework_TestCase
|
require_once 'application/http/UrlUtils.php';
|
||||||
|
|
||||||
|
class CleanupUrlTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var string reference URL
|
* @var string reference URL
|
|
@ -3,12 +3,14 @@
|
||||||
* Unitary tests for get_url_scheme()
|
* Unitary tests for get_url_scheme()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once 'application/Url.php';
|
namespace Shaarli\Http;
|
||||||
|
|
||||||
class GetUrlSchemeTest extends PHPUnit_Framework_TestCase
|
require_once 'application/http/UrlUtils.php';
|
||||||
|
|
||||||
|
class GetUrlSchemeTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Get empty scheme string for empty Url
|
* Get empty scheme string for empty UrlUtils
|
||||||
*/
|
*/
|
||||||
public function testGetUrlSchemeEmpty()
|
public function testGetUrlSchemeEmpty()
|
||||||
{
|
{
|
||||||
|
@ -16,7 +18,7 @@ public function testGetUrlSchemeEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get normal scheme of Url
|
* Get normal scheme of UrlUtils
|
||||||
*/
|
*/
|
||||||
public function testGetUrlScheme()
|
public function testGetUrlScheme()
|
||||||
{
|
{
|
|
@ -1,14 +1,16 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Unpares Url's tests
|
* Unpares UrlUtils's tests
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once 'application/Url.php';
|
namespace Shaarli\Http;
|
||||||
|
|
||||||
|
require_once 'application/http/UrlUtils.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unitary tests for unparse_url()
|
* Unitary tests for unparse_url()
|
||||||
*/
|
*/
|
||||||
class UnparseUrlTest extends PHPUnit_Framework_TestCase
|
class UnparseUrlTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Thanks for building nothing
|
* Thanks for building nothing
|
|
@ -1,15 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once 'application/Url.php';
|
namespace Shaarli\Http;
|
||||||
|
|
||||||
use Shaarli\Config\ConfigManager;
|
require_once 'application/http/UrlUtils.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class WhitelistProtocolsTest
|
* Class WhitelistProtocolsTest
|
||||||
*
|
*
|
||||||
* Test whitelist_protocols() function of Url.
|
* Test whitelist_protocols() function of UrlUtils.
|
||||||
*/
|
*/
|
||||||
class WhitelistProtocolsTest extends PHPUnit_Framework_TestCase
|
class WhitelistProtocolsTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Test whitelist_protocols() on a note (relative URL).
|
* Test whitelist_protocols() on a note (relative URL).
|
Loading…
Reference in a new issue