122 if ( !$this->status->isOK() ) {
123 return Status::wrap( $this->status );
126 if ( $this->proxy ) {
127 $this->guzzleOptions[
'proxy'] = $this->proxy;
130 $this->guzzleOptions[
'timeout'] = $this->timeout;
131 $this->guzzleOptions[
'connect_timeout'] = $this->connectTimeout;
132 $this->guzzleOptions[
'version'] =
'1.1';
134 if ( !$this->followRedirects ) {
135 $this->guzzleOptions[
'allow_redirects'] =
false;
137 $this->guzzleOptions[
'allow_redirects'] = [
138 'max' => $this->maxRedirects
142 if ( $this->method ==
'POST' ) {
145 $this->guzzleOptions[
'form_params'] =
$postData;
147 $this->guzzleOptions[
'body'] =
$postData;
149 if ( !isset( $this->reqHeaders[
'Content-Type'] ) ) {
150 $this->reqHeaders[
'Content-Type'] =
'application/x-www-form-urlencoded';
157 $this->guzzleOptions[
'expect'] =
false;
164 $stack = HandlerStack::create( $this->handler );
167 $stack->remove(
'cookies' );
170 $stack->push( Middleware::mapRequest(
171 static function ( RequestInterface $request ) use ( $mwCookieJar ) {
172 $uri = $request->getUri();
173 $cookieHeader = $mwCookieJar->serializeToHttpRequest(
174 $uri->getPath() ?:
'/',
177 if ( !$cookieHeader ) {
181 return $request->withHeader(
'Cookie', $cookieHeader );
185 $this->guzzleOptions[
'handler'] = $stack;
188 $this->guzzleOptions[
'sink'] = $this->sink;
191 if ( $this->caInfo ) {
192 $this->guzzleOptions[
'verify'] = $this->caInfo;
193 } elseif ( !$this->sslVerifyHost && !$this->sslVerifyCert ) {
194 $this->guzzleOptions[
'verify'] =
false;
197 $client =
new Client( $this->guzzleOptions );
198 $request =
new Request( $this->method, $this->url );
199 foreach ( $this->reqHeaders as $name => $value ) {
200 $request = $request->withHeader( $name, $value );
204 $response = $client->send( $request );
205 $this->headerList = $response->getHeaders();
207 $this->respVersion = $response->getProtocolVersion();
208 $this->respStatus = $response->getStatusCode() .
' ' . $response->getReasonPhrase();
209 }
catch ( GuzzleHttp\Exception\ConnectException $e ) {
217 $handlerContext = $e->getHandlerContext();
218 if ( $handlerContext[
'errno'] == CURLE_OPERATION_TIMEOUTED ) {
219 $this->status->fatal(
'http-timed-out', $this->url );
221 $this->status->fatal(
'http-curl-error', $handlerContext[
'error'] );
224 $this->status->fatal(
'http-request-error' );
226 }
catch ( GuzzleHttp\Exception\RequestException $e ) {
228 $handlerContext = $e->getHandlerContext();
229 $this->status->fatal(
'http-curl-error', $handlerContext[
'error'] );
232 $needle =
'Connection timed out';
233 if ( strpos( $e->getMessage(), $needle ) !==
false ) {
234 $this->status->fatal(
'http-timed-out', $this->url );
236 $this->status->fatal(
'http-request-error' );
239 }
catch ( GuzzleHttp\Exception\GuzzleException $e ) {
240 $this->status->fatal(
'http-internal-error' );
243 if ( $this->profiler ) {
244 $profileSection = $this->profiler->scopedProfileIn(
245 __METHOD__ .
'-' . $this->profileName
249 if ( $this->profiler ) {
250 $this->profiler->scopedProfileOut( $profileSection );
256 return Status::wrap( $this->status );