Skip to content

Commit 0f49b53

Browse files
authored
Document HTTP method override validation (#8368)
Refs cakephp/cakephp#19669.
1 parent e59f22c commit 0f49b53

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

‎docs/en/appendices/5-5-migration-guide.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ bin/cake upgrade rector --rules cakephp55 <path/to/app/src>
3333
this method must add the optional parameter to their signature and pass it
3434
through when calling `parent::addDefaultTypes()`.
3535

36+
### Http
37+
38+
- HTTP method overrides from `_method` or `X-Http-Method-Override` are normalized
39+
to uppercase. Invalid syntax and non-string values now raise
40+
`BadRequestException` (HTTP 400). See
41+
[HTTP Method Overrides](../controllers/request-response#http-method-overrides).
42+
3643
## Deprecations
3744

3845
Coming soon

‎docs/en/controllers/request-response.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,27 @@ Returns the HTTP method the request was made with:
514514
echo $request->getMethod();
515515
```
516516

517+
### HTTP Method Overrides
518+
519+
`ServerRequestFactory::fromGlobals()` supports a `_method` request-body field
520+
or an `X-Http-Method-Override` header to override the request method. The
521+
header takes precedence over the body field. `_method` is removed from the
522+
parsed body. Use
523+
`$request->getEnv('ORIGINAL_REQUEST_METHOD')` to read the original method.
524+
525+
Override values are converted to uppercase and must contain letters A-Z,
526+
optionally separated by single hyphens or underscores. For example, `patch`,
527+
`VERSION-CONTROL` and `CUSTOM_METHOD` are accepted; digits, whitespace, repeated
528+
separators and array values are rejected.
529+
530+
Invalid values throw `BadRequestException` with the message
531+
`Invalid HTTP method override.` and result in HTTP 400. This happens while
532+
building the request, before the middleware queue runs.
533+
534+
::: info Added in version 5.5.0
535+
Validation and normalization of HTTP method overrides were added.
536+
:::
537+
517538
### Restricting HTTP Methods per Action
518539

519540
`method` Cake\\Http\\ServerRequest::**allowMethod**(array|string $methods): bool

0 commit comments

Comments
 (0)