ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Sabre\HTTP Namespace Reference

Namespaces

namespace  Auth
 

Data Structures

class  Client
 A rudimentary HTTP client. More...
 
class  ClientException
 This exception may be emitted by the HTTP\Client class, in case there was a problem emitting the request. More...
 
class  ClientHttpException
 This exception represents a HTTP error coming from the Client. More...
 
class  ClientMock
 
class  ClientTest
 
class  FunctionsTest
 
interface  HttpException
 An exception representing a HTTP error. More...
 
class  Message
 This is the abstract base class for both the Request and Response objects. More...
 
class  MessageDecoratorTest
 
interface  MessageInterface
 The MessageInterface is the base interface that's used by both the RequestInterface and ResponseInterface. More...
 
class  MessageMock
 
class  MessageTest
 
class  Request
 The Request class represents a single HTTP request. More...
 
class  RequestDecorator
 Request Decorator. More...
 
class  RequestDecoratorTest
 
interface  RequestInterface
 The RequestInterface represents a HTTP request. More...
 
class  RequestTest
 
class  Response
 This class represents a single HTTP response. More...
 
class  ResponseDecorator
 Response Decorator. More...
 
class  ResponseDecoratorTest
 
interface  ResponseInterface
 This interface represents a HTTP response. More...
 
class  ResponseMock
 HTTP Response Mock object. More...
 
class  ResponseTest
 
class  Sapi
 PHP SAPI. More...
 
class  SapiMock
 HTTP Response Mock object. More...
 
class  SapiTest
 
class  URLUtil
 URL utility class. More...
 
class  URLUtilTest
 
class  Util
 HTTP utility methods. More...
 
class  UtilTest
 
class  Version
 This class contains the version number for the HTTP package. More...
 

Functions

 parseDate ($dateString)
 A collection of useful helpers for parsing or generating various HTTP headers. More...
 
 toDate (DateTime $dateTime)
 Transforms a DateTime object to a valid HTTP/1.1 Date header value. More...
 
 negotiateContentType ($acceptHeaderValue, array $availableOptions)
 This function can be used to aid with content negotiation. More...
 
 parsePrefer ($input)
 Parses the Prefer header, as defined in RFC7240. More...
 
 getHeaderValues ($values, $values2=null)
 This method splits up headers into all their individual values. More...
 
 parseMimeType ($str)
 Parses a mime-type and splits it into: More...
 
 encodePath ($path)
 Encodes the path of a url. More...
 
 encodePathSegment ($pathSegment)
 Encodes a 1 segment of a path. More...
 
 decodePath ($path)
 Decodes a url-encoded path. More...
 
 decodePathSegment ($path)
 Decodes a url-encoded path segment. More...
 
 getBodyAsStream ()
 Returns the body as a readable stream resource. More...
 
 getBodyAsString ()
 Returns the body as a string. More...
 
 getBody ()
 Returns the message body, as it's internal representation. More...
 
 setBody ($body)
 Updates the body resource with a new stream. More...
 
 getHeaders ()
 Returns all the HTTP headers as an array. More...
 
 hasHeader ($name)
 Will return true or false, depending on if a HTTP header exists. More...
 
 getHeader ($name)
 Returns a specific HTTP header, based on it's name. More...
 
 getHeaderAsArray ($name)
 Returns a HTTP header as an array. More...
 
 setHeader ($name, $value)
 Updates a HTTP header. More...
 
 setHeaders (array $headers)
 Sets a new set of HTTP headers. More...
 
 addHeader ($name, $value)
 Adds a HTTP header. More...
 
 addHeaders (array $headers)
 Adds a new set of HTTP headers. More...
 
 removeHeader ($name)
 Removes a HTTP header. More...
 
 setHttpVersion ($version)
 Sets the HTTP version. More...
 
 getHttpVersion ()
 Returns the HTTP version. More...
 

Variables

trait MessageDecoratorTrait
 This trait contains a bunch of methods, shared by both the RequestDecorator and the ResponseDecorator. More...
 

Function Documentation

◆ addHeader()

Sabre\HTTP\addHeader (   $name,
  $value 
)

Adds a HTTP header.

