21 use GuzzleHttp\Client;
22 use GuzzleHttp\Psr7\Request;
59 if ( isset( $options[
'handler'] ) ) {
60 $this->handler = $options[
'handler'];
62 if ( isset( $options[
'sink'] ) ) {
63 $this->sink = $options[
'sink'];
103 if ( !$this->sink ) {
117 if ( !$this->status->isOK() ) {
121 if ( $this->proxy ) {
127 $this->guzzleOptions[
'version'] =
'1.1';
129 if ( !$this->followRedirects ) {
130 $this->guzzleOptions[
'allow_redirects'] =
false;
132 $this->guzzleOptions[
'allow_redirects'] = [
137 if ( $this->method ==
'POST' ) {
140 $this->guzzleOptions[
'form_params'] =
$postData;
142 $this->guzzleOptions[
'body'] =
$postData;
144 if ( !isset( $this->reqHeaders[
'Content-Type'] ) ) {
145 $this->reqHeaders[
'Content-Type'] =
'application/x-www-form-urlencoded';
152 $this->guzzleOptions[
'expect'] =
false;
157 if ( $this->handler ) {
165 if ( $this->caInfo ) {
167 } elseif ( !$this->sslVerifyHost && !$this->sslVerifyCert ) {
168 $this->guzzleOptions[
'verify'] =
false;
172 $client =
new Client( $this->guzzleOptions );
173 $request =
new Request( $this->method, $this->url );
175 $this->headerList =
$response->getHeaders();
177 $this->respVersion =
$response->getProtocolVersion();
179 }
catch ( GuzzleHttp\Exception\ConnectException $e ) {
187 $handlerContext = $e->getHandlerContext();
188 if ( $handlerContext[
'errno'] == CURLE_OPERATION_TIMEOUTED ) {
189 $this->status->fatal(
'http-timed-out', $this->url );
191 $this->status->fatal(
'http-curl-error', $handlerContext[
'error'] );
194 $this->status->fatal(
'http-request-error' );
196 }
catch ( GuzzleHttp\Exception\RequestException $e ) {
198 $handlerContext = $e->getHandlerContext();
199 $this->status->fatal(
'http-curl-error', $handlerContext[
'error'] );
202 $needle =
'Connection timed out';
203 if ( strpos( $e->getMessage(), $needle ) !==
false ) {
204 $this->status->fatal(
'http-timed-out', $this->url );
206 $this->status->fatal(
'http-request-error' );
209 }
catch ( GuzzleHttp\Exception\GuzzleException $e ) {
210 $this->status->fatal(
'http-internal-error' );
213 if ( $this->profiler ) {
214 $profileSection = $this->profiler->scopedProfileIn(
215 __METHOD__ .
'-' . $this->profileName
219 if ( $this->profiler ) {
220 $this->profiler->scopedProfileOut( $profileSection );
238 return ( $this->handler && is_a( $this->handler,
'GuzzleHttp\Handler\CurlHandler' ) ) ||
239 ( !$this->handler && extension_loaded(
'curl' ) );
248 if ( !$this->status->isOK() ) {
249 $this->respStatus =
'0 Error';
252 foreach ( $this->headerList as $name => $values ) {
253 $this->respHeaders[strtolower( $name )] = $values;