101 if ( is_array( $this->postData ) ) {
105 if ( $this->parsedUrl[
'scheme'] !=
'http'
106 && $this->parsedUrl[
'scheme'] !=
'https' ) {
107 $this->status->fatal(
'http-invalid-scheme', $this->parsedUrl[
'scheme'] );
110 $this->reqHeaders[
'Accept'] =
"*/*";
111 $this->reqHeaders[
'Connection'] =
'Close';
112 if ( $this->method ==
'POST' ) {
114 $this->reqHeaders[
'Content-Length'] = strlen( $this->postData );
115 if ( !isset( $this->reqHeaders[
'Content-Type'] ) ) {
116 $this->reqHeaders[
'Content-Type'] =
"application/x-www-form-urlencoded";
123 'method' => $this->method,
125 'protocol_version' =>
'1.1',
126 'max_redirects' => $this->followRedirects ? $this->maxRedirects : 0,
127 'ignore_errors' =>
true,
128 'timeout' => $this->timeout,
130 'curl_verify_ssl_host' => $this->sslVerifyHost ? 2 : 0,
131 'curl_verify_ssl_peer' => $this->sslVerifyCert,
134 'verify_peer' => $this->sslVerifyCert,
135 'SNI_enabled' =>
true,
136 'ciphers' =>
'HIGH:!SSLv2:!SSLv3:-ADH:-kDH:-kECDH:-DSS',
137 'disable_compression' =>
true,
141 if ( $this->proxy ) {
142 $options[
'http'][
'proxy'] = $this->
urlToTcp( $this->proxy );
143 $options[
'http'][
'request_fulluri'] =
true;
146 if ( $this->postData ) {
147 $options[
'http'][
'content'] = $this->postData;
150 if ( $this->sslVerifyHost ) {
151 $options[
'ssl'][
'peer_name'] = $this->parsedUrl[
'host'];
156 $context = stream_context_create( $options );
158 $this->headerList = [];
164 if ( $this->profiler ) {
165 $profileSection = $this->profiler->scopedProfileIn(
166 __METHOD__ .
'-' . $this->profileName
171 $this->fopenErrors = [];
172 set_error_handler( [ $this,
'errorHandler' ] );
174 restore_error_handler();
180 $result = stream_get_meta_data(
$fh );
181 $this->headerList = $result[
'wrapper_data'];
184 if ( !$this->followRedirects ) {
188 # Handle manual redirection
189 if ( !$this->
isRedirect() || $reqCount > $this->maxRedirects ) {
192 # Check security of URL
195 if ( !Http::isValidURI(
$url ) ) {
196 $this->logger->debug( __METHOD__ .
": insecure redirection\n" );
200 if ( $this->profiler ) {
201 $this->profiler->scopedProfileOut( $profileSection );
206 if (
$fh ===
false ) {
207 if ( $this->fopenErrors ) {
208 $this->logger->warning( __CLASS__
209 .
': error opening connection: {errstr1}', $this->fopenErrors );
211 $this->status->fatal(
'http-request-error' );
212 return Status::wrap( $this->status );
215 if ( $result[
'timed_out'] ) {
216 $this->status->fatal(
'http-timed-out', $this->url );
217 return Status::wrap( $this->status );
222 if ( $this->status->isOK() || (
int)$this->respStatus >= 300 ) {
223 while ( !feof(
$fh ) ) {
224 $buf = fread(
$fh, 8192 );
226 if ( $buf ===
false ) {
227 $this->status->fatal(
'http-read-error' );
232 call_user_func( $this->callback,
$fh, $buf );
238 return Status::wrap( $this->status );