Make a request to a client

@param   string   $requestClientId  the client to send the request to
@param   Array    $payload          the payload to send to the client
@param   Closure  $handler          the reply handler
@return  void
338900
public function request($requestClientId, Array $payload, Closure $handler)
	{
		// generate a new requestId
		$requestId = $this->uuid();

		// store the handler
		$this->handlers[static::MESSAGE_TYPE_REPLY][$requestId] = $handler;

		$m = $this->bareMessage(static::MESSAGE_TYPE_REQUEST);
		$m->RequestClientId = $requestClientId;
		$m->RequestId = $requestId;
		$m->Payload = $payload;

		$this->send($m);
	}
390593
public function process(RequestInterface $request, HandlerInterface $handler)
    {
        $middleware = $this->callback;

        return $middleware($request, $handler);
    }
70542
public function setRequestTypeAndPayload($requestType, $payload = '')
    {
        if ($requestType != 'get') {
            if (!empty($payload)) $this->setOption(CURLOPT_POSTFIELDS, $payload);
            if ($requestType == 'post') {
                $this->setOption(CURLOPT_POST, true);
            }
            else {
                $this->setOption(CURLOPT_CUSTOMREQUEST, strtoupper($requestType));
            }
        }
        return $this;
    }
1210485
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $packer = service_packer();
        $data   = $request->getAttribute(self::ATTRIBUTE_DATA);
        $data   = $packer->unpack($data);

        // init data and trigger event
        App::trigger(RpcServerEvent::BEFORE_RECEIVE, null, $data);
        $request = $request->withAttribute(self::ATTRIBUTE_DATA, $data);

        /* @var \Swoft\Rpc\Server\Rpc\Response $response */
        $response      = $handler->handle($request);
        $serviceResult = $response->getAttribute(HandlerAdapter::ATTRIBUTE);
        $serviceResult = $packer->pack($serviceResult);

        return $response->withAttribute(HandlerAdapter::ATTRIBUTE, $serviceResult);
    }
1052695
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        /* @var \Swoft\Http\Server\Parser\RequestParserInterface $requestParser */
        $requestParser = App::getBean('requestParser');
        $request       = $requestParser->parse($request);

        return $handler->handle($request);
    }
858751
protected function acceptConnection($server, $request, $httpRequest, $handler)
    {
        $id = $request->fd;

        $connection = $this->createWebSocketConnection($server, $id);

        $this->fireOpenEvent($handler, $connection, $httpRequest);

        $this->connections[$id] = compact('connection', 'handler');
    }
2697
protected function dispatchRoute(
        RouteHandlerInterface $handler,
        ServerRequestInterface $request,
        Closure $next = null
    ): ResponseInterface {
        // callback that will be passed to the route handler call, as last argument.
        $handlerNext = $next ? function ($newRequest = null) use ($next, $request) {
            return $next($newRequest instanceof ServerRequestInterface ? $newRequest : $request);
        } :
            function () {
                // noop
            };
        return $handler($handlerNext);
    }
1145100
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $httpHandler = $request->getAttribute(AttributeEnum::ROUTER_ATTRIBUTE);
        $info = $httpHandler[2];

        $actionMiddlewares = [];
        if (isset($info['handler']) && \is_string($info['handler'])) {
            // Extract action info from router handler
            $exploded             = explode('@', $info['handler']);
            $controllerClass      = $exploded[0] ?? '';
            $action               = $exploded[1] ?? '';

            $collector = MiddlewareCollector::getCollector();
            $collectedMiddlewares = $collector[$controllerClass]['middlewares']??[];

            // Get group middleware from Collector
            if ($controllerClass) {
                $collect = $collectedMiddlewares['group'] ?? [];
                $collect && $actionMiddlewares = array_merge($actionMiddlewares, $collect);
            }
            // Get the specified action middleware from Collector
            if ($action) {
                $collect = $collectedMiddlewares['actions'][$action]??[];
                $collect && $actionMiddlewares = array_merge($actionMiddlewares, $collect ?? []);
            }
        }
        if (!empty($actionMiddlewares) && $handler instanceof RequestHandler) {
            $handler->insertMiddlewares($actionMiddlewares);
        }

        return $handler->handle($request);
    }
