This method creates a stream socket to the server.

@param ApiClient $apiClient the API client instance
@param HttpRequest $request the HTTP request
@throws ConnectionException
@return resource
511066
private function createSocketStream(ApiClient $apiClient, HttpRequest $request) {
		if ($request->isSecureConnection()) {
			if (!extension_loaded('openssl')) {
				throw new \Exception("You have to enable OpenSSL.");
			}
		}

		$proxyUrl = $this->readEnvironmentVariable(self::ENVIRONMENT_VARIABLE_PROXY_URL);
		if ($proxyUrl !== null) {
			$host = parse_url($proxyUrl, PHP_URL_HOST);
			$port = parse_url($proxyUrl, PHP_URL_PORT);
			if(empty($port)) {
				throw new ConnectionException($request->getUrl(), $request->getLogToken(), "The Proxy URL must contain a port number.");
			}
			
		} else {
			$host = ($request->isSecureConnection() ? $this->getSslProtocol() . '://' : '') . $request->getHost();
			$port = $request->getPort();
			if(empty($port)) {
				$port = $request->isSecureConnection() ? 443 : 80;
			}	
		}			
		$socket = $host . ':' . $port;

		$filePointer = @stream_socket_client($socket, $errno, $errstr, $apiClient->getConnectionTimeout(), STREAM_CLIENT_CONNECT,
				$this->createStreamContext($apiClient, $request));

		if ($filePointer === false) {
			throw new ConnectionException($request->getUrl(), $request->getLogToken(), $errstr);
		}

		if (!(get_resource_type($filePointer) == 'stream')) {
			$errorMessage = 'Could not connect to the server. The returned socket was not a stream.';
			throw new ConnectionException($request->getUrl(), $request->getLogToken(), $errorMessage);
		}

		return $filePointer;
	}
507450
protected function _send(Request $request)
    {
        $deadline = false;
        if (isset($this->_contextOptions['timeout']) && $this->_contextOptions['timeout'] > 0) {
            $deadline = time() + $this->_contextOptions['timeout'];
        }

        $url = $request->getUri();
        $this->_open($url);
        $content = '';
        $timedOut = false;

        while (!feof($this->_stream)) {
            if ($deadline !== false) {
                stream_set_timeout($this->_stream, max($deadline - time(), 1));
            }

            $content .= fread($this->_stream, 8192);

            $meta = stream_get_meta_data($this->_stream);
            if ($meta['timed_out'] || ($deadline !== false && time() > $deadline)) {
                $timedOut = true;
                break;
            }
        }
        $meta = stream_get_meta_data($this->_stream);
        fclose($this->_stream);

        if ($timedOut) {
            throw new HttpException('Connection timed out ' . $url, 504);
        }

        $headers = $meta['wrapper_data'];
        if (isset($headers['headers']) && is_array($headers['headers'])) {
            $headers = $headers['headers'];
        }

        return $this->createResponses($headers, $content);
    }
686208
public function send(RequestInterface $request)
    {
        // Checking the connection
        if (!$this->connection->isOpened()) {
            throw new LogicException('Cannot send request to the not open connection. Call connect() before send().');
        }

        // Preparing the request
        if (!$request->isBuilt()) {
            $request->build();
        }

        $requestXML = $request->saveXML();
        $this->logger->info('EPP request body.', ['body' => $requestXML]);

        // Sending a request
        $this->connection->write($requestXML);
        $responseXML = $this->connection->read();
        $this->logger->info('EPP response body.', ['body' => $responseXML]);

        // Creating a response
        $responseClass = $request->getResponseClass();
        $response = new $responseClass($responseXML);

        // Handle response in the extension
        foreach ($this->extensionStack as $extension) {
            $this->logger->debug(sprintf('Handle response in \'%s\' extension.', get_class($extension)));
            $extension->handleResponse($response);
        }

        return $response;
    }
115950
public static function make(Client $httpClient, array $params = [])
    {
        $instance = new static($httpClient);

        $instance->configure($params);

        return $instance;
    }
