/** * Assigns the properties of the current Request_Client to another * Request_Client instance - used when setting up a subsequent request. * * @param Request_Client $client */ public function assign_client_properties(Request_Client $client) { $client->cache($this->cache()); $client->follow($this->follow()); $client->follow_headers($this->follow_headers()); $client->header_callbacks($this->header_callbacks()); $client->max_callback_depth($this->max_callback_depth()); $client->callback_params($this->callback_params()); }
/** * The default handler for following redirects, triggered by the presence of * a Location header in the response. * * The client's follow property must be set TRUE and the HTTP response status * one of 201, 301, 302, 303 or 307 for the redirect to be followed. * * @param Request $request * @param Response $response * @param Request_Client $client */ public static function on_header_location(Request $request, Response $response, Request_Client $client) { // Do we need to follow a Location header ? if ($client->follow() and in_array($response->status(), array(201, 301, 302, 303, 307))) { // Figure out which method to use for the follow request switch ($response->status()) { default: case 301: case 307: $follow_method = $request->method(); break; case 201: case 303: $follow_method = Request::GET; break; case 302: // Cater for sites with broken HTTP redirect implementations if ($client->strict_redirect()) { $follow_method = $request->method(); } else { $follow_method = Request::GET; } break; } // Prepare the additional request, copying any follow_headers that were present on the original request $orig_headers = $request->headers()->getArrayCopy(); $follow_header_keys = array_intersect(array_keys($orig_headers), $client->follow_headers()); $follow_headers = \Arr::extract($orig_headers, $follow_header_keys); $follow_request = Request::factory($response->headers('Location'))->method($follow_method)->headers($follow_headers); if ($follow_method !== Request::GET) { $follow_request->body($request->body()); } return $follow_request; } return NULL; }
public static function on_header_location(Request $request, Response $response, Request_Client $client) { if ($client->follow() and in_array($response->status(), array(201, 301, 302, 303, 307))) { switch ($response->status()) { default: case 301: case 307: $follow_method = $request->method(); break; case 201: case 303: $follow_method = Request::GET; break; case 302: if ($client->strict_redirect()) { $follow_method = $request->method(); } else { $follow_method = Request::GET; } break; } $orig_headers = $request->headers()->getArrayCopy(); $follow_header_keys = array_intersect(array_keys($orig_headers), $client->follow_headers()); $follow_headers = \Arr::extract($orig_headers, $follow_header_keys); $follow_request = Request::factory($response->headers("Location"))->method($follow_method)->headers($follow_headers); if ($follow_method !== Request::GET) { $follow_request->body($request->body()); } return $follow_request; } return NULL; }