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