/usr/share/php/Sabre/HTTP/Request.php is in php-sabre-http 2.0.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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | <?php
namespace Sabre\HTTP;
/**
* The Request class represents a single HTTP request.
*
* You can either simply construct the object from scratch, or if you need
* access to the current HTTP request, use Sapi::getRequest.
*
* @copyright Copyright (C) 2009-2014 fruux GmbH (https://fruux.com/).
* @author Evert Pot (http://evertpot.com/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Request extends Message implements RequestInterface {
/**
* HTTP Method
*
* @var string
*/
protected $method;
/**
* Request Url
*
* @var string
*/
protected $url;
/**
* Creates the request object
*
* @param string $method
* @param string $url
* @param array $headers
* @param resource $body
*/
public function __construct($method = null, $url = null, array $headers = null, $body = null) {
if (!is_null($method)) $this->setMethod($method);
if (!is_null($url)) $this->setUrl($url);
if (!is_null($headers)) $this->setHeaders($headers);
if (!is_null($body)) $this->setBody($body);
}
/**
* Returns the current HTTP method
*
* @return string
*/
public function getMethod() {
return $this->method;
}
/**
* Sets the HTTP method
*
* @param string $method
* @return void
*/
public function setMethod($method) {
$this->method = $method;
}
/**
* Returns the request url.
*
* @return string
*/
public function getUrl() {
return $this->url;
}
/**
* Sets the request url.
*
* @param string $url
* @return void
*/
public function setUrl($url) {
$this->url = $url;
}
/**
* Returns the list of query parameters.
*
* This is equivalent to PHP's $_GET superglobal.
*
* @return array
*/
public function getQueryParameters() {
$url = $this->getUrl();
if (($index = strpos($url,'?'))===false) {
return [];
} else {
parse_str(substr($url, $index+1), $queryParams);
return $queryParams;
}
}
/**
* Sets the absolute url.
*
* @param string $url
* @return void
*/
public function setAbsoluteUrl($url) {
$this->absoluteUrl = $url;
}
/**
* Returns the absolute url.
*
* @return string
*/
public function getAbsoluteUrl() {
return $this->absoluteUrl;
}
/**
* Base url
*
* @var string
*/
protected $baseUrl = '/';
/**
* Sets a base url.
*
* This url is used for relative path calculations.
*
* @param string $url
* @return void
*/
public function setBaseUrl($url) {
$this->baseUrl = $url;
}
/**
* Returns the current base url.
*
* @return string
*/
public function getBaseUrl() {
return $this->baseUrl;
}
/**
* Returns the relative path.
*
* This is being calculated using the base url. This path will not start
* with a slash, so it will always return something like
* 'example/path.html'.
*
* If the full path is equal to the base url, this method will return an
* empty string.
*
* This method will also urldecode the path, and if the url was incoded as
* ISO-8859-1, it will convert it to UTF-8.
*
* If the path is outside of the base url, a LogicException will be thrown.
*
* @return string
*/
public function getPath() {
// Removing duplicated slashes.
$uri = str_replace('//','/',$this->getUrl());
if (strpos($uri,$this->getBaseUrl())===0) {
// We're not interested in the query part (everything after the ?).
list($uri) = explode('?', $uri);
return trim(URLUtil::decodePath(substr($uri,strlen($this->getBaseUrl()))),'/');
// A special case, if the baseUri was accessed without a trailing
// slash, we'll accept it as well.
} elseif ($uri.'/' === $this->getBaseUrl()) {
return '';
} else {
throw new \LogicException('Requested uri (' . $this->getUrl() . ') is out of base uri (' . $this->getBaseUrl() . ')');
}
}
/**
* Equivalent of PHP's $_POST.
*
* @var array
*/
protected $postData = [];
/**
* Sets the post data.
*
* This is equivalent to PHP's $_POST superglobal.
*
* This would not have been needed, if POST data was accessible as
* php://input, but unfortunately we need to special case it.
*
* @param array $postData
* @return void
*/
public function setPostData(array $postData) {
$this->postData = $postData;
}
/**
* Returns the POST data.
*
* This is equivalent to PHP's $_POST superglobal.
*
* @return array
*/
public function getPostData() {
return $this->postData;
}
/**
* An array containing the raw _SERVER array.
*
* @var array
*/
protected $rawServerData;
/**
* Returns an item from the _SERVER array.
*
* If the value does not exist in the array, null is returned.
*
* @param string $valueName
* @return string|null
*/
public function getRawServerValue($valueName) {
if (isset($this->rawServerData[$valueName])) {
return $this->rawServerData[$valueName];
}
}
/**
* Sets the _SERVER array.
*
* @param array $data
* @return void
*/
public function setRawServerData(array $data) {
$this->rawServerData = $data;
}
/**
* Serializes the request object as a string.
*
* This is useful for debugging purposes.
*
* @return string
*/
public function __toString() {
$str = $this->getMethod() . ' ' . $this->getUrl() . ' HTTP/' . $this->getHTTPVersion() . "\r\n";
foreach($this->getHeaders() as $key=>$value) {
$str.= $key . ": " . $value . "\r\n";
}
$str.="\r\n";
$str.=$this->getBodyAsString();
return $str;
}
}
|