668211
protected function createClientRequest(RequestInterface $request): PsrRequestInterface
    {
        $endpoint = $this->endpointService->getEndpointForRequest($request);

        return new Request(
            'POST',
            $endpoint->getRequestPath(),
            $this->getRequestHeaders($endpoint),
            $this->serializer->serialize($request, 'json')
        );
    }
1329818
public static function createFromRequest(StreamInterface $stream, ServerRequestInterface $request = null)
    {
        $result = [];
        if ($request === null) {
            $headers = \tao_helpers_Http::getHeaders();
            $rangeHeader = isset($headers['Range']) ? [$headers['Range']] : null;
        } else {
            $rangeHeader = $request->hasHeader('Range') ? $request->getHeader('Range') : null;
        }
        if ($rangeHeader) {
            $ranges = explode(',', $rangeHeader[0]);
            foreach($ranges as $range) {
                $range = str_replace('bytes=', '', $range);
                $result[] = new StreamRange($stream, $range);
            }
        }
        return $result;
    }
559335
private function httpRequest(
        $url,
        $request,
        $data = array(),
        $sendHeaders = array(),
        $timeout = 10
    ) {
        $streamParams = array(
            'http' => array(
                'method' => $request,
                'ignore_errors' => true,
                'timeout' => $timeout,
                'header' => "User-Agent: " . $this->userAgent . "\r\n"
            )
        );
        foreach ($sendHeaders as $header => $value) {
            $streamParams['http']['header'] .= $header . ': ' . $value . "\r\n";
        }
        foreach ($this->extraHeaders as $header => $value) {
            $streamParams['http']['header'] .= $header . ': ' . $value . "\r\n";
        }

        if (is_array($data)) {
            if (in_array($request, array('POST', 'PUT')))
                $streamParams['http']['content'] = http_build_query($data);
            elseif ($data && count($data))
                $url .= '?' . http_build_query($data);
        } elseif ($data !== null) {
            if (in_array($request, array('POST', 'PUT')))
                $streamParams['http']['content'] = $data;
        }

        $streamParams['cURL'] = $streamParams['http'];

        $context = stream_context_create($streamParams);
        $fp = @fopen($url, 'rb', false, $context);
        if (!$fp)
            $content = false;
        else
            $content = stream_get_contents($fp);

        $status = null;
        $statusCode = null;
        $headers = array();

        if ($content !== false) {
            $metadata = stream_get_meta_data($fp);
            if (isset($metadata['wrapper_data']['headers']))
                $headerMetadata = $metadata['wrapper_data']['headers'];
            else
                $headerMetadata = $metadata['wrapper_data'];
            foreach ($headerMetadata as $row) {
                if (preg_match('/^HTTP\/1\.[01] (\d{3})\s*(.*)/', $row, $m)) {
                    $statusCode = $m[1];
                    $status = $m[2];
                } elseif (preg_match('/^([^:]+):\s*(.*)$/', $row, $m)) {
                    $headers[mb_strtolower($m[1])] = $m[2];
                }
            }
        }

        return (object) array(
            'ok' => $statusCode == 200,
            'statusCode' => $statusCode,
            'status' => $status,
            'content' => $content,
            'headers' => $headers
        );
    }
249882
private function buildStreamContextOptions(ApiClient $apiClient, HttpRequest $request) {
		$options = array(
			'http' => array(),
			'ssl' => array()
		);
		if ($request->isSecureConnection()) {
			$options['ssl']['verify_host'] = true;
			$options['ssl']['allow_self_signed'] = false;
			$options['ssl']['verify_peer'] = false;

			if ($apiClient->isCertificateAuthorityCheckEnabled()) {
				$options['ssl']['verify_peer'] = true;
				$options['ssl']['cafile'] = $apiClient->getCertificateAuthority();
			}
		}
		$ipVersion = $this->readEnvironmentVariable(self::ENVIRONMENT_VARIABLE_IP_ADDRESS_VERSION);
		if ($ipVersion !== null) {
			if ($ipVersion == self::IP_ADDRESS_VERSION_V4) {
				$options['socket'] = array(
					'bindto' => '0.0.0.0:0'
				);
			} elseif ($ipVersion == self::IP_ADDRESS_VERSION_V6) {
				$options['socket'] = array(
					'bindto' => '[::]:0'
				);
			}
		}
		return $options;
	}