868946
protected function executeRequest(array $httpHeaders, $requestUrl, $httpMethod, $payload)
    {
        $result = [];

        $ch = curl_init($requestUrl);
        curl_setopt_array($ch, [
            CURLOPT_HTTPHEADER => $httpHeaders,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_SSL_VERIFYHOST => 0,
        ]);

        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $httpMethod);

        // Only send payload data for methods that need it.
        if ($payload instanceof Payload) {
            // Send payload data as a JSON string
            curl_setopt($ch, CURLOPT_POSTFIELDS, $payload->getPayloadJSON());
        }

        // Set response data
        $result['response'] = curl_exec($ch);
        // Set response code
        $result['http_code'] = curl_getinfo($ch, CURLINFO_HTTP_CODE);

        // Check if any related Curl error occurred.
        if (curl_error($ch)) {
            throw new RequestException(curl_error($ch));
        }

        // Close the session
        curl_close($ch);

        return $result;
    }
341079
function post($payload)
    {
        $this->requestDecorator->setPayload($payload);
        $result = $this->client->post($this->requestDecorator->makeResource(), $this->requestDecorator->makePayload(), $this->requestDecorator->makeHeaders());
        $this->refresh();
        return $result;
    }
845207
protected function createRequest($method, $payload = [])
    {
        $this->setMockResponses();
        $this->setupHttpClientSettings();

        $this->request = $this->httpClient->createRequest($method, $this->environment, ['json' => $payload]);

        $this->setRequestFullPath();
        $this->setRequestQueryString();

        return $this->send();
    }
1266605
public static function forRequest(Request $request, RequestHandler $handler, string $message = ''): self
    {
        return new static(
            sprintf(
                'The request [%s] could not be handled by [%s].  %s',
                $request::schema()->getId()->toString(),
                get_class($handler),
                $message
            ),
            Code::INTERNAL
        );
    }
405431
protected function handleReply($message)
	{
		// if we dont have a handler for this request, then something is wrong
		if (!array_key_exists($message->RequestId, $this->handlers[static::MESSAGE_TYPE_REPLY]))
		{
			throw new ClientException("Request handler not found");
		}

		// handle the event
		$this->handlers[static::MESSAGE_TYPE_REPLY][$message->RequestId]($message);

		// cleanup the handler, as it is no longer needed
		unset($this->handlers[static::MESSAGE_TYPE_REPLY][$message->RequestId]);
	}
1015068
private function invokeCallback ( Request $request, $handler ) {
      try {
        return call_user_func_array( $handler, array( $this, $request ) );
      } catch ( \Exception $ex ) {
        $this->exception = $ex;
        return call_user_func_array( $this->onException, array( $this, $request ) );
      }
    }
101018
public function queueRequest($handle, $url, $callback)
    {
        if (!is_resource(self::$queue_handle)) {
            self::initQueue();
        }

        self::$request_queue[] = array(
            'url'       => $url,
            'handle'    => $handle,
            'callback'  => $callback,
            'response'  => '',
        );
        curl_multi_add_handle(self::$queue_handle, $handle);
    }
350349
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        /* @var ValidatorInterface $validator */
        $serviceHandler = $request->getAttribute(RouterMiddleware::ATTRIBUTE);
        $serviceData    = $request->getAttribute(PackerMiddleware::ATTRIBUTE_DATA);
        $validator      = App::getBean(ServiceValidator::class);

        list($className, $validatorKey) = $serviceHandler;
        $collector = ValidatorCollector::getCollector();
        if (isset($collector[$className][$validatorKey]['validator'])) {
            $validators = $collector[$className][$validatorKey]['validator'];
            $validator->validate($validators, $serviceHandler, $serviceData);
        }

        return $handler->handle($request);
    }
682860
public static function make($handler)
    {
        //No handler specified
        if (!$handler) {
            return new DropboxGuzzleHttpClient();
        }

        //Custom Implementation, maybe.
        if ($handler instanceof DropboxHttpClientInterface) {
            return $handler;
        }

        //Handler is a custom configured Guzzle Client
        if ($handler instanceof Guzzle) {
            return new DropboxGuzzleHttpClient($handler);
        }

        //Invalid handler
        throw new InvalidArgumentException('The http client handler must be an instance of GuzzleHttp\Client or an instance of Kunnu\Dropbox\Http\Clients\DropboxHttpClientInterface.');
    }