Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 6864b29

Browse files
committed
Merge branch 'feature/29' into develop
Close #29
2 parents 8ae8d9b + ebda134 commit 6864b29

File tree

3 files changed

+34
-22
lines changed

3 files changed

+34
-22
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ All notable changes to this project will be documented in this file, in reverse
2727

2828
### Fixed
2929

30-
- Nothing.
30+
- [#29](https://github.com/zendframework/zend-diactoros/pull/29) fixes request
31+
method validation to allow any valid token as defined by [RFC
32+
7230](http://tools.ietf.org/html/rfc7230#appendix-B). This allows usage of
33+
custom request methods, vs a static, hard-coded list.
3134

3235
## 1.0.5 - 2015-06-24
3336

src/RequestTrait.php

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,6 @@ trait RequestTrait
4747
*/
4848
private $uri;
4949

50-
/**
51-
* Supported HTTP methods
52-
*
53-
* @var array
54-
*/
55-
private $validMethods = [
56-
'CONNECT',
57-
'DELETE',
58-
'GET',
59-
'HEAD',
60-
'OPTIONS',
61-
'PATCH',
62-
'POST',
63-
'PUT',
64-
'TRACE',
65-
];
66-
6750
/**
6851
* Initialize request state.
6952
*
@@ -290,9 +273,7 @@ private function validateMethod($method)
290273
));
291274
}
292275

293-
$method = strtoupper($method);
294-
295-
if (! in_array($method, $this->validMethods, true)) {
276+
if (! preg_match('/^[!#$%&\'*+.^_`\|~0-9a-z-]+$/i', $method)) {
296277
throw new InvalidArgumentException(sprintf(
297278
'Unsupported HTTP method "%s" provided',
298279
$method

test/RequestTest.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function invalidRequestMethod()
120120
'false' => [ false ],
121121
'int' => [ 1 ],
122122
'float' => [ 1.1 ],
123-
'bad-string' => [ 'BOGUS-METHOD' ],
123+
'bad-string' => [ 'BOGUS METHOD' ],
124124
'array' => [ ['POST'] ],
125125
'stdClass' => [ (object) [ 'method' => 'POST'] ],
126126
];
@@ -135,6 +135,34 @@ public function testConstructorRaisesExceptionForInvalidMethod($method)
135135
new Request(null, $method);
136136
}
137137

138+
public function customRequestMethods()
139+
{
140+
return[
141+
/* WebDAV methods */
142+
'TRACE' => ['TRACE'],
143+
'PROPFIND' => ['PROPFIND'],
144+
'PROPPATCH' => ['PROPPATCH'],
145+
'MKCOL' => ['MKCOL'],
146+
'COPY' => ['COPY'],
147+
'MOVE' => ['MOVE'],
148+
'LOCK' => ['LOCK'],
149+
'UNLOCK' => ['UNLOCK'],
150+
'UNLOCK' => ['UNLOCK'],
151+
/* Arbitrary methods */
152+
'#!ALPHA-1234&%' => ['#!ALPHA-1234&%'],
153+
];
154+
}
155+
156+
/**
157+
* @dataProvider customRequestMethods
158+
* @group 29
159+
*/
160+
public function testAllowsCustomRequestMethodsThatFollowSpec($method)
161+
{
162+
$request = new Request(null, $method);
163+
$this->assertSame($method, $request->getMethod());
164+
}
165+
138166
public function invalidRequestBody()
139167
{
140168
return [

0 commit comments

Comments
 (0)