This method will not overwrite any existing HTTP header, but instead add another value. Individual values can be retrieved with getHeadersAsArray.

Parameters
string$name
string$value
Returns
void

Definition at line 189 of file MessageDecoratorTrait.php.

189 {
190
191 $this->inner->addHeader($name, $value);
192
193 }

References $name.

◆ addHeaders()

Sabre\HTTP\addHeaders ( array  $headers)

Adds a new set of HTTP headers.

Any existing headers will not be overwritten.

Parameters
array$headers
Returns
void

Definition at line 203 of file MessageDecoratorTrait.php.

203 {
204
205 $this->inner->addHeaders($headers);
206
207 }

◆ decodePath()

Sabre\HTTP\decodePath (   $path)

Decodes a url-encoded path.

Parameters
string$path
Returns
string

Definition at line 419 of file functions.php.

419 {
420
421 return decodePathSegment($path);
422
423}
$path
Definition: aliased.php:25
decodePathSegment($path)
Decodes a url-encoded path segment.
Definition: functions.php:431

References $path, and Sabre\HTTP\decodePathSegment().

+ Here is the call graph for this function:

◆ decodePathSegment()

Sabre\HTTP\decodePathSegment (   $path)

Decodes a url-encoded path segment.

Parameters
string$path
Returns
string

Definition at line 431 of file functions.php.

431 {
432
433 $path = rawurldecode($path);
434 $encoding = mb_detect_encoding($path, ['UTF-8', 'ISO-8859-1']);
435
436 switch ($encoding) {
437
438 case 'ISO-8859-1' :
439 $path = utf8_encode($path);
440
441 }
442
443 return $path;
444
445}

References $path.

Referenced by Sabre\HTTP\decodePath().

+ Here is the caller graph for this function:

◆ encodePath()

Sabre\HTTP\encodePath (   $path)

Encodes the path of a url.

slashes (/) are treated as path-separators.

Parameters
string$path
Returns
string

Definition at line 386 of file functions.php.

386 {
387
388 return preg_replace_callback('/([^A-Za-z0-9_\-\.~\‍(\‍)\/:@])/', function($match) {
389
390 return '%' . sprintf('%02x', ord($match[0]));
391
392 }, $path);
393
394}

References $path.

Referenced by Sabre\DAV\Xml\Property\LocalHref\__construct(), Sabre\CalDAV\Backend\PDO\getInvites(), and Sabre\DAV\Xml\Element\Response\xmlSerialize().

+ Here is the caller graph for this function:

◆ encodePathSegment()

Sabre\HTTP\encodePathSegment (   $pathSegment)

Encodes a 1 segment of a path.

Slashes are considered part of the name, and are encoded as %2f

Parameters
string$pathSegment
Returns
string

Definition at line 404 of file functions.php.

404 {
405
406 return preg_replace_callback('/([^A-Za-z0-9_\-\.~\‍(\‍):@])/', function($match) {
407
408 return '%' . sprintf('%02x', ord($match[0]));
409
410 }, $pathSegment);
411}

◆ getBody()

Sabre\HTTP\getBody ( )

Returns the message body, as it's internal representation.

This could be either a string or a stream.

Returns
resource|string

Definition at line 62 of file MessageDecoratorTrait.php.

62 {
63
64 return $this->inner->getBody();
65
66 }

◆ getBodyAsStream()

Sabre\HTTP\getBodyAsStream ( )

Returns the body as a readable stream resource.

Note that the stream may not be rewindable, and therefore may only be read once.

Returns
resource

Definition at line 35 of file MessageDecoratorTrait.php.

35 {
36
37 return $this->inner->getBodyAsStream();
38
39 }

◆ getBodyAsString()

Sabre\HTTP\getBodyAsString ( )

Returns the body as a string.

Note that because the underlying data may be based on a stream, this method could only work correctly the first time.

Returns
string

Definition at line 49 of file MessageDecoratorTrait.php.

49 {
50
51 return $this->inner->getBodyAsString();
52
53 }

Referenced by Sabre\HTTP\ClientTest\testParseCurlResult().

+ Here is the caller graph for this function:

◆ getHeader()

Sabre\HTTP\getHeader (   $name)

Returns a specific HTTP header, based on it's name.

