From e5e29a24ede10ce45611451407d912312b15af9e Mon Sep 17 00:00:00 2001 From: zhangjunbin Date: Fri, 24 Jun 2016 17:00:39 +0800 Subject: [PATCH] Merge from galaxy @6f509027f78aa70e46eb1862257116802abc371c --- src/FDS/FDSClientConfiguration.php | 34 ++++++------------------ tests/FDS/FDSClientConfigurationTest.php | 30 +++++++++------------ 2 files changed, 20 insertions(+), 44 deletions(-) diff --git a/src/FDS/FDSClientConfiguration.php b/src/FDS/FDSClientConfiguration.php index e4bcbbc..531564d 100644 --- a/src/FDS/FDSClientConfiguration.php +++ b/src/FDS/FDSClientConfiguration.php @@ -12,10 +12,9 @@ class FDSClientConfiguration { const URI_HTTP_PREFIX = "http://"; const URI_HTTPS_PREFIX = "https://"; - const URI_FILES = "files"; const URI_CDN = "cdn"; - const URI_FDS_SUFFIX = ".fds.api.xiaomi.com/"; - const URI_FDS_SSL_SUFFIX = ".fds-ssl.api.xiaomi.com/"; + const URI_SUFFIX = "fds.api.xiaomi.com"; + const URI_CDN_SUFFIX = "fds.api.mi-img.com"; const DEFAULT_RETRY_NUM = 3; const DEFAULT_CONNECTION_TIMEOUT_SECS = 30; const DEFAULT_MAX_BATCH_DELETE_SIZE = 100; @@ -36,7 +35,7 @@ class FDSClientConfiguration { public function __construct() { $this->enable_https = true; - $this->region_name = ""; + $this->region_name = "cnbj0"; $this->enable_cdn_for_upload = false; $this->enable_cdn_for_download = true; $this->enable_md5_calculate = false; @@ -123,30 +122,13 @@ public function buildBaseUri($enableCdn) { } $uri = $this->enable_https ? self::URI_HTTPS_PREFIX : self::URI_HTTP_PREFIX; - $uri .= $this->getBaseUriPrefix($enableCdn, $this->region_name); - $uri .= $this->getBaseUriSuffix($enableCdn, $this->enable_https); - return $uri; - } - - private function getBaseUriPrefix($enableCdn, $regionName) { - if (empty($regionName)) { - if ($enableCdn) { - return self::URI_CDN; - } - return self::URI_FILES; + if ($enableCdn) { + $uri .= self::URI_CDN . '.' . $this->region_name . '.' . self::URI_CDN_SUFFIX; } else { - if ($enableCdn) { - return $regionName . '-' . self::URI_CDN; - } - return $regionName . '-' . self::URI_FILES; + $uri .= $this->region_name . '.' . self::URI_SUFFIX; } - } - - private function getBaseUriSuffix($enableCdn, $enableHttps) { - if ($enableCdn && $enableHttps) { - return self::URI_FDS_SSL_SUFFIX; - } - return self::URI_FDS_SUFFIX; + $uri .= '/'; + return $uri; } public function isDebugEnabled() { diff --git a/tests/FDS/FDSClientConfigurationTest.php b/tests/FDS/FDSClientConfigurationTest.php index 153f702..c06174c 100644 --- a/tests/FDS/FDSClientConfigurationTest.php +++ b/tests/FDS/FDSClientConfigurationTest.php @@ -14,8 +14,8 @@ class FDSClientConfigurationTest extends \PHPUnit_Framework_TestCase { - const URI_FDS_SUFFIX = ".fds.api.xiaomi.com/"; - const URI_FDS_SSL_SUFFIX = ".fds-ssl.api.xiaomi.com/"; + const URI_SUFFIX = "fds.api.xiaomi.com"; + const URI_CDN_SUFFIX = "fds.api.mi-img.com"; public function testDefaultConfigurationValue() { $fds_config = new FDSClientConfiguration(); @@ -30,29 +30,29 @@ public function testDefaultConfigurationValue() { public function testCdnChosen() { $fdsConfig = new FDSClientConfiguration(); - $fdsConfig->setRegionName(""); + $fdsConfig->setRegionName("regionName"); $fdsConfig->enableHttps(true); // Test flag enableCdnForUpload $fdsConfig->enableCdnForUpload(false); - $this->assertEquals("https://files" . self::URI_FDS_SUFFIX, + $this->assertEquals("https://regionName." . self::URI_SUFFIX . '/', $fdsConfig->getUploadBaseUri()); $fdsConfig->enableCdnForUpload(true); - $this->assertEquals("https://cdn" . self::URI_FDS_SSL_SUFFIX, + $this->assertEquals("https://cdn.regionName." . self::URI_CDN_SUFFIX . '/', $fdsConfig->getUploadBaseUri()); $fdsConfig->enableHttps(false); - $this->assertEquals("http://cdn" . self::URI_FDS_SUFFIX, + $this->assertEquals("http://cdn.regionName." . self::URI_CDN_SUFFIX . '/', $fdsConfig->getUploadBaseUri()); // Test flag enableCdnForDownload $fdsConfig->enableCdnForDownload(false); - $this->assertEquals("http://files" . self::URI_FDS_SUFFIX, + $this->assertEquals("http://regionName." . self::URI_SUFFIX . '/', $fdsConfig->getDownloadBaseUri()); $fdsConfig->enableCdnForDownload(true); - $this->assertEquals("http://cdn" . self::URI_FDS_SUFFIX, + $this->assertEquals("http://cdn.regionName." . self::URI_CDN_SUFFIX . '/', $fdsConfig->getDownloadBaseUri()); $fdsConfig->enableHttps(true); - $this->assertEquals("https://cdn" . self::URI_FDS_SSL_SUFFIX, + $this->assertEquals("https://cdn.regionName." . self::URI_CDN_SUFFIX . '/', $fdsConfig->getDownloadBaseUri()); } @@ -62,18 +62,12 @@ public function testBuildBaseUri() { $fds_config = new FDSClientConfiguration(); // Test against flag enable https. - $fds_config->setRegionName(""); + $fds_config->setRegionName($region_name); $fds_config->enableHttps(true); - $this->assertEquals("https://files" . self::URI_FDS_SUFFIX, + $this->assertEquals("https://" . $region_name . '.' . self::URI_SUFFIX . '/', $fds_config->buildBaseUri(false)); $fds_config->enableHttps(false); - $this->assertEquals("http://files" . self::URI_FDS_SUFFIX, + $this->assertEquals("http://" . $region_name . '.' . self::URI_SUFFIX . '/', $fds_config->buildBaseUri(false)); - - // Test against region name. - $fds_config->setRegionName($region_name); - $fds_config->enableHttps(true); - $this->assertEquals("https://" . $region_name . "-cdn" . - self::URI_FDS_SSL_SUFFIX , $fds_config->buildBaseUri(true)); } } \ No newline at end of file