Page MenuHomePhabricator

Rest router should provide parsed body data to handler.
Closed, ResolvedPublic

Description

Router::execute should call a new method Router::setBodyData, which should:

  • should throw for GET, HEAD, and DELETE if there is body data. Compare the code in Use the code from Validator::validateBody.
  • should throw for POST and PUT if there is body data but no content type. Be careful not to try and loat the entire body in order to check, since it may be very large. Use the code from Validator::validateBody.
  • should not throw for POST and PUT if there is no content type but also no body
  • call Handler::parseBodyData (if appropriate)
  • call RequestInterface::setParsedBody if Handler::parseBodyData returned an array.

Note that we should throw a 415 exception if the handler doesn't support the given body type. Since Handler::parseBodyData can legitimately return null even for a supported type (if the handler wants to process it as a stream and avoid parsing), this means Handler::parseBodyData should be changed to throw on unsupported types. The only type that should be supported per default is application/json. It should however be easy for handlers to opt into supporting form data by calling $handler->getPostParams().

To support the changes to Handler::parseBodyData, we will probably want to move some constants from Validator into RequestInterface, namely NO_BODY_METHODS, BODY_METHODS, and FORM_DATA_CONTENT_TYPES.

Related Objects

Event Timeline

Change 1006906 had a related patch set uploaded (by WQuarshie; author: WQuarshie):

[mediawiki/core@master] Rest router should provide parsed body data to handler.

https://gerrit.wikimedia.org/r/1006906

Change 1006876 had a related patch set uploaded (by Atieno; author: Atieno):

[mediawiki/core@master] handler: Throw on unsupported body

https://gerrit.wikimedia.org/r/1006876

Change 1006876 merged by jenkins-bot:

[mediawiki/core@master] handler: Throw on unsupported body

https://gerrit.wikimedia.org/r/1006876

daniel triaged this task as Medium priority.

Change 1006906 merged by jenkins-bot:

[mediawiki/core@master] Rest router should provide parsed body data to handler.

https://gerrit.wikimedia.org/r/1006906

Change 1008562 had a related patch set uploaded (by Arlolra; author: Arlolra):

[mediawiki/extensions/EventBus@master] Update expected body.message for unsupported content-type

https://gerrit.wikimedia.org/r/1008562

Change 1008562 merged by jenkins-bot:

[mediawiki/extensions/EventBus@master] Update expected body.message for unsupported content-type

https://gerrit.wikimedia.org/r/1008562

This appears to have broken existing support for other body types (application/json-patch+json) in the Wikibase REST API, please see T359149.