Open Journal Systems  3.3.0
Request/BodyVisitor.php
1 <?php
2 
4 
11 
20 {
21  public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
22  {
23  $value = $param->filter($value);
24  $entityBody = EntityBody::factory($value);
25  $request->setBody($entityBody);
26  $this->addExpectHeader($request, $entityBody, $param->getData('expect_header'));
27  // Add the Content-Encoding header if one is set on the EntityBody
28  if ($encoding = $entityBody->getContentEncoding()) {
29  $request->setHeader('Content-Encoding', $encoding);
30  }
31  }
32 
40  protected function addExpectHeader(EntityEnclosingRequestInterface $request, EntityBodyInterface $body, $expect)
41  {
42  // Allow the `expect` data parameter to be set to remove the Expect header from the request
43  if ($expect === false) {
44  $request->removeHeader('Expect');
45  } elseif ($expect !== true) {
46  // Default to using a MB as the point in which to start using the expect header
47  $expect = $expect ?: 1048576;
48  // If the expect_header value is numeric then only add if the size is greater than the cutoff
49  if (is_numeric($expect) && $body->getSize()) {
50  if ($body->getSize() < $expect) {
51  $request->removeHeader('Expect');
52  } else {
53  $request->setHeader('Expect', '100-Continue');
54  }
55  }
56  }
57  }
58 }
Guzzle\Service\Command\LocationVisitor\Request
Definition: AbstractRequestVisitor.php:3
Guzzle\Http\Message\RequestInterface
Definition: lib/vendor/guzzle/guzzle/src/Guzzle/Http/Message/RequestInterface.php:16
Guzzle\Service\Description\Parameter\filter
filter($value)
Definition: Parameter.php:201
Guzzle\Http\Message\MessageInterface\setHeader
setHeader($header, $value)
Guzzle\Service\Command\LocationVisitor\Request\BodyVisitor\visit
visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
Definition: Request/BodyVisitor.php:21
Guzzle\Http\EntityBodyInterface
Definition: EntityBodyInterface.php:10
Guzzle\Service\Command\LocationVisitor\Request\AbstractRequestVisitor
Definition: AbstractRequestVisitor.php:9
Guzzle\Http\Message\EntityEnclosingRequestInterface
Definition: EntityEnclosingRequestInterface.php:12
Guzzle\Service\Description\Parameter
Definition: Parameter.php:10
Guzzle\Http\EntityBody\factory
static factory($resource='', $size=null)
Definition: EntityBody.php:36
Guzzle\Http\Message\MessageInterface\removeHeader
removeHeader($header)
Guzzle\Http\EntityBody
Definition: EntityBody.php:13
Guzzle\Service\Command\CommandInterface
Definition: CommandInterface.php:17
Guzzle\Service\Command\LocationVisitor\Request\BodyVisitor\addExpectHeader
addExpectHeader(EntityEnclosingRequestInterface $request, EntityBodyInterface $body, $expect)
Definition: Request/BodyVisitor.php:40
Guzzle\Service\Description\Parameter\getData
getData($name=null)
Definition: Parameter.php:566
Guzzle\Service\Command\LocationVisitor\Request\BodyVisitor
Definition: Request/BodyVisitor.php:19
Guzzle\Stream\StreamInterface\getSize
getSize()