MediaWiki  master
MediaWiki\Rest\ConditionalHeaderUtil Class Reference

Public Member Functions

 applyResponseHeaders (ResponseInterface $response)
 Set Last-Modified and ETag headers in the response according to the cached values set by setValidators(), which are also used for precondition checks. More...
 
 checkPreconditions (RequestInterface $request)
 Check conditional request headers in the order required by RFC 7232 section 6. More...
 
 setValidators ( $eTag, $lastModified, $hasRepresentation)
 Initialize the object with information about the requested resource. More...
 
 setVarnishETagHack ( $hack)
 If the Varnish ETag hack is disabled by calling this method, strong ETag comparison will follow RFC 7232, rejecting all weak ETags for If-Match comparison. More...
 

Private Member Functions

 strongCompare ( $resourceETag, $headerETag)
 The strong comparison function. More...
 
 weakCompare ( $resourceETag, $headerETag)
 The weak comparison function, per RFC 7232, section 2.3.2. More...
 

Private Attributes

 $eTag
 
 $hasRepresentation
 
 $lastModified
 
 $validatorsHaveBeenSet = false
 
 $varnishETagHack = true
 

Detailed Description

Definition at line 9 of file ConditionalHeaderUtil.php.

Member Function Documentation

◆ applyResponseHeaders()

MediaWiki\Rest\ConditionalHeaderUtil::applyResponseHeaders ( ResponseInterface  $response)

Set Last-Modified and ETag headers in the response according to the cached values set by setValidators(), which are also used for precondition checks.

If the headers are already present in the response, the existing headers take precedence.

Parameters
ResponseInterface$response

Definition at line 136 of file ConditionalHeaderUtil.php.

References MediaWiki\Rest\HeaderParser\HttpDate\format(), MediaWiki\Rest\ResponseInterface\hasHeader(), and MediaWiki\Rest\ResponseInterface\setHeader().

◆ checkPreconditions()

MediaWiki\Rest\ConditionalHeaderUtil::checkPreconditions ( RequestInterface  $request)

Check conditional request headers in the order required by RFC 7232 section 6.

Parameters
RequestInterface$request
Returns
int|null The status code to immediately return, or null to continue processing the request.

Definition at line 62 of file ConditionalHeaderUtil.php.

References MediaWiki\Rest\RequestInterface\getHeader(), MediaWiki\Rest\RequestInterface\getMethod(), MediaWiki\Rest\RequestInterface\hasHeader(), MediaWiki\Rest\HeaderParser\HttpDate\parse(), MediaWiki\Rest\HeaderParser\IfNoneMatch\parseETag(), MediaWiki\Rest\ConditionalHeaderUtil\strongCompare(), and MediaWiki\Rest\ConditionalHeaderUtil\weakCompare().

◆ setValidators()

MediaWiki\Rest\ConditionalHeaderUtil::setValidators (   $eTag,
  $lastModified,
  $hasRepresentation 
)

Initialize the object with information about the requested resource.

Parameters
string | null$eTagThe entity-tag (including quotes), or null if it is unknown.
string | int | null$lastModifiedThe Last-Modified date in a format accepted by ConvertibleTimestamp, or null if it is unknown.
bool | null$hasRepresentationWhether the server has a current representation of the target resource. This should be true if the resource exists, and false if it does not exist. It is used for wildcard validators – the intended use case is to abort a PUT if the resource does (or does not) exist. If null is passed, we assume that the resource exists if an ETag was specified for it.

Definition at line 30 of file ConditionalHeaderUtil.php.

References MediaWiki\Rest\ConditionalHeaderUtil\$eTag, MediaWiki\Rest\ConditionalHeaderUtil\$hasRepresentation, and MediaWiki\Rest\ConditionalHeaderUtil\$lastModified.

Referenced by MediaWiki\Rest\Handler\getConditionalHeaderUtil().

◆ setVarnishETagHack()

MediaWiki\Rest\ConditionalHeaderUtil::setVarnishETagHack (   $hack)

If the Varnish ETag hack is disabled by calling this method, strong ETag comparison will follow RFC 7232, rejecting all weak ETags for If-Match comparison.

Parameters
bool$hack

Definition at line 51 of file ConditionalHeaderUtil.php.

◆ strongCompare()

MediaWiki\Rest\ConditionalHeaderUtil::strongCompare (   $resourceETag,
  $headerETag 
)
private

The strong comparison function.

A strong ETag returned by the server may have been "weakened" by Varnish when applying compression. So optionally ignore the weakness of the header. https://varnish-cache.org/docs/6.0/users-guide/compression.html.

See also
T238849 and T310710
Parameters
array | null$resourceETagETag generated by the handler, parsed tag info array
array | null$headerETagETag supplied by the client, parsed tag info array
Returns
bool

Definition at line 172 of file ConditionalHeaderUtil.php.

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

◆ weakCompare()

MediaWiki\Rest\ConditionalHeaderUtil::weakCompare (   $resourceETag,
  $headerETag 
)
private

The weak comparison function, per RFC 7232, section 2.3.2.

Parameters
array | null$resourceETagETag generated by the handler, parsed tag info array
array | null$headerETagETag supplied by the client, parsed tag info array
Returns
bool

Definition at line 152 of file ConditionalHeaderUtil.php.

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

Member Data Documentation

◆ $eTag

MediaWiki\Rest\ConditionalHeaderUtil::$eTag
private

◆ $hasRepresentation

MediaWiki\Rest\ConditionalHeaderUtil::$hasRepresentation
private

◆ $lastModified

MediaWiki\Rest\ConditionalHeaderUtil::$lastModified
private

◆ $validatorsHaveBeenSet

MediaWiki\Rest\ConditionalHeaderUtil::$validatorsHaveBeenSet = false
private

Definition at line 10 of file ConditionalHeaderUtil.php.

◆ $varnishETagHack

MediaWiki\Rest\ConditionalHeaderUtil::$varnishETagHack = true
private

Definition at line 11 of file ConditionalHeaderUtil.php.


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