md5-validator-plugin.rst 1.3 KB

1234567891011121314151617181920212223242526272829
  1. ====================
  2. MD5 validator plugin
  3. ====================
  4. Entity bodies can sometimes be modified over the wire due to a faulty TCP transport or misbehaving proxy. If an HTTP
  5. response contains a Content-MD5 header, then a MD5 hash of the entity body of a response can be compared against the
  6. Content-MD5 header of the response to determine if the response was delivered intact. The
  7. ``Guzzle\Plugin\Md5\Md5ValidatorPlugin`` will throw an ``UnexpectedValueException`` if the calculated MD5 hash does
  8. not match the Content-MD5 header value:
  9. .. code-block:: php
  10. use Guzzle\Http\Client;
  11. use Guzzle\Plugin\Md5\Md5ValidatorPlugin;
  12. $client = new Client('http://www.test.com/');
  13. $md5Plugin = new Md5ValidatorPlugin();
  14. // Add the md5 plugin to the client object
  15. $client->addSubscriber($md5Plugin);
  16. $request = $client->get('http://www.yahoo.com/');
  17. $request->send();
  18. Calculating the MD5 hash of a large entity body or an entity body that was transferred using a Content-Encoding is an
  19. expensive operation. When working in high performance applications, you might consider skipping the MD5 hash
  20. validation for entity bodies bigger than a certain size or Content-Encoded entity bodies
  21. (see ``Guzzle\Plugin\Md5\Md5ValidatorPlugin`` for more information).