The name must be treated as case-insensitive. If the header does not exist, this method must return null.

If a header appeared more than once in a HTTP request, this method will concatenate all the values with a comma.

Note that this not make sense for all headers. Some, such as Set-Cookie cannot be logically combined with a comma. In those cases you should use getHeaderAsArray().

Parameters
string$name
Returns
string|null

Definition at line 121 of file MessageDecoratorTrait.php.

121 {
122
123 return $this->inner->getHeader($name);
124
125 }

References $name.

◆ getHeaderAsArray()

Sabre\HTTP\getHeaderAsArray (   $name)

Returns a HTTP header as an array.

For every time the HTTP header appeared in the request or response, an item will appear in the array.

If the header did not exists, this method will return an empty array.

Parameters
string$name
Returns
string[]

Definition at line 138 of file MessageDecoratorTrait.php.

138 {
139
140 return $this->inner->getHeaderAsArray($name);
141
142 }

References $name.

◆ getHeaders()

Sabre\HTTP\getHeaders ( )

Returns all the HTTP headers as an array.

Every header is returned as an array, with one or more values.

Returns
array

Definition at line 87 of file MessageDecoratorTrait.php.

87 {
88
89 return $this->inner->getHeaders();
90
91 }

Referenced by Sabre\HTTP\ClientTest\testParseCurlResult().

+ Here is the caller graph for this function:

◆ getHeaderValues()

Sabre\HTTP\getHeaderValues (   $values,
  $values2 = null 
)

This method splits up headers into all their individual values.

A HTTP header may have more than one header, such as this: Cache-Control: private, no-store

Header values are always split with a comma.

You can pass either a string, or an array. The resulting value is always an array with each spliced value.

If the second headers argument is set, this value will simply be merged in. This makes it quicker to merge an old list of values with a new set.

Parameters
string | string[]$values
string | string[]$values2
Returns
string[]

Definition at line 301 of file functions.php.

301 {
302
303 $values = (array)$values;
304 if ($values2) {
305 $values = array_merge($values, (array)$values2);
306 }
307 foreach ($values as $l1) {
308 foreach (explode(',', $l1) as $l2) {
309 $result[] = trim($l2);
310 }
311 }
312 return $result;
313
314}
$result
$values

References $result, and $values.

Referenced by Sabre\HTTP\parsePrefer(), and Sabre\HTTP\FunctionsTest\testGetHeaderValues().

+ Here is the caller graph for this function:

◆ getHttpVersion()

Sabre\HTTP\getHttpVersion ( )

Returns the HTTP version.

Returns
string

Definition at line 245 of file MessageDecoratorTrait.php.

245 {
246
247 return $this->inner->getHttpVersion();
248
249 }

◆ hasHeader()

Sabre\HTTP\hasHeader (   $name)

Will return true or false, depending on if a HTTP header exists.

Parameters
string$name
Returns
bool

Definition at line 99 of file MessageDecoratorTrait.php.

99 {
100
101 return $this->inner->hasHeader($name);
102
103 }

References $name.

◆ negotiateContentType()

Sabre\HTTP\negotiateContentType (   $acceptHeaderValue,
array  $availableOptions 
)

This function can be used to aid with content negotiation.

It takes 2 arguments, the $acceptHeaderValue, which usually comes from an Accept header, and $availableOptions, which contains an array of items that the server can support.

The result of this function will be the 'best possible option'. If no best possible option could be found, null is returned.

When it's null you can according to the spec either return a default, or you can choose to emit 406 Not Acceptable.

The method also accepts sending 'null' for the $acceptHeaderValue, implying that no accept header was sent.

Parameters
string | null$acceptHeaderValue
array$availableOptions
Returns
string|null

Definition at line 107 of file functions.php.

