8000 feature #19322 [HttpFoundation] Add Request::isMethodIdempotent metho… · symfony/symfony@0fc2b62 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0fc2b62

Browse files
committed
feature #19322 [HttpFoundation] Add Request::isMethodIdempotent method (dunglas)
This PR was squashed before being merged into the 3.2-dev branch (closes #19322). Discussion ---------- [HttpFoundation] Add Request::isMethodIdempotent method | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Addd a new method in the spirit of `isMethodSafe` to know if the current method is idempotent according to RFCs. Commits ------- 44df6a4 [HttpFoundation] Add Request::isMethodIdempotent method
2 parents 36ec085 + 44df6a4 commit 0fc2b62

File tree

2 files changed

+37
-1
lines changed
< 8000 ul role="tree" aria-label="File Tree" data-truncate-text="true" class="prc-TreeView-TreeViewRootUlStyles-eZtxW">
  • src/Symfony/Component/HttpFoundation
  • 2 files changed

    +37
    -1
    lines changed

    src/Symfony/Component/HttpFoundation/Request.php

    Lines changed: 11 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -1473,7 +1473,7 @@ public function isMethod($method)
    14731473
    }
    14741474

    14751475
    /**
    1476-
    * Checks whether the method is safe or not.
    1476+
    * Checks whether or not the method is safe.
    14771477
    *
    14781478
    * @return bool
    14791479
    */
    @@ -1482,6 +1482,16 @@ public function isMethodSafe()
    14821482
    return in_array($this->getMethod(), array('GET', 'HEAD'));
    14831483
    }
    14841484

    1485+
    /**
    1486+
    * Checks whether or not the method is idempotent.
    1487+
    *
    1488+
    * @return bool
    1489+
    */
    1490+
    public function isMethodIdempotent()
    1491+
    {
    1492+
    return in_array($this->getMethod(), array('HEAD', 'GET', 'PUT', 'DELETE', 'TRACE', 'OPTIONS', 'PURGE'));
    1493+
    }
    1494+
    14851495
    /**
    14861496
    * Returns the request body content.
    14871497
    *

    src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

    Lines changed: 26 additions & 0 deletions
    Original file line numberDiff line number 8000 Diff line change
    @@ -1951,6 +1951,32 @@ public function getLongHostNames()
    19511951
    array(str_repeat(':', 101)),
    19521952
    );
    19531953
    }
    1954+
    1955+
    /**
    1956+
    * @dataProvider methodIdempotentProvider
    1957+
    */
    1958+
    public function testMethodIdempotent($method, $idempotent)
    1959+
    {
    1960+
    $request = new Request();
    1961+
    $request->setMethod($method);
    1962+
    $this->assertEquals($idempotent, $request->isMethodIdempotent());
    1963+
    }
    1964+
    1965+
    public function methodIdempotentProvider()
    1966+
    {
    1967+
    return array(
    1968+
    array('HEAD', true),
    1969+
    array('GET', true),
    1970+
    array('POST', false),
    1971+
    array('PUT', true),
    1972+
    array('PATCH', false),
    1973+
    array('DELETE', true),
    1974+
    array('PURGE', true),
    1975+
    array('OPTIONS', true),
    1976+
    array('TRACE', true),
    1977+
    array('CONNECT', false),
    1978+
    );
    1979+
    }
    19541980
    }
    19551981

    19561982
    class RequestContentProxy extends Request

    0 commit comments

    Comments
     (0)
    0