public function parseResponse(Google_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 = Google_CurlIO::parseResponseHeaders($metaHeaders);
                 $status = substr($part, 0, strpos($part, "\n"));
                 $status = explode(" ", $status);
                 $status = $status[1];
                 list($partHeaders, $partBody) = Google_CurlIO::parseHttpResponse($part, false);
                 $response = new Google_HttpRequest("");
                 $response->setResponseHttpCode($status);
                 $response->setResponseHeaders($partHeaders);
                 $response->setResponseBody($partBody);
                 $response = Google_REST::decodeHttpResponse($response);
                 // Need content id.
                 $responses[$metaHeaders['content-id']] = $response;
             }
         }
         return $responses;
     }
     return null;
 }
 public function nextChunk(Google_HttpRequest $req, $chunk = false)
 {
     if (false == $this->resumeUri) {
         $this->resumeUri = $this->getResumeUri($req);
     }
     if (false == $chunk) {
         $chunk = substr($this->data, $this->progress, $this->chunkSize);
     }
     $lastBytePos = $this->progress + strlen($chunk) - 1;
     $headers = array('content-range' => "bytes {$this->progress}-{$lastBytePos}/{$this->size}", 'content-type' => $req->getRequestHeader('content-type'), 'content-length' => $this->chunkSize, 'expect' => '');
     $httpRequest = new Google_HttpRequest($this->resumeUri, 'PUT', $headers, $chunk);
     $response = Google_Client::$io->authenticatedRequest($httpRequest);
     $code = $response->getResponseHttpCode();
     if (308 == $code) {
         $range = explode('-', $response->getResponseHeader('range'));
         $this->progress = $range[1] + 1;
         return false;
     } else {
         return Google_REST::decodeHttpResponse($response);
     }
 }