MediaWiki REL1_40
MediaWiki\Rest\HeaderParser\HttpDate Class Reference

This is a parser for "HTTP-date" as defined by RFC 7231. More...

Inherits MediaWiki\Rest\HeaderParser\HeaderParserBase.

Collaboration diagram for MediaWiki\Rest\HeaderParser\HttpDate:

Static Public Member Functions

static format ( $unixTime)
 A convenience function to convert a UNIX timestamp to the preferred IMF-fixdate format for HTTP header output.
 
static parse ( $dateString)
 Parse an HTTP-date string.
 

Additional Inherited Members

- Protected Member Functions inherited from MediaWiki\Rest\HeaderParser\HeaderParserBase
 assertEnd ()
 If the position is not at the end of the input string, raise an error, complaining of trailing characters.
 
 consumeFixedDigits ( $numDigits)
 Consume a specified number of digits, or throw an exception.
 
 consumeString ( $s)
 Consume a specified string, or throw an exception.
 
 error ( $message)
 Throw an exception to indicate a parse error.
 
 setInput ( $input)
 Set the input, and derived convenience properties.
 
 skipWhitespace ()
 Skip whitespace at the input position (OWS)
 
- Protected Attributes inherited from MediaWiki\Rest\HeaderParser\HeaderParserBase
string $input
 The input string being processed.
 
int $inputLength
 The length of $input.
 
int $pos
 The position within $input.
 

Detailed Description

This is a parser for "HTTP-date" as defined by RFC 7231.

Normally in MediaWiki, dates in HTTP headers are converted using ConvertibleTimestamp or strtotime(), and this is encouraged by RFC 7231:

"Recipients of timestamp values are encouraged to be robust in parsing timestamps unless otherwise restricted by the field definition."

In the case of If-Modified-Since, we are in fact otherwise restricted, since RFC 7232 says:

"A recipient MUST ignore the If-Modified-Since header field if the received field-value is not a valid HTTP-date"

So it is not correct to use strtotime() or ConvertibleTimestamp to parse If-Modified-Since.

Definition at line 23 of file HttpDate.php.

Member Function Documentation

◆ format()

static MediaWiki\Rest\HeaderParser\HttpDate::format ( $unixTime)
static

A convenience function to convert a UNIX timestamp to the preferred IMF-fixdate format for HTTP header output.

Parameters
int$unixTime
Returns
false|string

Definition at line 96 of file HttpDate.php.

Referenced by MediaWiki\Rest\ConditionalHeaderUtil\applyResponseHeaders().

◆ parse()

static MediaWiki\Rest\HeaderParser\HttpDate::parse ( $dateString)
static

Parse an HTTP-date string.

Parameters
string$dateString
Returns
int|null The UNIX timestamp, or null if the date was invalid

Definition at line 80 of file HttpDate.php.

Referenced by MediaWiki\Rest\ConditionalHeaderUtil\checkPreconditions().


The documentation for this class was generated from the following file: