35 'request.sent' => array(
'onRequestSent', 100),
36 'request.clone' =>
'cleanupRequest',
37 'request.before_send' =>
'cleanupRequest'
48 $params = $event[
'request']->getParams();
49 unset($params[self::REDIRECT_COUNT]);
50 unset($params[self::PARENT_REQUEST]);
60 $response = $event[
'response'];
61 $request = $event[
'request'];
64 if (!$response || $request->getParams()->get(self::DISABLE)) {
72 if (!$response->isRedirect() || !$response->hasHeader(
'Location')) {
73 if ($request !== $original) {
75 $response->getParams()->set(self::REDIRECT_COUNT, $original->getParams()->get(self::REDIRECT_COUNT));
76 $original->setResponse($response);
77 $response->setEffectiveUrl($request->getUrl());
96 while ($parent = $original->getParams()->get(self::PARENT_REQUEST)) {
118 RequestInterface $request,
123 $redirectRequest =
null;
124 $strict = $original->
getParams()->get(self::STRICT_REDIRECTS);
131 $redirectRequest = clone $request;
134 $redirectRequest->setIsRedirect(
true);
136 $redirectRequest->setResponseBody($request->getResponseBody());
140 if (!$location->isAbsolute()) {
141 $originalUrl = $redirectRequest->getUrl(
true);
143 $originalUrl->getQuery()->clear();
144 $location = $originalUrl->combine((
string) $location,
true);
147 $redirectRequest->setUrl($location);
150 $redirectRequest->getEventDispatcher()->addListener(
151 'request.before_send',
152 $func =
function ($e) use (&$func, $request, $redirectRequest) {
153 $redirectRequest->getEventDispatcher()->removeListener(
'request.before_send', $func);
160 $body = $redirectRequest->getBody();
162 if ($body->ftell() && !$body->rewind()) {
164 'Unable to rewind the non-seekable entity body of the request after redirecting. cURL probably '
165 .
'sent part of body before the redirect occurred. Try adding acustom rewind function using on the '
166 .
'entity body of the request using setRewindFunction().'
171 return $redirectRequest;
193 if ($current > $max) {
200 $response->getStatusCode(),
201 trim($response->getLocation()),
216 protected function sendRedirectRequest(RequestInterface $original, RequestInterface $request, Response $response)
221 $redirectRequest->send();
241 $original->getEventDispatcher()->addListener(
243 $func =
function ($e) use (&$func, $original, $max) {
244 $original->getEventDispatcher()->removeListener(
'request.complete', $func);
245 $str =
"{$max} redirects were issued for this request:\n" . $e[
'request']->getRawHeaders();