HTTP request that sends an entity-body in the request message (POST, PUT, PATCH, DELETE)
Expanded class hierarchy of EntityEnclosingRequest
class EntityEnclosingRequest extends Request implements EntityEnclosingRequestInterface {
/**
* @var int When the size of the body is greater than 1MB, then send Expect: 100-Continue
*/
protected $expectCutoff = 1048576;
/**
* @var EntityBodyInterface $body Body of the request
*/
protected $body;
/**
* @var QueryString POST fields to use in the EntityBody
*/
protected $postFields;
/**
* @var array POST files to send with the request
*/
protected $postFiles = array();
/**
* {@inheritdoc}
*/
public function __construct($method, $url, $headers = array()) {
$this->postFields = new QueryString();
$this->postFields
->setPrefix('');
parent::__construct($method, $url, $headers);
}
/**
* Get the HTTP request as a string
*
* @return string
*/
public function __toString() {
// Only attempt to include the POST data if it's only fields
if (count($this->postFields) && empty($this->postFiles)) {
return parent::__toString() . (string) $this->postFields;
}
return parent::__toString() . $this->body;
}
/**
* {@inheritdoc}
*/
public function setState($state) {
parent::setState($state);
if ($state == self::STATE_TRANSFER && !$this->body && !count($this->postFields) && !count($this->postFiles)) {
$this
->setHeader('Content-Length', 0)
->removeHeader('Transfer-Encoding');
}
return $this;
}
/**
* {@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;
}
/**
* {@inheritdoc}
*/
public function getBody() {
return $this->body;
}
/**
* Set the size that the entity body of the request must exceed before adding the Expect: 100-Continue header.
*
* @param int|bool $size Cutoff in bytes. Set to false to never send the expect header (even with non-seekable data)
*
* @return self
*/
public function setExpectHeaderCutoff($size) {
$this->expectCutoff = $size;
if ($size === false || !$this->body) {
$this
->removeHeader('Expect');
}
elseif ($this->body && $this->body
->getSize() && $this->body
->getSize() > $size) {
$this
->setHeader('Expect', '100-Continue');
}
return $this;
}
/**
* {@inheritdoc}
*/
public function configureRedirects($strict = false, $maxRedirects = 5) {
$this
->getParams()
->set(RedirectPlugin::STRICT_REDIRECTS, $strict);
if ($maxRedirects == 0) {
$this
->getParams()
->set(RedirectPlugin::DISABLE, true);
}
else {
$this
->getParams()
->set(RedirectPlugin::MAX_REDIRECTS, $maxRedirects);
}
return $this;
}
/**
* {@inheritdoc}
*/
public function getPostField($field) {
return $this->postFields
->get($field);
}
/**
* {@inheritdoc}
*/
public function getPostFields() {
return $this->postFields;
}
/**
* {@inheritdoc}
*/
public function setPostField($key, $value) {
$this->postFields
->set($key, $value);
$this
->processPostFields();
return $this;
}
/**
* {@inheritdoc}
*/
public function addPostFields($fields) {
$this->postFields
->merge($fields);
$this
->processPostFields();
return $this;
}
/**
* {@inheritdoc}
*/
public function removePostField($field) {
$this->postFields
->remove($field);
$this
->processPostFields();
return $this;
}
/**
* {@inheritdoc}
*/
public function getPostFiles() {
return $this->postFiles;
}
/**
* {@inheritdoc}
*/
public function getPostFile($fieldName) {
return isset($this->postFiles[$fieldName]) ? $this->postFiles[$fieldName] : null;
}
/**
* {@inheritdoc}
*/
public function removePostFile($fieldName) {
unset($this->postFiles[$fieldName]);
$this
->processPostFields();
return $this;
}
/**
* {@inheritdoc}
*/
public function addPostFile($field, $filename = null, $contentType = null) {
$data = null;
if ($field instanceof PostFileInterface) {
$data = $field;
}
elseif (!is_string($filename)) {
throw new RequestException('The path to a file must be a string');
}
elseif (!empty($filename)) {
// Adding an empty file will cause cURL to error out
$data = new PostFile($field, $filename, $contentType);
}
if ($data) {
if (!isset($this->postFiles[$data
->getFieldName()])) {
$this->postFiles[$data
->getFieldName()] = array(
$data,
);
}
else {
$this->postFiles[$data
->getFieldName()][] = $data;
}
$this
->processPostFields();
}
return $this;
}
/**
* {@inheritdoc}
*/
public function addPostFiles(array $files) {
foreach ($files as $key => $file) {
if ($file instanceof PostFileInterface) {
$this
->addPostFile($file, null, null, false);
}
elseif (is_string($file)) {
// Convert non-associative array keys into 'file'
if (is_numeric($key)) {
$key = 'file';
}
$this
->addPostFile($key, $file, null, false);
}
else {
throw new RequestException('File must be a string or instance of PostFileInterface');
}
}
return $this;
}
/**
* Determine what type of request should be sent based on post fields
*/
protected function processPostFields() {
if (empty($this->postFiles)) {
$this
->removeHeader('Expect')
->setHeader('Content-Type', self::URL_ENCODED);
}
else {
$this
->setHeader('Content-Type', self::MULTIPART);
if ($this->expectCutoff !== false) {
$this
->setHeader('Expect', '100-Continue');
}
}
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AbstractMessage:: |
private | property | ||
AbstractMessage:: |
protected | property | ||
AbstractMessage:: |
protected | property | ||
AbstractMessage:: |
protected | property | ||
AbstractMessage:: |
public | function |
Add a Cache-Control directive on the message Overrides MessageInterface:: |
|
AbstractMessage:: |
public | function |
Add a header to an existing collection of headers. Overrides MessageInterface:: |
|
AbstractMessage:: |
public | function |
Add and merge in an array of HTTP headers. Overrides MessageInterface:: |
|
AbstractMessage:: |
public | function |
Get a Cache-Control directive from the message Overrides MessageInterface:: |
|
AbstractMessage:: |
public | function |
Retrieve an HTTP header by name. Performs a case-insensitive search of all headers. Overrides MessageInterface:: |
|
AbstractMessage:: |
public | function |
Get an array of message header lines Overrides MessageInterface:: |
|
AbstractMessage:: |
public | function |
Get all headers as a collection Overrides MessageInterface:: |
|
AbstractMessage:: |
public | function |
Get application and plugin specific parameters set on the message. Overrides MessageInterface:: |
|
AbstractMessage:: |
public | function |
Get a tokenized header as a Collection Overrides MessageInterface:: |
|
AbstractMessage:: |
public | function |
Check if the message has a Cache-Control directive Overrides MessageInterface:: |
|
AbstractMessage:: |
public | function |
Check if the specified header is present. Overrides MessageInterface:: |
|
AbstractMessage:: |
private | function | Parse the Cache-Control HTTP header into an array | |
AbstractMessage:: |
private | function | Rebuild the Cache-Control HTTP header using the user-specified values | |
AbstractMessage:: |
public | function |
Remove a Cache-Control directive from the message Overrides MessageInterface:: |
|
AbstractMessage:: |
public | function |
Remove a specific HTTP header. Overrides MessageInterface:: |
|
AbstractMessage:: |
public | function |
Set an HTTP header Overrides MessageInterface:: |
|
AbstractMessage:: |
public | function |
Overwrite all HTTP headers with the supplied array of headers Overrides MessageInterface:: |
|
AbstractMessage:: |
public | function |
Set a tokenized header on the request that implodes a Collection of data into a string separated by a token. Overrides MessageInterface:: |
|
EntityEnclosingRequest:: |
protected | property | ||
EntityEnclosingRequest:: |
protected | property | ||
EntityEnclosingRequest:: |
protected | property | ||
EntityEnclosingRequest:: |
protected | property | ||
EntityEnclosingRequest:: |
public | function |
Add POST fields to use in the request Overrides EntityEnclosingRequestInterface:: |
|
EntityEnclosingRequest:: |
public | function |
Add a POST file to the upload Overrides EntityEnclosingRequestInterface:: |
|
EntityEnclosingRequest:: |
public | function |
Add POST files to use in the upload Overrides EntityEnclosingRequestInterface:: |
|
EntityEnclosingRequest:: |
public | function |
Configure how redirects are handled for the request Overrides EntityEnclosingRequestInterface:: |
|
EntityEnclosingRequest:: |
public | function |
Get the body of the request if set Overrides EntityEnclosingRequestInterface:: |
|
EntityEnclosingRequest:: |
public | function |
Get a POST field from the request Overrides EntityEnclosingRequestInterface:: |
|
EntityEnclosingRequest:: |
public | function |
Get the post fields that will be used in the request Overrides EntityEnclosingRequestInterface:: |
|
EntityEnclosingRequest:: |
public | function |
Get a POST file from the request Overrides EntityEnclosingRequestInterface:: |
|
EntityEnclosingRequest:: |
public | function |
Returns an associative array of POST field names to PostFileInterface objects Overrides EntityEnclosingRequestInterface:: |
|
EntityEnclosingRequest:: |
protected | function | Determine what type of request should be sent based on post fields | |
EntityEnclosingRequest:: |
public | function |
Remove a POST field or file by name Overrides EntityEnclosingRequestInterface:: |
|
EntityEnclosingRequest:: |
public | function |
Remove a POST file from the request Overrides EntityEnclosingRequestInterface:: |
|
EntityEnclosingRequest:: |
public | function |
Set the body of the request Overrides EntityEnclosingRequestInterface:: |
|
EntityEnclosingRequest:: |
public | function | Set the size that the entity body of the request must exceed before adding the Expect: 100-Continue header. | |
EntityEnclosingRequest:: |
public | function |
Set a POST field value Overrides EntityEnclosingRequestInterface:: |
|
EntityEnclosingRequest:: |
public | function |
Set the state of the request Overrides Request:: |
|
EntityEnclosingRequest:: |
public | function |
Create a new request Overrides Request:: |
|
EntityEnclosingRequest:: |
public | function |
Get the HTTP request as a string Overrides Request:: |
|
EntityEnclosingRequestInterface:: |
constant | |||
EntityEnclosingRequestInterface:: |
constant | |||
Request:: |
protected | property | ||
Request:: |
protected | property | ||
Request:: |
protected | property | ||
Request:: |
protected | property | ||
Request:: |
protected | property | ||
Request:: |
protected | property | ||
Request:: |
protected | property | ||
Request:: |
protected | property | ||
Request:: |
protected | property | ||
Request:: |
protected | property | ||
Request:: |
public | function |
Add a Cookie value by name to the Cookie header Overrides RequestInterface:: |
|
Request:: |
public | function |
@codeCoverageIgnore Overrides HasDispatcherInterface:: |
|
Request:: |
public | function |
Returns whether or not the request can be cached Overrides RequestInterface:: |
|
Request:: |
protected | function |
Check to see if the modified headers need to reset any of the managed
headers like cache-control Overrides AbstractMessage:: |
|
Request:: |
public | function |
Helper to dispatch Guzzle events and set the event name on the event Overrides HasDispatcherInterface:: |
|
Request:: |
public static | function |
Get a list of all of the events emitted from the class Overrides HasDispatcherInterface:: |
|
Request:: |
public | function |
Get the client used to transport the request Overrides RequestInterface:: |
|
Request:: |
public | function |
Get a cookie value by name Overrides RequestInterface:: |
|
Request:: |
public | function |
Get an array of Cookies Overrides RequestInterface:: |
|
Request:: |
public | function |
Get the cURL options that will be applied when the cURL handle is created Overrides RequestInterface:: |
|
Request:: |
protected | function | Get an array containing the request and response for event notifications | |
Request:: |
public | function |
Get the EventDispatcher of the request Overrides HasDispatcherInterface:: |
|
Request:: |
public | function |
Get the host of the request Overrides RequestInterface:: |
|
Request:: |
public | function |
Get the HTTP method of the request Overrides RequestInterface:: |
|
Request:: |
public | function |
Get the password to pass in the URL if set Overrides RequestInterface:: |
|
Request:: |
public | function |
Get the path of the request (e.g. '/', '/index.html') Overrides RequestInterface:: |
|
Request:: |
public | function |
Get the port that the request will be sent on if it has been set Overrides RequestInterface:: |
|
Request:: |
public | function |
Get the HTTP protocol version of the request Overrides RequestInterface:: |
|
Request:: |
public | function |
Get the collection of key value pairs that will be used as the query
string in the request Overrides RequestInterface:: |
|
Request:: |
public | function |
Get the raw message headers as a string Overrides MessageInterface:: |
|
Request:: |
public | function |
Get the resource part of the the request, including the path, query
string, and fragment Overrides RequestInterface:: |
|
Request:: |
public | function |
Get the previously received {not been sent Overrides RequestInterface:: |
|
Request:: |
protected | function | ||
Request:: |
public | function |
Get the URI scheme of the request (http, https, ftp, etc) Overrides RequestInterface:: |
|
Request:: |
public | function |
Get the state of the request. One of 'complete', 'sending', 'new' Overrides RequestInterface:: |
|
Request:: |
public | function |
Get the full URL of the request (e.g. 'http://www.guzzle-project.com/')
scheme://username:password@domain:port/path?query_string#fragment Overrides RequestInterface:: |
|
Request:: |
public | function |
Get the username to pass in the URL if set Overrides RequestInterface:: |
|
Request:: |
public | function |
Determine if the response body is repeatable (readable + seekable) Overrides RequestInterface:: |
|
Request:: |
public static | function | Default method that will throw exceptions if an unsuccessful response is received. | |
Request:: |
protected | function | Process a received response | |
Request:: |
public | function |
Method to receive HTTP response headers as they are retrieved Overrides RequestInterface:: |
|
Request:: |
public | function |
Remove a specific cookie value by name Overrides RequestInterface:: |
|
Request:: |
public | function |
Send the request Overrides RequestInterface:: |
|
Request:: |
public | function |
Set HTTP authorization parameters Overrides RequestInterface:: |
|
Request:: |
public | function |
Set the client used to transport the request Overrides RequestInterface:: |
|
Request:: |
public | function |
Set the EventDispatcher of the request Overrides HasDispatcherInterface:: |
|
Request:: |
public | function |
Set the host of the request. Including a port in the host will modify
the port of the request. Overrides RequestInterface:: |
|
Request:: |
public | function |
Set the path of the request (e.g. '/', '/index.html') Overrides RequestInterface:: |
|
Request:: |
public | function |
Set the port that the request will be sent on Overrides RequestInterface:: |
|
Request:: |
public | function |
Set the HTTP protocol version of the request (e.g. 1.1 or 1.0) Overrides RequestInterface:: |
|
Request:: |
public | function |
Manually set a response for the request. Overrides RequestInterface:: |
|
Request:: |
public | function |
Set the EntityBody that will hold the response message's entity body. Overrides RequestInterface:: |
|
Request:: |
public | function |
Set the URI scheme of the request (http, https, ftp, etc) Overrides RequestInterface:: |
|
Request:: |
public | function |
Set the URL of the request Overrides RequestInterface:: |
|
Request:: |
public | function | Clone the request object, leaving off any response that was received | |
RequestInterface:: |
constant | |||
RequestInterface:: |
constant | |||
RequestInterface:: |
constant | |||
RequestInterface:: |
constant | |||
RequestInterface:: |
constant | |||
RequestInterface:: |
constant | |||
RequestInterface:: |
constant | |||
RequestInterface:: |
constant | |||
RequestInterface:: |
constant | |||
RequestInterface:: |
constant | |||
RequestInterface:: |
constant | |||
RequestInterface:: |
constant | |||
RequestInterface:: |
constant |