Browse Source

fix HTTP\Stream

pull/1/head 0.1.2
Aaron Parecki 7 years ago
parent
commit
6ef5134d76
No known key found for this signature in database GPG Key ID: 276C2817346D6056
2 changed files with 6 additions and 7 deletions
  1. +2
    -1
      src/p3k/HTTP/Curl.php
  2. +4
    -6
      src/p3k/HTTP/Stream.php

+ 2
- 1
src/p3k/HTTP/Curl.php View File

@ -74,7 +74,8 @@ class Curl implements Transport {
private function _set_curlopts($ch, $url) { private function _set_curlopts($ch, $url) {
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
if($this->_max_redirects > 0)
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, $this->_max_redirects); curl_setopt($ch, CURLOPT_MAXREDIRS, $this->_max_redirects);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, round($this->_timeout * 1000)); curl_setopt($ch, CURLOPT_TIMEOUT_MS, round($this->_timeout * 1000));
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, 2000); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, 2000);

+ 4
- 6
src/p3k/HTTP/Stream.php View File

@ -23,19 +23,19 @@ class Stream implements Transport {
} }
public function get($url, $headers=[]) { public function get($url, $headers=[]) {
set_error_handler("p3k\HTTPStream::exception_error_handler");
set_error_handler("p3k\HTTP\Stream::exception_error_handler");
$context = $this->_stream_context('GET', $url, false, $headers); $context = $this->_stream_context('GET', $url, false, $headers);
return $this->_fetch($url, $context); return $this->_fetch($url, $context);
} }
public function post($url, $body, $headers=[]) { public function post($url, $body, $headers=[]) {
set_error_handler("p3k\HTTPStream::exception_error_handler");
set_error_handler("p3k\HTTP\Stream::exception_error_handler");
$context = $this->_stream_context('POST', $url, $body, $headers); $context = $this->_stream_context('POST', $url, $body, $headers);
return $this->_fetch($url, $context); return $this->_fetch($url, $context);
} }
public function head($url, $headers=[]) { public function head($url, $headers=[]) {
set_error_handler("p3k\HTTPStream::exception_error_handler");
set_error_handler("p3k\HTTP\Stream::exception_error_handler");
$context = $this->_stream_context('HEAD', $url, false, $headers); $context = $this->_stream_context('HEAD', $url, false, $headers);
return $this->_fetch($url, $context); return $this->_fetch($url, $context);
} }
@ -97,9 +97,7 @@ class Stream implements Transport {
$options['header'] = implode("\r\n", $headers); $options['header'] = implode("\r\n", $headers);
} }
// Special-case appspot.com URLs to not follow redirects.
// https://cloud.google.com/appengine/docs/php/urlfetch/
if(should_follow_redirects($url)) {
if($this->_max_redirects > 0) {
$options['follow_location'] = 1; $options['follow_location'] = 1;
$options['max_redirects'] = $this->_max_redirects; $options['max_redirects'] = $this->_max_redirects;
} else { } else {

Loading…
Cancel
Save