/usr/share/php/kohana3.1/system/classes/kohana/request/client/http.php is in libkohana3.1-core-php 3.1.5-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | <?php defined('SYSPATH') or die('No direct script access.');
/**
* [Request_Client_External] HTTP driver performs external requests using the
* php-http extention. To use this driver, ensure the following is completed
* before executing an external request- ideally in the application bootstrap.
*
* @example
*
* // In application bootstrap
* Request_Client_External::$client = 'Request_Client_HTTP';
*
* @package Kohana
* @category Base
* @author Kohana Team
* @copyright (c) 2008-2011 Kohana Team
* @license http://kohanaframework.org/license
* @uses [PECL HTTP](http://php.net/manual/en/book.http.php)
*/
class Kohana_Request_Client_HTTP extends Request_Client_External {
/**
* Creates a new `Request_Client` object,
* allows for dependency injection.
*
* @param array $params Params
* @throws Request_Exception
*/
public function __construct(array $params = array())
{
// Check that PECL HTTP supports requests
if ( ! http_support(HTTP_SUPPORT_REQUESTS))
{
throw new Request_Exception('Need HTTP request support!');
}
// Carry on
parent::__construct($params);
}
/**
* @var array curl options
* @see [http://www.php.net/manual/en/function.curl-setopt.php]
*/
protected $_options = array();
/**
* Sends the HTTP message [Request] to a remote server and processes
* the response.
*
* @param Request request to send
* @return Response
*/
public function _send_message(Request $request)
{
$http_method_mapping = array(
HTTP_Request::GET => HTTPRequest::METH_GET,
HTTP_Request::HEAD => HTTPRequest::METH_HEAD,
HTTP_Request::POST => HTTPRequest::METH_POST,
HTTP_Request::PUT => HTTPRequest::METH_PUT,
HTTP_Request::DELETE => HTTPRequest::METH_DELETE,
HTTP_Request::OPTIONS => HTTPRequest::METH_OPTIONS,
HTTP_Request::TRACE => HTTPRequest::METH_TRACE,
HTTP_Request::CONNECT => HTTPRequest::METH_CONNECT,
);
// Create an http request object
$http_request = new HTTPRequest($request->uri(), $http_method_mapping[$request->method()]);
if ($this->_options)
{
// Set custom options
$http_request->setOptions($this->_options);
}
// Set headers
$http_request->setHeaders($request->headers()->getArrayCopy());
// Set cookies
$http_request->setCookies($request->cookie());
// Set query data (?foo=bar&bar=foo)
$http_request->setQueryData($request->query());
// Set the body
if ($request->method() == HTTP_Request::PUT)
{
$http_request->addPutData($request->body());
}
else
{
$http_request->setBody($request->body());
}
try
{
$http_request->send();
}
catch (HTTPRequestException $e)
{
throw new Request_Exception($e->getMessage());
}
catch (HTTPMalformedHeaderException $e)
{
throw new Request_Exception($e->getMessage());
}
catch (HTTPEncodingException $e)
{
throw new Request_Exception($e->getMessage());
}
// Create the response
$response = $request->create_response();
// Build the response
$response->status($http_request->getResponseCode())
->headers($http_request->getResponseHeader())
->cookie($http_request->getResponseCookies())
->body($http_request->getResponseBody());
return $response;
}
} // End Kohana_Request_Client_HTTP
|