Lines Matching refs:request
11 * Creates curl resources from a request
19 * @param array $request Request hash
26 public function __invoke(array $request, $handle = null)
29 $options = $this->getDefaultOptions($request, $headers);
30 $this->applyMethod($request, $options);
32 if (isset($request['client'])) {
33 $this->applyHandlerOptions($request, $options);
36 $this->applyHeaders($request, $options);
39 // Add handler options from the request's configuration options
40 if (isset($request['client']['curl'])) {
42 $request['client']['curl'],
51 $body = $this->getOutputBody($request, $options);
61 * @param array $request Request that sent.
70 array $request,
91 ? self::createErrorResponse($handler, $request, $response)
97 array $request,
113 return self::retryFailedRewind($handler, $request, $response);
138 private function getOutputBody(array $request, array &$options)
142 return $request['client']['save_to'];
149 if ($request['http_method'] != 'HEAD') {
157 private function getDefaultOptions(array $request, array &$headers)
159 $url = Core::url($request);
163 '_headers' => $request['headers'],
164 CURLOPT_CUSTOMREQUEST => $request['http_method'],
183 if (isset($request['version'])) {
184 if ($request['version'] == 2.0) {
186 } else if ($request['version'] == 1.1) {
200 private function applyMethod(array $request, array &$options)
202 if (isset($request['body'])) {
203 $this->applyBody($request, $options);
207 switch ($request['http_method']) {
211 if (!Core::hasHeader($request, 'Content-Length')) {
226 private function applyBody(array $request, array &$options)
228 $contentLength = Core::firstHeader($request, 'Content-Length');
232 // [client][curl][body_as_string] request value is set.
234 isset($request['client']['curl']['body_as_string']) ||
235 is_string($request['body'])
237 $options[CURLOPT_POSTFIELDS] = Core::body($request);
248 $this->addStreamingBody($request, $options);
252 if (!Core::hasHeader($request, 'Expect')) {
257 if (!Core::hasHeader($request, 'Content-Type')) {
262 private function addStreamingBody(array $request, array &$options)
264 $body = $request['body'];
289 throw new \InvalidArgumentException('Invalid request body provided');
293 private function applyHeaders(array $request, array &$options)
302 if (!Core::hasHeader($request, 'Accept')) {
309 * request's configuration array and maps them to CURLOPT_* options.
311 * This method is only called when a request has a 'curl' config setting.
347 * Applies an array of request client options to a the options array.
352 private function applyHandlerOptions(array $request, array &$options)
354 foreach ($request['client'] as $key => $value) {
385 $accept = Core::firstHeader($request, 'Accept-Encoding');
443 } elseif (isset($request['scheme'])) {
444 $scheme = $request['scheme'];
516 * was not set, then the request is retried if possible. This error
520 * error, causing the request to be sent through curl_multi_info_read()
525 array $request,
530 if (!isset($request['body'])) {
531 $response['err_message'] = 'No response was received for a request '
534 return self::createErrorResponse($handler, $request, $response);
537 if (!Core::rewindBody($request)) {
539 . 'without providing an error. The request would have been '
540 . 'retried, but attempting to rewind the request body failed.';
541 return self::createErrorResponse($handler, $request, $response);
545 if (!isset($request['curl']['retries'])) {
546 $request['curl']['retries'] = 1;
547 } elseif ($request['curl']['retries'] == 2) {
548 $response['err_message'] = 'The cURL request was retried 3 times '
550 . 'the request and subsequent retries resulted in the same '
553 return self::createErrorResponse($handler, $request, $response);
555 $request['curl']['retries']++;
558 return $handler($request);