public function prepare() { /* Any HTTP/1.1 message containing an entity-body SHOULD include a Content-Type header field defining the media type of that body. http://www.w3.org/Protocols/rfc2616/rfc2616-sec7.html#sec7.2.1 */ // Must be a multipart request if ($this->files->all()) { $boundary = self::generateBoundary(); $this->prepared_body = Request::buildPostBody($this->post->all(), $this->files->all(), $boundary); $this->headers->set('content-type', 'multipart/form-data; boundary=' . $boundary); } else { if ($this->post->all()) { $this->prepared_body = http_build_query($this->post->all()); $this->headers->set('content-type', 'application/x-www-form-urlencoded'); } else { $this->headers->set('content-type', $this->detectContentType($this->body)); $this->prepared_body = $this->body; } } /* The transfer-length of a message is the length of the message-body as it appears in the message; that is, after any transfer-codings have been applied. http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.4 */ $len = strlen($this->prepared_body); if ($len > 0) { $this->headers->set('content-length', $len); } else { $this->headers->remove('content-length'); $this->headers->remove('content-type'); } }