107 {
108
109 if (!$acceptHeaderValue) {
110 // Grabbing the first in the list.
111 return reset($availableOptions);
112 }
113
114 $proposals = array_map(
115 'Sabre\HTTP\parseMimeType',
116 explode(',', $acceptHeaderValue)
117 );
118
119 // Ensuring array keys are reset.
120 $availableOptions = array_values($availableOptions);
121
122 $options = array_map(
123 'Sabre\HTTP\parseMimeType',
124 $availableOptions
125 );
126
127 $lastQuality = 0;
128 $lastSpecificity = 0;
129 $lastOptionIndex = 0;
130 $lastChoice = null;
131
132 foreach ($proposals as $proposal) {
133
134 // Ignoring broken values.
135 if (is_null($proposal)) continue;
136
137 // If the quality is lower we don't have to bother comparing.
138 if ($proposal['quality'] < $lastQuality) {
139 continue;
140 }
141
142 foreach ($options as $optionIndex => $option) {
143
144 if ($proposal['type'] !== '*' && $proposal['type'] !== $option['type']) {
145 // no match on type.
146 continue;
147 }
148 if ($proposal['subType'] !== '*' && $proposal['subType'] !== $option['subType']) {
149 // no match on subtype.
150 continue;
151 }
152
153 // Any parameters appearing on the options must appear on
154 // proposals.
155 foreach ($option['parameters'] as $paramName => $paramValue) {
156 if (!array_key_exists($paramName, $proposal['parameters'])) {
157 continue 2;
158 }
159 if ($paramValue !== $proposal['parameters'][$paramName]) {
160 continue 2;
161 }
162 }
163
164 // If we got here, we have a match on parameters, type and
165 // subtype. We need to calculate a score for how specific the
166 // match was.
167 $specificity =
168 ($proposal['type'] !== '*' ? 20 : 0) +
169 ($proposal['subType'] !== '*' ? 10 : 0) +
170 count($option['parameters']);
171
172
173 // Does this entry win?
174 if (
175 ($proposal['quality'] > $lastQuality) ||
176 ($proposal['quality'] === $lastQuality && $specificity > $lastSpecificity) ||
177 ($proposal['quality'] === $lastQuality && $specificity === $lastSpecificity && $optionIndex < $lastOptionIndex)
178 ) {
179
180 $lastQuality = $proposal['quality'];
181 $lastSpecificity = $specificity;
182 $lastOptionIndex = $optionIndex;
183 $lastChoice = $availableOptions[$optionIndex];
184
185 }
186
187 }
188
189 }
190
191 return $lastChoice;
192
193}

References PHPMailer\PHPMailer\$options.

◆ parseDate()

Sabre\HTTP\parseDate (   $dateString)

A collection of useful helpers for parsing or generating various HTTP headers.

