Skip to content

Commit

Permalink
source code copied from azure-storage-php for v1.5.0-common release
Browse files Browse the repository at this point in the history
  • Loading branch information
vinjiang committed Aug 28, 2020
1 parent be4df80 commit fe85677
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 20 deletions.
10 changes: 10 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
2020.08 - version 1.5.0
* Resolved TLS 1.2 issue and some test issues.
* Check $uri null type before array/string access.
* Accept DateTimeImmutable as EdmType input.
* Added client-request-id to requests.
* Updated getContinuationToken return type.
* Call static methods using `static::` not `self::`.
* Added $isSecondary parameter for appendBlobRetryDecider.
* Retry on no response from server after a successful connection

2020.01 - version 1.4.1
* Changed to perform override existence instead of value check for ‘$options[‘verify’]’ in ‘ServiceRestProxy’.

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "microsoft/azure-storage-common",
"version": "1.4.1",
"version": "1.5.0",
"description": "This project provides a set of common code shared by Azure Storage Blob, Table, Queue and File PHP client libraries.",
"keywords": [ "php", "azure", "storage", "sdk", "common" ],
"license": "MIT",
Expand Down
4 changes: 3 additions & 1 deletion src/Common/Internal/Http/HttpCallContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,9 @@ public function __toString()
$headers = Resources::EMPTY_STRING;
$uri = $this->_uri;

if ($uri[strlen($uri)-1] != '/') {
if ($uri === null) {
$uri = '/';
} elseif ($uri[strlen($uri)-1] != '/') {
$uri = $uri.'/';
}

Expand Down
6 changes: 3 additions & 3 deletions src/Common/Internal/Middlewares/CommonRequestMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ protected function onRequest(RequestInterface $request)
$date = gmdate(Resources::AZURE_DATE_FORMAT, time());
$result = $result->withHeader(Resources::DATE, $date);

//Adding request-ID if not specified by the user.
if (!$result->hasHeader(Resources::X_MS_REQUEST_ID)) {
$result = $result->withHeader(Resources::X_MS_REQUEST_ID, \uniqid());
//Adding client request-ID if not specified by the user.
if (!$result->hasHeader(Resources::X_MS_CLIENT_REQUEST_ID)) {
$result = $result->withHeader(Resources::X_MS_CLIENT_REQUEST_ID, \uniqid());
}
//Sign the request if authentication scheme is not null.
$request = $this->authenticationScheme == null ?
Expand Down
8 changes: 6 additions & 2 deletions src/Common/Internal/Resources.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ class Resources
const X_MS_CONTINUATION_NEXTPARTITIONKEY = 'x-ms-continuation-nextpartitionkey';
const X_MS_CONTINUATION_NEXTROWKEY = 'x-ms-continuation-nextrowkey';
const X_MS_REQUEST_ID = 'x-ms-request-id';
const X_MS_CLIENT_REQUEST_ID = 'x-ms-client-request-id';
const X_MS_CONTINUATION_LOCATION_MODE = 'x-ms-continuation-location-mode';
const X_MS_TYPE = 'x-ms-type';
const X_MS_CONTENT_LENGTH = 'x-ms-content-length';
Expand Down Expand Up @@ -239,16 +240,19 @@ class Resources
const BEARER = 'Bearer ';

// Header values
const COMMON_SDK_VERSION = '1.4.1';
const COMMON_SDK_VERSION = '1.5.0';
const INT32_MAX = 2147483647;
const INT32_MIN = -2147483648;

// Query parameter names
const QP_ENTRIES = 'Entries';
const QP_PREFIX = 'Prefix';
const QP_PREFIX_LOWERCASE = 'prefix';
const QP_MAX_RESULTS = 'MaxResults';
const QP_METADATA = 'Metadata';
const QP_MAX_RESULTS_LOWERCASE = 'maxresults';
const QP_MARKER = 'Marker';
const QP_MARKER_LOWERCASE = 'marker';
const QP_METADATA = 'Metadata';
const QP_NEXT_MARKER = 'NextMarker';
const QP_COMP = 'comp';
const QP_INCLUDE = 'include';
Expand Down
5 changes: 5 additions & 0 deletions src/Common/Internal/ServiceRestProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ private static function createClient(array $options)
"allow_redirects" => true,
"exceptions" => true,
"decode_content" => true,
"config" => [
"curl" => [
CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1_2
]
]
),
'cookies' => true,
'verify' => $verify,
Expand Down
6 changes: 3 additions & 3 deletions src/Common/Internal/Validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public static function isTrue($isSatisfied, $failureMessage)
}

