Transport.php 953 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace Qiniu\Pili;
  3. use \Qiniu\Pili\Utils;
  4. use \Qiniu\Pili\HttpRequest;
  5. final class Transport
  6. {
  7. private $_mac;
  8. public function __construct($mac)
  9. {
  10. $this->_mac = $mac;
  11. }
  12. public function send($method, $url, $body = null)
  13. {
  14. $headers = $this->_setHeaders($method, $url, $body);
  15. $response = HttpRequest::send($method, $url, $body, $headers);
  16. return $response->body;
  17. }
  18. private function _setHeaders($method, $url, $body = null)
  19. {
  20. if ($method != HttpRequest::GET) {
  21. $cType = 'application/json';
  22. } else {
  23. $cType = null;
  24. }
  25. $macToken = $this->_mac->MACToken($method, $url, $cType, $body);
  26. $ua = Utils::getUserAgent(Config::SDK_USER_AGENT, Config::SDK_VERSION);
  27. return array(
  28. 'Content-Type' => $cType,
  29. 'User-Agent' => $ua,
  30. 'Authorization' => $macToken,
  31. );
  32. }
  33. }