Пример #1
0
 private function shouldRetry(HttpRequest $request, \Exception $ex, $retries)
 {
     if ($retries > $this->maxErrotRetry) {
         return false;
     }
     if (!$request->seekable()) {
         return false;
     }
     return false;
 }
Пример #2
0
 public function sendRequest(HttpRequest $request, ExecutionContext $context)
 {
     $request->addHeader(HttpHeaders::USER_AGENT, $this->userAgent);
     $context->getSigner()->sign($request, $context->getCredentials());
     $response = $this->client->sendRequest($request, $context);
     foreach ($context->getResponseHandlers() as $handler) {
         $handler->handle($response);
     }
     return $response;
 }
Пример #3
0
 protected function buildCoreRequest(HttpRequest $request)
 {
     $headers = $request->getHeaders();
     $contentLength = 0;
     if (!$request->isParameterInUrl()) {
         $body = $request->getParameterString();
         $contentLength = strlen($body);
     } else {
         $body = $request->getContent();
         if ($body !== null) {
             AssertUtils::assertSet(HttpHeaders::CONTENT_LENGTH, $headers);
             $contentLength = (int) $headers[HttpHeaders::CONTENT_LENGTH];
         }
     }
     $entity = null;
     $headers[HttpHeaders::CONTENT_LENGTH] = (string) $contentLength;
     if ($body !== null) {
         $entity = new ReadLimitEntityBody(EntityBody::factory($body), $contentLength, $request->getOffset() !== false ? $request->getOffset() : 0);
     }
     $coreRequest = $this->client->createRequest($request->getMethod(), $request->getFullUrl(), $headers, $entity);
     if ($request->getResponseBody() != null) {
         $coreRequest->setResponseBody($request->getResponseBody());
     }
     return $coreRequest;
 }
Пример #4
0
 public static function buildCanonicalString(HttpRequest $request, $bucket, $objectKey)
 {
     $buildString = $request->getMethod() . self::$NEW_LINE;
     $headersToSign = array();
     foreach ($request->getHeaders() as $key => $value) {
         if (empty($key)) {
             continue;
         }
         $lowerKey = strtolower($key);
         if ($lowerKey == strtolower(OSSHeaders::CONTENT_TYPE) || $lowerKey == strtolower(OSSHeaders::CONTENT_MD5) || $lowerKey == strtolower(OSSHeaders::DATE) || strpos($lowerKey, OSSHeaders::OSS_PREFIX) === 0) {
             $headersToSign[$lowerKey] = $value;
         }
     }
     if (!isset($headersToSign[strtolower(OSSHeaders::CONTENT_TYPE)])) {
         $headersToSign[strtolower(OSSHeaders::CONTENT_TYPE)] = '';
     }
     if (!isset($headersToSign[strtolower(OSSHeaders::CONTENT_MD5)])) {
         $headersToSign[strtolower(OSSHeaders::CONTENT_MD5)] = '';
     }
     // Add querys that have the prefix "x-oss-"
     foreach ($request->getParameters() as $key => $value) {
         if (strpos($key, OSSHeaders::OSS_PREFIX) === 0) {
             $headersToSign[$key] = $value;
         }
     }
     // Sort
     ksort($headersToSign);
     // Add all headers to sign to the builder
     foreach ($headersToSign as $key => $value) {
         if (strpos($key, OSSHeaders::OSS_PREFIX) === 0) {
             $buildString = $buildString . $key . ':' . $value;
         } else {
             $buildString .= $value;
         }
         $buildString .= self::$NEW_LINE;
     }
     return $buildString . self::buildCanonicalizedResource(self::buildResourcePath($bucket, $objectKey), $request->getParameters());
 }
Пример #5
0
 public function build()
 {
     AssertUtils::assertString($this->endpoint, 'endpoint');
     // sent request
     $request = new HttpRequest();
     $request->setEndpoint(OSSUtils::buildEndpoint($this->endpoint, $this->bucket));
     if (isset($this->method)) {
         $request->setMethod($this->method);
     }
     $headers = $this->headers;
     // Date
     if (!isset($headers[OSSHeaders::DATE])) {
         $headers[OSSHeaders::DATE] = DateUtils::formatDate(new \DateTime());
     }
     // Content-Type
     if (!isset($headers[OSSHeaders::CONTENT_TYPE])) {
         $headers[OSSHeaders::CONTENT_TYPE] = '';
     }
     if (!isset($headers[OSSHeaders::CONTENT_LENGTH]) && is_string($this->content)) {
         $headers[OSSHeaders::CONTENT_LENGTH] = (string) strlen($this->content);
     }
     foreach ($headers as $key => $value) {
         $request->addHeader($key, $value);
     }
     $parameters = $this->parameters;
     foreach ($parameters as $key => $value) {
         $request->addParameter($key, $value);
     }
     $request->setResourcePath(OSSUtils::buildResourcePath($this->key));
     $request->setContent($this->content);
     $request->setResponseBody($this->responseBody);
     return $request;
 }