104 if ( is_array( $this->postData ) ) {
108 if ( $this->parsedUrl[
'scheme'] !=
'http'
109 && $this->parsedUrl[
'scheme'] !=
'https' ) {
110 $this->status->fatal(
'http-invalid-scheme', $this->parsedUrl[
'scheme'] );
113 $this->reqHeaders[
'Accept'] =
"*/*";
114 $this->reqHeaders[
'Connection'] =
'Close';
115 if ( $this->method ==
'POST' ) {
117 $this->reqHeaders[
'Content-Length'] = strlen( $this->postData );
118 if ( !isset( $this->reqHeaders[
'Content-Type'] ) ) {
119 $this->reqHeaders[
'Content-Type'] =
"application/x-www-form-urlencoded";
126 'method' => $this->method,
128 'protocol_version' =>
'1.1',
129 'max_redirects' => $this->followRedirects ? $this->maxRedirects : 0,
130 'ignore_errors' =>
true,
131 'timeout' => $this->timeout,
133 'curl_verify_ssl_host' => $this->sslVerifyHost ? 2 : 0,
134 'curl_verify_ssl_peer' => $this->sslVerifyCert,
137 'verify_peer' => $this->sslVerifyCert,
138 'SNI_enabled' =>
true,
139 'ciphers' =>
'HIGH:!SSLv2:!SSLv3:-ADH:-kDH:-kECDH:-DSS',
140 'disable_compression' =>
true,
144 if ( $this->proxy ) {
145 $options[
'http'][
'proxy'] = $this->
urlToTcp( $this->proxy );
146 $options[
'http'][
'request_fulluri'] =
true;
149 if ( $this->postData ) {
150 $options[
'http'][
'content'] = $this->postData;
153 if ( $this->sslVerifyHost ) {
154 $options[
'ssl'][
'peer_name'] = $this->parsedUrl[
'host'];
159 $context = stream_context_create( $options );
161 $this->headerList = [];
167 if ( $this->profiler ) {
168 $profileSection = $this->profiler->scopedProfileIn(
169 __METHOD__ .
'-' . $this->profileName
174 $this->fopenErrors = [];
175 set_error_handler( [ $this,
'errorHandler' ] );
176 $fh = fopen(
$url,
"r",
false, $context );
177 restore_error_handler();
183 $result = stream_get_meta_data( $fh );
184 $this->headerList = $result[
'wrapper_data'];
187 if ( !$this->followRedirects ) {
191 # Handle manual redirection
192 if ( !$this->
isRedirect() || $reqCount > $this->maxRedirects ) {
195 # Check security of URL
199 $this->logger->debug( __METHOD__ .
": insecure redirection" );
203 if ( $this->profiler ) {
204 $this->profiler->scopedProfileOut( $profileSection );
209 if ( $fh ===
false ) {
210 if ( $this->fopenErrors ) {
211 $this->logger->warning( __CLASS__
212 .
': error opening connection: {errstr1}', $this->fopenErrors );
214 $this->status->fatal(
'http-request-error' );
215 return Status::wrap( $this->status );
218 if ( $result[
'timed_out'] ) {
219 $this->status->fatal(
'http-timed-out', $this->url );
220 return Status::wrap( $this->status );
225 if ( $this->status->isOK() || (
int)$this->respStatus >= 300 ) {
226 while ( !feof( $fh ) ) {
227 $buf = fread( $fh, 8192 );
229 if ( $buf ===
false ) {
230 $this->status->fatal(
'http-read-error' );
235 call_user_func( $this->callback, $fh, $buf );
241 return Status::wrap( $this->status );