diff --git a/ChangeLog.md b/ChangeLog.md index 5a0254d..bc914f8 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -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’. diff --git a/composer.json b/composer.json index a924baa..a621560 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/src/Common/Internal/Http/HttpCallContext.php b/src/Common/Internal/Http/HttpCallContext.php index e0805ad..31eba33 100644 --- a/src/Common/Internal/Http/HttpCallContext.php +++ b/src/Common/Internal/Http/HttpCallContext.php @@ -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.'/'; } diff --git a/src/Common/Internal/Middlewares/CommonRequestMiddleware.php b/src/Common/Internal/Middlewares/CommonRequestMiddleware.php index 6d7e597..4da9ba0 100644 --- a/src/Common/Internal/Middlewares/CommonRequestMiddleware.php +++ b/src/Common/Internal/Middlewares/CommonRequestMiddleware.php @@ -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 ? diff --git a/src/Common/Internal/Resources.php b/src/Common/Internal/Resources.php index 973fa46..8e49c4f 100644 --- a/src/Common/Internal/Resources.php +++ b/src/Common/Internal/Resources.php @@ -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'; @@ -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'; diff --git a/src/Common/Internal/ServiceRestProxy.php b/src/Common/Internal/ServiceRestProxy.php index ee560fb..008dc0d 100644 --- a/src/Common/Internal/ServiceRestProxy.php +++ b/src/Common/Internal/ServiceRestProxy.php @@ -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, diff --git a/src/Common/Internal/Validate.php b/src/Common/Internal/Validate.php index 4517e7d..1d29268 100644 --- a/src/Common/Internal/Validate.php +++ b/src/Common/Internal/Validate.php @@ -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. * @@ -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'); } } diff --git a/src/Common/MarkerContinuationTokenTrait.php b/src/Common/MarkerContinuationTokenTrait.php index 7ef5308..4532c46 100644 --- a/src/Common/MarkerContinuationTokenTrait.php +++ b/src/Common/MarkerContinuationTokenTrait.php @@ -63,7 +63,7 @@ public function setMarker($marker) /** * Getter for continuationToken * - * @return ContinuationToken + * @return MarkerContinuationToken */ public function getContinuationToken() { diff --git a/src/Common/Middlewares/RetryMiddlewareFactory.php b/src/Common/Middlewares/RetryMiddlewareFactory.php index ca841e7..f024ef7 100644 --- a/src/Common/Middlewares/RetryMiddlewareFactory.php +++ b/src/Common/Middlewares/RetryMiddlewareFactory.php @@ -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); @@ -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 ); @@ -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. */ @@ -216,11 +220,12 @@ 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 @@ -228,7 +233,7 @@ protected static function appendBlobRetryDecider($statusCode) //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; }