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.

56 lines
1.3 KiB

  1. <?php
  2. namespace p3k;
  3. class HTTP {
  4. public $timeout = 4;
  5. public $max_redirects = 8;
  6. public function get($url, $headers=[]) {
  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, $headers);
  12. }
  13. public function post($url, $body, $headers=[]) {
  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(!should_follow_redirects($url)) {
  29. return 'p3k\HTTPStream';
  30. } else {
  31. return 'p3k\HTTPCurl';
  32. }
  33. }
  34. public static function link_rels($header_array) {
  35. $headers = '';
  36. foreach($header_array as $k=>$header) {
  37. if(is_string($header)) {
  38. $headers .= $k . ': ' . $header . "\r\n";
  39. } else {
  40. foreach($header as $h) {
  41. $headers .= $k . ': ' . $h . "\r\n";
  42. }
  43. }
  44. }
  45. $rels = \IndieWeb\http_rels($headers);
  46. return $rels;
  47. }
  48. }