Commit graph

13 commits

Author SHA1 Message Date
Umherirrender
503bff0b04 Rest: Add missing documentation to class properties
Add doc-typehints to class properties found by the PropertyDocumentation
sniff to improve the documentation.

Once the sniff is enabled it avoids that new code is missing type
declarations. This is focused on documentation and does not change code.

Change-Id: Idf17719c875466810313f0fbbf16bc67f3e40059
2024-09-07 21:49:56 +02:00
thiemowmde
c7cb9d1a58 Rest: Reduce code duplication in ConditionalHeaderUtil
Change-Id: Ie02976fee5a0e7846b81c2450313659a2538e482
2024-09-02 07:24:10 +00:00
James D. Forrester
102a4f8a35 build: Upgrade mediawiki/mediawiki-phan-config from 0.13.0 to 0.14.0 manually
* Switch out raw Exceptions, mostly for InvalidArgumentExceptions.
  * Fake exceptions triggered to give Monolog a backtrace are for
    some reason "traditionally" RuntimeExceptions, instead, so we
    continue to use that pattern in remaining locations.
* Just entirely give up on PostgresResultWrapper's resource vs. object mess.
* Drop now-unneeded false positive hits.

Change-Id: Id183ab60994cd9c6dc80401d4ce4de0ddf2b3da0
2024-02-10 02:22:41 +00:00
James D. Forrester
67547915f3 Rest/HeaderParser: Give full context rather than simply Expected """
Also make the error thrown by ConditionalHeaderUtil slightly more
obvious where the upstream content ends and the context starts.

Bug: T350852
Change-Id: Ia76c0974487f151c3ca37fba2c666143bd435843
2024-01-30 11:27:47 -05:00
thiemowmde
8b49357b25 Replace some tivial ??= with even more trivial ??
Patch Ifa7a9bc replaced some longer `=== null` constructs with the
new ??= operator we have since PHP 7.4. However, some of these can be
simplified even more with the ?? operator we have since PHP 7.0.

Follow-Up: Ifa7a9bc7b2ec415ad7ecb23f4c1776f51f58fd6b
Change-Id: I7b05e723810558bb5437adc97eab54ca04d38c06
2022-12-23 08:35:44 +01:00
DannyS712
c1db64b808 Make use of ??= in more places
New feature from PHP 7.4

Change-Id: Ifa7a9bc7b2ec415ad7ecb23f4c1776f51f58fd6b
2022-12-17 01:10:13 +00:00
Jakob Warkotsch
64ddedb63d ConditionalHeaderUtil: Handle If-None-Match: *
The relevant section in the RFC says the following:

> If the field-value is "*", the condition is false if the origin
> server has a current representation for the target resource.
> An origin server that evaluates an If-None-Match condition MUST NOT
> perform the requested method if the condition evaluates to false;
> instead, the origin server MUST respond with either a) the 304 (Not
> Modified) status code if the request method is GET or HEAD or b) the
> 412 (Precondition Failed) status code for all other request methods.

https://httpwg.org/specs/rfc9110.html

Bug: T319382
Change-Id: Ieb3269d61de42242602ec9c46e19c4f2c3b37f6e
2022-10-07 09:06:04 +00:00
Jakob Warkotsch
c5bf89c2df Remove unused property in ConditionalHeaderUtil
Change-Id: I5d257d0e5b2cd8f3769e4f067f717f1ea72848a1
2022-10-06 17:29:28 +02:00
daniel
39b721667a REST: Allow weak ETags to match strong ETags.
This changes handling of the If-Match header so a weak ETag coming from
the client may match a strong ETag generated by the handler.

This is needed because ETags may get "weakened" on the way to the client
by proxies and middleware, e.g. Varnish applying compression, see
<https://varnish-cache.org/docs/6.0/users-guide/compression.html>.

This behavior is technically a violation of RFC 7232 section 3.1, but it
should actually be safe: A client sending a weak ETag is still ok with
getting a strong match, and a handler that generates a strong ETag knows
that it can rely on strong semantics holding, even if the tag sent by
the client is weak.

Bug: T310710
Bug: T238849
Change-Id: I2a604f2f46719a5f74ddac1b1fa58c8a36910240
2022-06-27 12:52:42 +00:00
Umherirrender
7bc9a4d3d0 Rest: Fix various scalar and null types
Change-Id: Ifb9a0c8faf6be1d6247d610e9f32dbbb5e4d0acd
2022-03-09 20:36:23 +00:00
Umherirrender
9efd9ca45e Add explicit casts between scalar types
* Some functions accept only string, cast ints and floats to string
* After preg_matches or explode() casts numbers to int to do maths
* Cast unix timestamps to int to do maths
* Cast return values from timestamp format function to int
* Cast bitwise operator to bool when needed as bool

* php internal functions like floor/round/ceil documented to return
  float, most cases the result is used as int, added casts

Found by phan strict checks

Change-Id: Icb2de32107f43817acc45fe296fb77acf65c1786
2022-03-01 18:19:33 +01:00
Max Semenik
986fe3bd33 PHP 7.4 fixes
All errors currently seen in Travis:
* Function ReflectionType::__toString() is deprecated
* Trying to access array offset on value of type null
* Array and string offset access syntax with curly braces is
  deprecated

Bug: T233012
Change-Id: I9619fcae5dd8b633f8c579b924aec311343da880
2019-11-22 09:49:56 +00:00
Tim Starling
558471f044 Conditional request support
* Added ConditionalHeaderUtil, a conditional request helper class meant
  for composition into Handler. I evaluated the composer package
  micheh/psr7-cache for this role but I decided that I prefer DIY
  code rather than some rather ugly glue.
* Check conditional request headers prior to entry into
  Handler::execute(). Contrary to what was previously documented, use
  the results of getLastModified() and getETag() to set headers in the
  response. This is convenient and can be overridden in the Handler if
  desired by overriding a one-line function.
* Instead of locking up header parsing inside ConditionalHeaderUtil as
  was done in micheh/psr7-cache, make a start on a new reusable header
  parsing framework, with recursive descent parsers for HTTP-date and
  IfNoneMatch.

Change-Id: I260809081cad7701df8620ab03834158670d4230
2019-10-14 12:01:25 +11:00