37498
public function createClient(array $config = []): HttpClient
    {
        if (!class_exists(Client::class)) {
            throw new LogicException(
                'To use the Socket client you need to install the "php-http/socket-client" package.'
            );
        }

        return new Client($this->messageFactory, $config);
    }
1114607
private static void streamRequest(Request request, ApiClient client, SocketListener listener) {
    WebSocketCall.create(client.getHttpClient(), request).enqueue(new Listener(listener));
  }
66322
@Deprecated
  public synchronized void setHttpClient(CloseableHttpClient httpClient) {
    Objects.requireNonNull(httpClient);
    close();
    HttpExecutorFactory.httpClient = httpClient;
  }
800254
public function processRequest(ApiRequestInterface $request)
  {
    $maxAttempts = 2;
    $ex = null;
    $startTime = time();
    for($i = 0; $i < $maxAttempts; $i++)
    {
      try
      {
        $ex = null;
        $response = parent::processRequest($request);
        break;
      }
      catch(ConnectException $e)
      {
        usleep(10000); // 10ms sleep on failures
        $ex = $e;
        if((time() - $startTime) > 10) // wait no more than 10 seconds to get a connection
        {
          break;
        }
      }
    }
    if($ex)
    {
      throw $ex;
    }

    if($response instanceof FortifiApiResponse)
    {
      $response->setRequestId($this->_lastRequestId);
    }
    return $response;
  }
1085157
public function execute(ClientRequestInterface $request, array $headers = null, array $clientOptions = [])
    {
        if ($request instanceof ContextAwareInterface) {
            $request->setContextIfNull($this->getConfig()->getContext());
        }
        $httpRequest = $this->createHttpRequest($request, $headers);

        try {
            $client = $this->getHttpClient();
            if ($client instanceof AdapterOptionInterface) {
                $httpResponse = $client->execute($httpRequest, $clientOptions);
            } else {
                $httpResponse = $client->execute($httpRequest);
            }
            $response = $request->buildResponse($httpResponse);
        } catch (ApiException $exception) {
            if ($exception instanceof InvalidTokenException && !$this->tokenRefreshed) {
                $this->tokenRefreshed = true;
                $this->getOauthManager()->refreshToken();
                return $this->execute($request);
            }
            if ($this->getConfig()->getThrowExceptions() || !$exception->getResponse() instanceof ResponseInterface) {
                throw $exception;
            }
            $httpResponse = $exception->getResponse();
            $this->logException($exception);
            $response = new ErrorResponse($exception, $request, $httpResponse);
        }
        $this->logDeprecatedRequest($httpResponse, $httpRequest);


        return $response;
    }
360023
public function create(ApiClientInterface $client, UserInterface $user = null)
    {
        $tokenClass = $this->tokenClass;

        return $tokenClass::create($client, $user);
    }
387161
public function transform($apiClientCollection, array $params = array())
    {
        $facade = $this->newFacade();

        foreach ($apiClientCollection as $apiClient) {
            $facade->addApiClient($this->getContext()->transform('api_client', $apiClient));
        }

        return $facade;
    }
1277723
public function setHttpClient($httpClient = null)
    {
        if ($httpClient === null)
        {
            $this->_httpClient = new CurlClient($this->_apiKey, $this->_siteID);
            return;
        }
        $httpClient->setCredentials($this->_apiKey, $this->_siteID);
        $this->_httpClient = $httpClient;
    }
1317864
public static function create(
        ApiContext $apiContext,
        string $clientPublicKey
    ): BunqResponseInstallation {
        $installation = new static($clientPublicKey);

        $apiClient = new ApiClient($apiContext);
        $responseRaw = $apiClient->post(self::ENDPOINT_URL_POST, $installation->jsonSerialize(), []);

        return BunqResponseInstallation::castFromBunqResponse(
            static::classFromJson($responseRaw)
        );
    }