123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php
- require_once 'HTTP/Request2/Response.php';
- abstract class HTTP_Request2_Adapter
- {
-
- protected static $bodyDisallowed = array('TRACE');
-
- protected static $bodyRequired = array('POST', 'PUT');
-
- protected $request;
-
- protected $requestBody;
-
- protected $contentLength;
-
- abstract public function sendRequest(HTTP_Request2 $request);
-
- protected function calculateRequestLength(&$headers)
- {
- $this->requestBody = $this->request->getBody();
- if (is_string($this->requestBody)) {
- $this->contentLength = strlen($this->requestBody);
- } elseif (is_resource($this->requestBody)) {
- $stat = fstat($this->requestBody);
- $this->contentLength = $stat['size'];
- rewind($this->requestBody);
- } else {
- $this->contentLength = $this->requestBody->getLength();
- $headers['content-type'] = 'multipart/form-data; boundary=' .
- $this->requestBody->getBoundary();
- $this->requestBody->rewind();
- }
- if (in_array($this->request->getMethod(), self::$bodyDisallowed)
- || 0 == $this->contentLength
- ) {
-
-
- if (in_array($this->request->getMethod(), self::$bodyRequired)) {
- $headers['content-length'] = 0;
- } else {
- unset($headers['content-length']);
-
-
- unset($headers['content-type']);
- }
- } else {
- if (empty($headers['content-type'])) {
- $headers['content-type'] = 'application/x-www-form-urlencoded';
- }
-
- if (!isset($headers['transfer-encoding'])) {
- $headers['content-length'] = $this->contentLength;
- }
- }
- }
- }
- ?>
|