Beispiel #1
0
 public function testGzipSupport()
 {
     $url = 'http://localhost:8080/foo/bar?foo=a&foo=b&wowee=oh+my';
     $request = new Postman_Google_Http_Request($url);
     $request->enableGzip();
     $this->assertStringEndsWith(Postman_Google_Http_Request::GZIP_UA, $request->getUserAgent());
     $this->assertArrayHasKey('accept-encoding', $request->getRequestHeaders());
     $this->assertTrue($request->canGzip());
     $request->disableGzip();
     $this->assertStringEndsNotWith(Postman_Google_Http_Request::GZIP_UA, $request->getUserAgent());
     $this->assertArrayNotHasKey('accept-encoding', $request->getRequestHeaders());
     $this->assertFalse($request->canGzip());
 }
Beispiel #2
0
 /**
  * Send the next part of the file to upload.
  * @param [$chunk] the next set of bytes to send. If false will used $data passed
  * at construct time.
  */
 public function nextChunk($chunk = false)
 {
     if (false == $this->resumeUri) {
         $this->resumeUri = $this->getResumeUri();
     }
     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' => $this->request->getRequestHeader('content-type'), 'content-length' => $this->chunkSize, 'expect' => '');
     $httpRequest = new Postman_Google_Http_Request($this->resumeUri, 'PUT', $headers, $chunk);
     if ($this->client->getClassConfig("Postman_Google_Http_Request", "enable_gzip_for_uploads")) {
         $httpRequest->enableGzip();
     } else {
         $httpRequest->disableGzip();
     }
     $response = $this->client->getIo()->makeRequest($httpRequest);
     $response->setExpectedClass($this->request->getExpectedClass());
     $code = $response->getResponseHttpCode();
     $this->httpResultCode = $code;
     if (308 == $code) {
         // Track the amount uploaded.
         $range = explode('-', $response->getResponseHeader('range'));
         $this->progress = $range[1] + 1;
         // Allow for changing upload URLs.
         $location = $response->getResponseHeader('location');
         if ($location) {
             $this->resumeUri = $location;
         }
         // No problems, but upload not complete.
         return false;
     } else {
         return Postman_Google_Http_REST::decodeHttpResponse($response, $this->client);
     }
 }