예제 #1
0
 public function parseResponse(HttpRequest $response)
 {
     $contentType = $response->getResponseHeader('content-type');
     $contentType = explode(';', $contentType);
     $boundary = false;
     foreach ($contentType as $part) {
         $part = explode('=', $part, 2);
         if (isset($part[0]) && 'boundary' == trim($part[0])) {
             $boundary = $part[1];
         }
     }
     $body = $response->getResponseBody();
     if ($body) {
         $body = str_replace("--{$boundary}--", "--{$boundary}", $body);
         $parts = explode("--{$boundary}", $body);
         $responses = array();
         foreach ($parts as $part) {
             $part = trim($part);
             if (!empty($part)) {
                 list($metaHeaders, $part) = explode("\r\n\r\n", $part, 2);
                 $metaHeaders = CurlIO::parseResponseHeaders($metaHeaders);
                 $status = substr($part, 0, strpos($part, "\n"));
                 $status = explode(" ", $status);
                 $status = $status[1];
                 list($partHeaders, $partBody) = CurlIO::parseHttpResponse($part, false);
                 $response = new HttpRequest("");
                 $response->setResponseHttpCode($status);
                 $response->setResponseHeaders($partHeaders);
                 $response->setResponseBody($partBody);
                 $response = REST::decodeHttpResponse($response);
                 // Need content id.
                 $responses[$metaHeaders['content-id']] = $response;
             }
         }
         return $responses;
     }
     return null;
 }
예제 #2
0
 public function nextChunk(HttpRequest $req)
 {
     if (false == $this->resumeUri) {
         $this->resumeUri = $this->getResumeUri($req);
     }
     $data = substr($this->data, $this->progress, $this->chunkSize);
     $lastBytePos = $this->progress + strlen($data) - 1;
     $headers = array('content-range' => "bytes {$this->progress}-{$lastBytePos}/{$this->size}", 'content-type' => $req->getRequestHeader('content-type'), 'content-length' => $this->chunkSize, 'expect' => '');
     $httpRequest = new HttpRequest($this->resumeUri, 'PUT', $headers, $data);
     $response = Client::$io->authenticatedRequest($httpRequest);
     $code = $response->getResponseHttpCode();
     if (308 == $code) {
         $range = explode('-', $response->getResponseHeader('range'));
         $this->progress = $range[1] + 1;
         return false;
     } else {
         return REST::decodeHttpResponse($response);
     }
 }