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; }
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()); }