Browse Source

Ensure the request method is always uppercased

microsub
J. King 6 years ago
parent
commit
0ec0a5b085
  1. 2
      lib/Misc/Date.php
  2. 9
      lib/REST.php
  3. 2
      tests/cases/REST/TestREST.php

2
lib/Misc/Date.php

@ -6,7 +6,7 @@
declare(strict_types=1);
namespace JKingWeb\Arsse\Misc;
class Date {
class Date {
public static function transform($date, string $outFormat = null, string $inFormat = null) {
$date = ValueInfo::normalize($date, ValueInfo::T_DATE, $inFormat);
if (!$date) {

9
lib/REST.php

@ -41,12 +41,13 @@ class REST {
// Google Reader http://feedhq.readthedocs.io/en/latest/api/index.html
// Fever https://feedafever.com/api
// Feedbin v2 https://github.com/feedbin/feedbin-api
// Feedbin v1 https://github.com/feedbin/feedbin-api/commit/86da10aac5f1a57531a6e17b08744e5f9e7db8a9
// Miniflux https://github.com/miniflux/miniflux/blob/master/docs/json-rpc-api.markdown
// CommaFeed https://www.commafeed.com/api/
// Unclear if clients exist:
// Miniflux https://github.com/miniflux/miniflux/blob/master/docs/json-rpc-api.markdown
// NextCloud News v2 https://github.com/nextcloud/news/blob/master/docs/externalapi/External-Api.md
// Selfoss https://github.com/SSilence/selfoss/wiki/Restful-API-for-Apps-or-any-other-external-access
// BirdReader https://github.com/glynnbird/birdreader/blob/master/API.md
// Feedbin v1 https://github.com/feedbin/feedbin-api/commit/86da10aac5f1a57531a6e17b08744e5f9e7db8a9
// Proprietary (centralized) entities:
// NewsBlur http://www.newsblur.com/api
// Feedly https://developer.feedly.com/
@ -63,8 +64,8 @@ class REST {
// find the API to handle
try {
list ($api, $target, $class) = $this->apiMatch($req->getRequestTarget(), $this->apis);
// modify the request to have a stripped target
$req = $req->withRequestTarget($target);
// modify the request to have an uppercase method and a stripped target
$req = $req->withMethod(strtoupper($req->getMethod()))->withRequestTarget($target);
// fetch the correct handler
$drv = $this->getHandler($class);
// generate a response

2
tests/cases/REST/TestREST.php

@ -120,6 +120,8 @@ class TestREST extends \JKingWeb\Arsse\Test\AbstractTest {
return [
[new ServerRequest([], [], "/index.php/apps/news/api/v1-2/feeds", "GET"), "GET", true, NCN::Class, "/feeds"],
[new ServerRequest([], [], "/index.php/apps/news/api/v1-2/feeds", "HEAD"), "GET", true, NCN::Class, "/feeds"],
[new ServerRequest([], [], "/index.php/apps/news/api/v1-2/feeds", "get"), "GET", true, NCN::Class, "/feeds"],
[new ServerRequest([], [], "/index.php/apps/news/api/v1-2/feeds", "head"), "GET", true, NCN::Class, "/feeds"],
[new ServerRequest([], [], "/tt-rss/api/", "POST"), "POST", true, TTRSS::Class, "/"],
[new ServerRequest([], [], "/no/such/api/", "HEAD"), "GET", false],
[new ServerRequest([], [], "/no/such/api/", "GET"), "GET", false],

Loading…
Cancel
Save