You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
951 B

  1. <?php
  2. namespace p3k;
  3. class HTTP {
  4. public $timeout = 4;
  5. public $max_redirects = 8;
  6. public function get($url) {
  7. $class = $this->_class($url);
  8. $http = new $class($url);
  9. $http->timeout = $this->timeout;
  10. $http->max_redirects = $this->max_redirects;
  11. return $http->get($url);
  12. }
  13. public function post($url, $body, $headers=array()) {
  14. $class = $this->_class($url);
  15. $http = new $class($url);
  16. $http->timeout = $this->timeout;
  17. $http->max_redirects = $this->max_redirects;
  18. return $http->post($url, $body, $headers);
  19. }
  20. public function head($url) {
  21. $class = $this->_class($url);
  22. $http = new $class($url);
  23. $http->timeout = $this->timeout;
  24. $http->max_redirects = $this->max_redirects;
  25. return $http->head($url);
  26. }
  27. private function _class($url) {
  28. if(preg_match('/brid\.gy|appspot\.com/', $url)) {
  29. return 'p3k\HTTPStream';
  30. } else {
  31. return 'p3k\HTTPCurl';
  32. }
  33. }
  34. }