Skip to content

Commit

Permalink
Merge from galaxy @6f509027f78aa70e46eb1862257116802abc371c
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangjunbin committed Jun 24, 2016
1 parent 84d4f9f commit e5e29a2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 44 deletions.
34 changes: 8 additions & 26 deletions src/FDS/FDSClientConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
30 changes: 12 additions & 18 deletions tests/FDS/FDSClientConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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());
}

Expand All @@ -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));
}
}

0 comments on commit e5e29a2

Please sign in to comment.