/**
  * {@inheritdoc}
  */
 public function setBody($body, $contentType = null, $tryChunkedTransfer = false)
 {
     $this->body = EntityBody::factory($body);
     $this->removeHeader('Content-Length');
     if ($contentType) {
         $this->setHeader('Content-Type', (string) $contentType);
     }
     // Always add the Expect 100-Continue header if the body cannot be rewound. This helps with redirects.
     if (!$this->body->isSeekable() && $this->expectCutoff !== false) {
         $this->setHeader('Expect', '100-Continue');
     }
     if ($tryChunkedTransfer) {
         $this->setHeader('Transfer-Encoding', 'chunked');
     } else {
         $this->removeHeader('Transfer-Encoding');
         // Set the Content-Length header if it can be determined
         $size = $this->body->getContentLength();
         if ($size !== null && $size !== false) {
             $this->setHeader('Content-Length', $size);
             if ($size > $this->expectCutoff) {
                 $this->setHeader('Expect', '100-Continue');
             }
         } elseif ('1.1' == $this->protocolVersion) {
             $this->setHeader('Transfer-Encoding', 'chunked');
         } else {
             throw new RequestException('Cannot determine Content-Length and cannot use chunked Transfer-Encoding when using HTTP/1.0');
         }
     }
     return $this;
 }
 public function setBody($body, $contentType = null)
 {
     $this->body = EntityBody::factory($body);
     // Auto detect the Content-Type from the path of the request if possible
     if ($contentType === null && !$this->hasHeader('Content-Type')) {
         $contentType = $this->body->getContentType() ?: Mimetypes::getInstance()->fromFilename($this->getPath());
     }
     if ($contentType) {
         $this->setHeader('Content-Type', $contentType);
     }
     // Always add the Expect 100-Continue header if the body cannot be rewound. This helps with redirects.
     if (!$this->body->isSeekable() && $this->expectCutoff !== false) {
         $this->setHeader('Expect', '100-Continue');
     }
     // Set the Content-Length header if it can be determined
     $size = $this->body->getContentLength();
     if ($size !== null && $size !== false) {
         $this->setHeader('Content-Length', $size);
         if ($size > $this->expectCutoff) {
             $this->setHeader('Expect', '100-Continue');
         }
     } elseif (!$this->hasHeader('Content-Length')) {
         if ('1.1' == $this->protocolVersion) {
             $this->setHeader('Transfer-Encoding', 'chunked');
         } else {
             throw new RequestException('Cannot determine Content-Length and cannot use chunked Transfer-Encoding when using HTTP/1.0');
         }
     }
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function setBody($body, $contentType = null, $tryChunkedTransfer = false)
 {
     $this->body = EntityBody::factory($body);
     $this->removeHeader('Content-Length');
     $this->setHeader('Expect', '100-Continue');
     if ($contentType) {
         $this->setHeader('Content-Type', (string) $contentType);
     }
     if ($tryChunkedTransfer) {
         $this->setHeader('Transfer-Encoding', 'chunked');
     } else {
         $this->removeHeader('Transfer-Encoding');
         // Set the Content-Length header if it can be determined
         $size = $this->body->getContentLength();
         if ($size !== null && $size !== false) {
             $this->setHeader('Content-Length', $size);
         } elseif ('1.1' == $this->protocolVersion) {
             $this->setHeader('Transfer-Encoding', 'chunked');
         } else {
             throw new RequestException('Cannot determine Content-Length and cannot use chunked Transfer-Encoding when using HTTP/1.0');
         }
     }
     return $this;
 }