121 if ( !$this->status->isOK() ) {
122 return Status::wrap( $this->status );
125 if ( $this->proxy ) {
126 $this->guzzleOptions[
'proxy'] = $this->proxy;
129 $this->guzzleOptions[
'timeout'] = $this->timeout;
130 $this->guzzleOptions[
'connect_timeout'] = $this->connectTimeout;
131 $this->guzzleOptions[
'version'] =
'1.1';
133 if ( !$this->followRedirects ) {
134 $this->guzzleOptions[
'allow_redirects'] =
false;
136 $this->guzzleOptions[
'allow_redirects'] = [
137 'max' => $this->maxRedirects
141 if ( $this->method ==
'POST' ) {
144 $this->guzzleOptions[
'form_params'] =
$postData;
146 $this->guzzleOptions[
'body'] =
$postData;
148 if ( !isset( $this->reqHeaders[
'Content-Type'] ) ) {
149 $this->reqHeaders[
'Content-Type'] =
'application/x-www-form-urlencoded';
156 $this->guzzleOptions[
'expect'] =
false;
163 $stack = HandlerStack::create( $this->handler );
166 $stack->remove(
'cookies' );
169 $stack->push( Middleware::mapRequest(
170 static function ( RequestInterface $request ) use ( $mwCookieJar ) {
171 $uri = $request->getUri();
172 $cookieHeader = $mwCookieJar->serializeToHttpRequest(
173 $uri->getPath() ?:
'/',
176 if ( !$cookieHeader ) {
180 return $request->withHeader(
'Cookie', $cookieHeader );
184 $this->guzzleOptions[
'handler'] = $stack;
187 $this->guzzleOptions[
'sink'] = $this->sink;
190 if ( $this->caInfo ) {
191 $this->guzzleOptions[
'verify'] = $this->caInfo;
192 } elseif ( !$this->sslVerifyHost && !$this->sslVerifyCert ) {
193 $this->guzzleOptions[
'verify'] =
false;
196 $client =
new Client( $this->guzzleOptions );
197 $request =
new Request( $this->method, $this->url );
198 foreach ( $this->reqHeaders as $name => $value ) {
199 $request = $request->withHeader( $name, $value );
203 $response = $client->send( $request );
204 $this->headerList = $response->getHeaders();
206 $this->respVersion = $response->getProtocolVersion();
207 $this->respStatus = $response->getStatusCode() .
' ' . $response->getReasonPhrase();
208 }
catch ( GuzzleHttp\Exception\ConnectException $e ) {
216 $handlerContext = $e->getHandlerContext();
217 if ( $handlerContext[
'errno'] == CURLE_OPERATION_TIMEOUTED ) {
218 $this->status->fatal(
'http-timed-out', $this->url );
220 $this->status->fatal(
'http-curl-error', $handlerContext[
'error'] );
223 $this->status->fatal(
'http-request-error' );
225 }
catch ( GuzzleHttp\Exception\RequestException $e ) {
227 $handlerContext = $e->getHandlerContext();
228 $this->status->fatal(
'http-curl-error', $handlerContext[
'error'] );
231 $needle =
'Connection timed out';
232 if ( strpos( $e->getMessage(), $needle ) !==
false ) {
233 $this->status->fatal(
'http-timed-out', $this->url );
235 $this->status->fatal(
'http-request-error' );
238 }
catch ( GuzzleHttp\Exception\GuzzleException $e ) {
239 $this->status->fatal(
'http-internal-error' );
242 if ( $this->profiler ) {
243 $profileSection = $this->profiler->scopedProfileIn(
244 __METHOD__ .
'-' . $this->profileName
248 if ( $this->profiler ) {
249 $this->profiler->scopedProfileOut( $profileSection );
255 return Status::wrap( $this->status );