/**
* Throws exception if the provided $date is not of type \DateTime
* Throws exception if the provided $date doesn't implement \DateTimeInterface
*
* @param mixed $date variable to check against.
*
Expand All @@ -190,8 +190,8 @@ public static function isTrue($isSatisfied, $failureMessage)
*/
public static function isDate($date)
{
if (gettype($date) != 'object' || get_class($date) != 'DateTime') {
throw new InvalidArgumentTypeException('DateTime');
if (gettype($date) != 'object' || !($date instanceof \DateTimeInterface)) {
throw new InvalidArgumentTypeException('DateTimeInterface');
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Common/MarkerContinuationTokenTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function setMarker($marker)
/**
* Getter for continuationToken
*
* @return ContinuationToken
* @return MarkerContinuationToken
*/
public function getContinuationToken()
{
Expand Down
23 changes: 14 additions & 9 deletions src/Common/Middlewares/RetryMiddlewareFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ public static function create(
//accumulation method.
$intervalCalculator =
$accumulationMethod == self::LINEAR_INTERVAL_ACCUMULATION ?
self::createLinearDelayCalculator($interval) :
self::createExponentialDelayCalculator($interval);
static::createLinearDelayCalculator($interval) :
static::createExponentialDelayCalculator($interval);

//Get the retry decider according to the type of the retry and
//the number of retries.
$retryDecider = self::createRetryDecider($type, $numberOfRetries, $retryConnect);
$retryDecider = static::createRetryDecider($type, $numberOfRetries, $retryConnect);

//construct the retry middle ware.
return new RetryMiddleware($intervalCalculator, $retryDecider);
Expand Down Expand Up @@ -171,16 +171,19 @@ protected static function createRetryDecider($type, $maxRetries, $retryConnect)
return $retryConnect;
} else {
$response = $exception->getResponse();
if (!$response) {
return true;
}
}
}

if ($type == self::GENERAL_RETRY_TYPE) {
return self::generalRetryDecider(
return static::generalRetryDecider(
$response->getStatusCode(),
$isSecondary
);
} else {
return self::appendBlobRetryDecider(
return static::appendBlobRetryDecider(
$response->getStatusCode(),
$isSecondary
);
Expand All @@ -193,7 +196,8 @@ protected static function createRetryDecider($type, $maxRetries, $retryConnect)
/**
* Decide if the given status code indicate the request should be retried.
*
* @param int $statusCode status code of the previous request.
* @param int $statusCode Status code of the previous request.
* @param bool $isSecondary Whether the request is sent to secondary endpoint.
*
* @return bool true if the request should be retried.
*/
Expand All @@ -216,19 +220,20 @@ protected static function generalRetryDecider($statusCode, $isSecondary)
* Decide if the given status code indicate the request should be retried.
* This is for append blob.
*
* @param int $statusCode status code of the previous request.
* @param int $statusCode Status code of the previous request.
* @param bool $isSecondary Whether the request is sent to secondary endpoint.
*
* @return bool true if the request should be retried.
*/
protected static function appendBlobRetryDecider($statusCode)
protected static function appendBlobRetryDecider($statusCode, $isSecondary)
{
//The retry logic is different for append blob.
//First it will need to record the former status code if it is
//server error. Then if the following request is 412 then it
//needs to be retried. Currently this is not implemented so will
//only adapt to the general retry decider.
//TODO: add logic for append blob's retry when implemented.
$retry = self::generalRetryDecider($statusCode);
$retry = static::generalRetryDecider($statusCode, $isSecondary);
return $retry;
}

Expand Down

0 comments on commit fe85677

Please sign in to comment.