1: <?php
2:
3: namespace Guzzle\Service\Command\LocationVisitor\Request;
4:
5: use Guzzle\Http\EntityBody;
6: use Guzzle\Http\Message\EntityEnclosingRequestInterface;
7: use Guzzle\Http\Message\RequestInterface;
8: use Guzzle\Http\EntityBodyInterface;
9: use Guzzle\Service\Command\CommandInterface;
10: use Guzzle\Service\Description\Parameter;
11:
12: 13: 14: 15: 16: 17: 18:
19: class BodyVisitor extends AbstractRequestVisitor
20: {
21: 22: 23:
24: public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
25: {
26: $value = $param->filter($value);
27: $entityBody = EntityBody::factory($value);
28: $request->setBody($entityBody);
29: $this->addExpectHeader($request, $entityBody, $param->getData('expect_header'));
30:
31: if ($encoding = $entityBody->getContentEncoding()) {
32: $request->setHeader('Content-Encoding', $encoding);
33: }
34: }
35:
36: 37: 38: 39: 40: 41: 42:
43: protected function (EntityEnclosingRequestInterface $request, EntityBodyInterface $body, $expect)
44: {
45:
46: if ($expect === false) {
47: $request->removeHeader('Expect');
48: } elseif ($expect !== true) {
49:
50: $expect = $expect ?: 1048576;
51:
52: if (is_numeric($expect) && $body->getSize()) {
53: if ($body->getSize() < $expect) {
54: $request->removeHeader('Expect');
55: } else {
56: $request->setHeader('Expect', '100-Continue');
57: }
58: }
59: }
60: }
61: }
62: