Overview

Namespaces

  • Contrib
    • Bundle
      • CoverallsBundle
        • Console
        • Entity
      • CoverallsV1Bundle
        • Api
        • Collector
        • Command
        • Config
        • Entity
          • Git
    • Component
      • File
      • Log
      • System
        • Git
  • Guzzle
    • Batch
      • Exception
    • Cache
    • Common
      • Exception
    • Http
      • Curl
      • Exception
      • Message
      • QueryAggregator
    • Inflection
    • Iterator
    • Log
    • Parser
      • Cookie
      • Message
      • UriTemplate
      • Url
    • Plugin
      • Async
      • Backoff
      • Cache
      • Cookie
        • CookieJar
        • Exception
      • CurlAuth
      • ErrorResponse
        • Exception
      • History
      • Log
      • Md5
      • Mock
      • Oauth
    • Service
      • Builder
      • Command
        • Factory
        • LocationVisitor
          • Request
          • Response
      • Description
      • Exception
      • Resource
    • Stream
  • PHP
  • Psr
    • Log
  • Symfony
    • Component
      • Config
        • Definition
          • Builder
          • Exception
        • Exception
        • Loader
        • Resource
        • Util
      • Console
        • Command
        • Formatter
        • Helper
        • Input
        • Output
        • Tester
      • EventDispatcher
        • Debug
      • Finder
        • Adapter
        • Comparator
        • Exception
        • Expression
        • Iterator
        • Shell
      • Stopwatch
      • Yaml
        • Exception

Classes

  • AbstractRequestVisitor
  • BodyVisitor
  • HeaderVisitor
  • JsonVisitor
  • PostFieldVisitor
  • PostFileVisitor
  • QueryVisitor
  • ResponseBodyVisitor
  • XmlVisitor

Interfaces

  • RequestVisitorInterface
  • Overview
  • Namespace
  • Class
  • Tree
  • Todo
 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:  * Visitor used to apply a body to a request
14:  *
15:  * This visitor can use a data parameter of 'expect' to control the Expect header. Set the expect data parameter to
16:  * false to disable the expect header, or set the value to an integer so that the expect 100-continue header is only
17:  * added if the Content-Length of the entity body is greater than the value.
18:  */
19: class BodyVisitor extends AbstractRequestVisitor
20: {
21:     /**
22:      * {@inheritdoc}
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:         // Add the Content-Encoding header if one is set on the EntityBody
31:         if ($encoding = $entityBody->getContentEncoding()) {
32:             $request->setHeader('Content-Encoding', $encoding);
33:         }
34:     }
35: 
36:     /**
37:      * Add the appropriate expect header to a request
38:      *
39:      * @param EntityEnclosingRequestInterface $request Request to update
40:      * @param EntityBodyInterface             $body    Entity body of the request
41:      * @param string|int                      $expect  Expect header setting
42:      */
43:     protected function addExpectHeader(EntityEnclosingRequestInterface $request, EntityBodyInterface $body, $expect)
44:     {
45:         // Allow the `expect` data parameter to be set to remove the Expect header from the request
46:         if ($expect === false) {
47:             $request->removeHeader('Expect');
48:         } elseif ($expect !== true) {
49:             // Default to using a MB as the point in which to start using the expect header
50:             $expect = $expect ?: 1048576;
51:             // If the expect_header value is numeric then only add if the size is greater than the cutoff
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: 
php-coveralls API documentation generated by ApiGen 2.8.0