/** * Constructs a new http client response instance this is normally done by the HTTP client. * * @param MOXMAN_Http_HttpClient $client HTTP client instance to connect to request. * @param MOXMAN_Http_HttpClientRequest $req HTTP client request instance for the specified response. */ public function __construct(MOXMAN_Http_HttpClient $client, MOXMAN_Http_HttpClientRequest $req, $contentLength = 0, $stream = null) { $this->client = $client; $this->req = $req; $this->stream = $stream; $this->bufferSize = $client->getBufferSize(); $this->chunkLength = 0; $this->contentIndex = 0; $this->readHead(); $this->transferEncoding = strtolower($this->getHeader("transfer-encoding", "")); $this->contentEncoding = strtolower($this->getHeader("content-encoding", "")); $this->contentLength = $contentLength ? $contentLength : $this->getHeader("content-length", 0); $this->chunkedContentLength = $this->contentLength; $method = $req->getMethod(); $code = $this->getCode(); // These requests doesn't have a body if ($method == "head" || $code == 204 || $code == 304 || $method == "connect" && $code >= 200 && $code < 300) { $this->isEmptyBody = true; } }
/** * signRequest * * @param MOXMAN_Http_HttpClientRequest $request Request from HttpClient to sign. * @return MOXMAN_Http_HttpClientRequest HttpClient Request returned with right headers signed. */ private function signRequest(MOXMAN_Http_HttpClientRequest $request) { $request->setHeader("x-ms-date", gmdate('D, d M Y H:i:s T', time())); $request->setHeader("x-ms-version", "2015-02-21"); $stringToSign = $this->getStringToString($request); $hash = hash_hmac("sha256", $stringToSign, base64_decode($this->getContainerOption("sharedkey")), true); $request->setHeader("Authorization", "SharedKey " . $this->getContainerOption("account") . ":" . base64_encode($hash)); return $request; }
/** * signRequest * * @param MOXMAN_Http_HttpClientRequest $request Request from HttpClient to sign. * @return MOXMAN_Http_HttpClientRequest HttpClient Request returned with right headers signed. */ private function signRequest(MOXMAN_Http_HttpClientRequest $request) { $signData = array("Content-Encoding", "Content-Language", "Content-Length", "Content-MD5", "Content-Type", "Date", "If-Modified-Since", "If-Match", "If-None-Match", "If-Unmodified-Since", "Range"); $signed = strtoupper($request->getMethod()) . "\n"; foreach ($signData as $name) { $signed .= $request->getHeader($name) . "\n"; } $request->setHeader("x-ms-date", gmdate('D, d M Y H:i:s T', time())); $request->setHeader("x-ms-version", "2009-09-19"); foreach ($request->getHeaders() as $name => $val) { if (strpos($name, "x-ms-") === 0) { $signed .= $name . ":" . $val . "\n"; } } $url = $request->getUrl(); $signed .= "/" . $this->getContainerOption("account") . $url["path"]; if (isset($url["query"])) { $queryParts = array(); parse_str($url["query"], $queryParts); $keys = array_keys($queryParts); sort($keys); foreach ($keys as $key) { $signed .= "\n" . $key . ":" . $queryParts[$key]; } } $hash = hash_hmac("sha256", $signed, base64_decode($this->getContainerOption("sharedkey")), true); $signature = base64_encode($hash); $request->setHeader("Authorization", "SharedKey " . $this->getContainerOption("account") . ":" . $signature); return $request; }
public function sendRawRequest(MOXMAN_Http_HttpClientRequest $request, $payloadHash = "") { $date = $this->getCurrentUtcDate(); // Generate default payload hash if (!$payloadHash) { $payloadHash = $this->hash(""); } $request->setHeader("X-Amz-Content-SHA256", $payloadHash); $request->setHeader("X-Amz-Date", $date->format("Ymd\\THis\\Z")); $canonicalRequest = $this->getCanonicalRequest($request, $payloadHash); $stringToSign = $this->getStringToSign($canonicalRequest, $date); $signature = $this->getSignature($stringToSign, $date); $request->setHeader("Authorization", $this->getAuthorization($request, $date, $signature)); return $request->send(); }