Author
Evert Pot (http://evertpot.com/) @license http://sabre.io/license/ Modified BSD License Parses a HTTP date-string.

This method returns false if the date is invalid.

The following formats are supported: Sun, 06 Nov 1994 08:49:37 GMT ; IMF-fixdate Sunday, 06-Nov-94 08:49:37 GMT ; obsolete RFC 850 format Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format

See: http://tools.ietf.org/html/rfc7231#section-7.1.1.1

Parameters
string$dateString
Returns
bool|DateTime

Definition at line 32 of file functions.php.

32 {
33
34 // Only the format is checked, valid ranges are checked by strtotime below
35 $month = '(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)';
36 $weekday = '(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday)';
37 $wkday = '(Mon|Tue|Wed|Thu|Fri|Sat|Sun)';
38 $time = '([0-1]\d|2[0-3])(\:[0-5]\d){2}';
39 $date3 = $month . ' ([12]\d|3[01]| [1-9])';
40 $date2 = '(0[1-9]|[12]\d|3[01])\-' . $month . '\-\d{2}';
41 // 4-digit year cannot begin with 0 - unix timestamp begins in 1970
42 $date1 = '(0[1-9]|[12]\d|3[01]) ' . $month . ' [1-9]\d{3}';
43
44 // ANSI C's asctime() format
45 // 4-digit year cannot begin with 0 - unix timestamp begins in 1970
46 $asctime_date = $wkday . ' ' . $date3 . ' ' . $time . ' [1-9]\d{3}';
47 // RFC 850, obsoleted by RFC 1036
48 $rfc850_date = $weekday . ', ' . $date2 . ' ' . $time . ' GMT';
49 // RFC 822, updated by RFC 1123
50 $rfc1123_date = $wkday . ', ' . $date1 . ' ' . $time . ' GMT';
51 // allowed date formats by RFC 2616
52 $HTTP_date = "($rfc1123_date|$rfc850_date|$asctime_date)";
53
54 // allow for space around the string and strip it
55 $dateString = trim($dateString, ' ');
56 if (!preg_match('/^' . $HTTP_date . '$/', $dateString))
57 return false;
58
59 // append implicit GMT timezone to ANSI C time format
60 if (strpos($dateString, ' GMT') === false)
61 $dateString .= ' GMT';
62
63 try {
64 return new DateTime($dateString, new \DateTimeZone('UTC'));
65 } catch (\Exception $e) {
66 return false;
67 }
68
69}
$time
Definition: cron.php:21

References $time.

Referenced by Sabre\HTTP\Util\parseHTTPDate().

+ Here is the caller graph for this function:

◆ parseMimeType()

Sabre\HTTP\parseMimeType (   $str)

Parses a mime-type and splits it into:

  1. type
  2. subtype
  3. quality
  4. parameters
Parameters
string$str
Returns
array

Definition at line 327 of file functions.php.

327 {
328
329 $parameters = [];
330 // If no q= parameter appears, then quality = 1.
331 $quality = 1;
332
333 $parts = explode(';', $str);
334
335 // The first part is the mime-type.
336 $mimeType = array_shift($parts);
337
338 $mimeType = explode('/', trim($mimeType));
339 if (count($mimeType) !== 2) {
340 // Illegal value
341 return null;
342 }
343 list($type, $subType) = $mimeType;
344
345 foreach ($parts as $part) {
346
347 $part = trim($part);
348 if (strpos($part, '=')) {
349 list($partName, $partValue) =
350 explode('=', $part, 2);
351 } else {
352 $partName = $part;
353 $partValue = null;
354 }
355
356 // The quality parameter, if it appears, also marks the end of
357 // the parameter list. Anything after the q= counts as an
358 // 'accept extension' and could introduce new semantics in
359 // content-negotation.
360 if ($partName !== 'q') {
361 $parameters[$partName] = $part;
362 } else {
363 $quality = (float)$partValue;
364 break; // Stop parsing parts
365 }
366
367 }
368
369 return [
370 'type' => $type,
371 'subType' => $subType,
372 'quality' => $quality,
373 'parameters' => $parameters,
374 ];
375
376}
$type

References $type.

◆ parsePrefer()

Sabre\HTTP\parsePrefer (   $input)

Parses the Prefer header, as defined in RFC7240.

Input can be given as a single header value (string) or multiple headers (array of string).

This method will return a key->value array with the various Prefer parameters.

Prefer: return=minimal will result in:

[ 'return' => 'minimal' ]

Prefer: foo, wait=10 will result in:

[ 'foo' => true, 'wait' => '10']

This method also supports the formats from older drafts of RFC7240, and it will automatically map them to the new values, as the older values are still pretty common.

Parameters are currently discarded. There's no known prefer value that uses them.

Parameters
string | string[]$input
Returns
array

Definition at line 222 of file functions.php.

222 {
223
224 $token = '[!#$%&\'*+\-.^_`~A-Za-z0-9]+';
225
226 // Work in progress
227 $word = '(?: [a-zA-Z0-9]+ | "[a-zA-Z0-9]*" )';
228
229 $regex = <<<REGEX
230/
231^
232(?<name> $token) # Prefer property name
233\s* # Optional space
234(?: = \s* # Prefer property value
235 (?<value> $word)
236)?
237(?: \s* ; (?: .*))? # Prefer parameters (ignored)
238$
239/x
240REGEX;
241
242 $output = [];
243 foreach (getHeaderValues($input) as $value) {
244
245 if (!preg_match($regex, $value, $matches)) {
246 // Ignore
247 continue;
248 }
249
250 // Mapping old values to their new counterparts
251 switch ($matches['name']) {
252 case 'return-asynch' :
253 $output['respond-async'] = true;
254 break;
255 case 'return-representation' :
256 $output['return'] = 'representation';
257 break;
258 case 'return-minimal' :
259 $output['return'] = 'minimal';
260 break;
261 case 'strict' :
262 $output['handling'] = 'strict';
263 break;
264 case 'lenient' :
265 $output['handling'] = 'lenient';
266 break;
267 default :
268 if (isset($matches['value'])) {
269 $value = trim($matches['value'], '"');
270 } else {
271 $value = true;
272 }
273 $output[strtolower($matches['name'])] = empty($value) ? true : $value;
274 break;
275 }
276
277 }
278
279 return $output;
280
281}
getHeaderValues($values, $values2=null)
This method splits up headers into all their individual values.
Definition: functions.php:301

References $input, Sabre\VObject\$output, PHPMailer\PHPMailer\$token, and Sabre\HTTP\getHeaderValues().

Referenced by Sabre\DAV\Server\getHTTPPrefer(), and Sabre\HTTP\FunctionsTest\testPrefer().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeHeader()

Sabre\HTTP\removeHeader (   $name)

Removes a HTTP header.

The specified header name must be treated as case-insensitive. This method should return true if the header was successfully deleted, and false if the header did not exist.

Parameters
string$name
Returns
bool

Definition at line 220 of file MessageDecoratorTrait.php.

220 {
221
222 return $this->inner->removeHeader($name);
223
224 }

References $name.

◆ setBody()

Sabre\HTTP\setBody (   $body)

Updates the body resource with a new stream.

Parameters
resource$body
Returns
void

Definition at line 74 of file MessageDecoratorTrait.php.

74 {
75
76 $this->inner->setBody($body);
77
78 }

◆ setHeader()

Sabre\HTTP\setHeader (   $name,
  $value 
)

Updates a HTTP header.

The case-sensitivity of the name value must be retained as-is.

If the header already existed, it will be overwritten.

Parameters
string$name
string | string[]$value
Returns
void

Definition at line 155 of file MessageDecoratorTrait.php.

155 {
156
157 $this->inner->setHeader($name, $value);
158
159 }

References $name.

Referenced by ilPersonalProfileGUI\importPersonalData(), ilPersonalProfileGUI\importPersonalDataSelection(), Gettext\Translations\mergeWith(), Gettext\Translations\setDomain(), Gettext\Translations\setLanguage(), Gettext\Translations\setPluralForms(), ilPersonalProfileGUI\showExportImport(), and ilPersonalProfileGUI\showPublicProfile().

+ Here is the caller graph for this function:

◆ setHeaders()

Sabre\HTTP\setHeaders ( array  $headers)

Sets a new set of HTTP headers.

The headers array should contain headernames for keys, and their value should be specified as either a string or an array.

Any header that already existed will be overwritten.

Parameters
array$headers
Returns
void

Definition at line 172 of file MessageDecoratorTrait.php.

172 {
173
174 $this->inner->setHeaders($headers);
175
176 }

◆ setHttpVersion()

Sabre\HTTP\setHttpVersion (   $version)

Sets the HTTP version.

Should be 1.0 or 1.1.

Parameters
string$version
Returns
void

Definition at line 234 of file MessageDecoratorTrait.php.

234 {
235
236 $this->inner->setHttpVersion($version);
237
238 }
$version
Definition: build.php:27

References $version.

◆ toDate()

Sabre\HTTP\toDate ( DateTime  $dateTime)

Transforms a DateTime object to a valid HTTP/1.1 Date header value.

Parameters
DateTime$dateTime
Returns
string

Definition at line 77 of file functions.php.

77 {
78
79 // We need to clone it, as we don't want to affect the existing
80 // DateTime.
81 $dateTime = clone $dateTime;
82 $dateTime->setTimezone(new \DateTimeZone('GMT'));
83 return $dateTime->format('D, d M Y H:i:s \G\M\T');
84
85}

Referenced by Sabre\HTTP\Util\toHTTPDate().

+ Here is the caller graph for this function:

Variable Documentation

◆ MessageDecoratorTrait

trait Sabre::HTTP\MessageDecoratorTrait
Initial value:
{
protected $inner

This trait contains a bunch of methods, shared by both the RequestDecorator and the ResponseDecorator.

Didn't seem needed to create a full class for this, so we're just implementing it as a trait.

Author
Evert Pot (http://evertpot.com/) @license http://sabre.io/license/ Modified BSD License

Definition at line 16 of file MessageDecoratorTrait.php.