123 if ( !$this->status->isOK() ) {
124 return Status::wrap( $this->status );
127 if ( $this->proxy ) {
128 $this->guzzleOptions[
'proxy'] = $this->proxy;
131 $this->guzzleOptions[
'timeout'] = $this->timeout;
132 $this->guzzleOptions[
'connect_timeout'] = $this->connectTimeout;
133 $this->guzzleOptions[
'version'] =
'1.1';
135 if ( !$this->followRedirects ) {
136 $this->guzzleOptions[
'allow_redirects'] =
false;
138 $this->guzzleOptions[
'allow_redirects'] = [
139 'max' => $this->maxRedirects
143 if ( $this->method ==
'POST' ) {
146 $this->guzzleOptions[
'form_params'] =
$postData;
148 $this->guzzleOptions[
'body'] =
$postData;
150 if ( !isset( $this->reqHeaders[
'Content-Type'] ) ) {
151 $this->reqHeaders[
'Content-Type'] =
'application/x-www-form-urlencoded';
158 $this->guzzleOptions[
'expect'] =
false;
161 $stack = HandlerStack::create( $this->handler );
168 $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 if ( !$this->logger instanceof NullLogger ) {
186 $stack->push( Middleware::log( $this->logger,
new MessageFormatter(
190 '[{ts}] {method} {uri} HTTP/{version} - {code} {error}'
194 $this->guzzleOptions[
'handler'] = $stack;
197 $this->guzzleOptions[
'sink'] = $this->sink;
200 if ( $this->caInfo ) {
201 $this->guzzleOptions[
'verify'] = $this->caInfo;
202 } elseif ( !$this->sslVerifyHost && !$this->sslVerifyCert ) {
203 $this->guzzleOptions[
'verify'] =
false;
206 $client =
new Client( $this->guzzleOptions );
207 $request =
new Request( $this->method, $this->url );
208 foreach ( $this->reqHeaders as $name => $value ) {
209 $request = $request->withHeader( $name, $value );
213 $response = $client->send( $request );
214 $this->headerList = $response->getHeaders();
216 $this->respVersion = $response->getProtocolVersion();
217 $this->respStatus = $response->getStatusCode() .
' ' . $response->getReasonPhrase();
218 }
catch ( GuzzleHttp\Exception\ConnectException $e ) {
226 $handlerContext = $e->getHandlerContext();
227 if ( $handlerContext[
'errno'] == CURLE_OPERATION_TIMEOUTED ) {
228 $this->status->fatal(
'http-timed-out', $this->url );
230 $this->status->fatal(
'http-curl-error', $handlerContext[
'error'] );
233 $this->status->fatal(
'http-request-error' );
235 }
catch ( GuzzleHttp\Exception\RequestException $e ) {
237 $handlerContext = $e->getHandlerContext();
238 $this->status->fatal(
'http-curl-error', $handlerContext[
'error'] );
241 $needle =
'Connection timed out';
242 if ( strpos( $e->getMessage(), $needle ) !==
false ) {
243 $this->status->fatal(
'http-timed-out', $this->url );
245 $this->status->fatal(
'http-request-error' );
248 }
catch ( GuzzleHttp\Exception\GuzzleException $e ) {
249 $this->status->fatal(
'http-internal-error' );
252 if ( $this->profiler ) {
253 $profileSection = $this->profiler->scopedProfileIn(
254 __METHOD__ .
'-' . $this->profileName
258 if ( $this->profiler ) {
259 $this->profiler->scopedProfileOut( $profileSection );
265 return Status::wrap( $this->status );