Problem/Motivation

When using Drupal on versions of PHP before 5.6, along with code that utilize PSR-7 HTTP messages, calling \Symfony\Component\HttpFoundation\Request::getContent() can result in a LogicException being thrown, with the message:

getContent() can only be called once when using the resource return type and PHP below 5.6.

This only occurs if libraries or modules that use PSR-7 messages are executed before the call to Request::getContent(). I've tracked this to an issue in the DiactorosFactory::createRequest() in v0.2 of the symfony/psr-http-message-bridge library. This method calls Request::getContent(true), which causes the LogicException on any later calls of Request::getContent(). Version 1.0.0 of that library fixes this issue.

Steps to reproduce:
1) Install jsonapi and simple_oauth modules
2) Configure simple_oauth and acquire an OAuth2 token via password grant as per the instructions at https://www.drupal.org/project/simple_oauth
3) Make a JSON API request using that access token. This will result in a 500 HTTP response, due to the LogicException.

Proposed resolution

Update Drupal core's composer.json to require version 1.0.0 of symfony/psr-http-message-bridge

Remaining tasks

User interface changes

None

API changes

None

Data model changes

None

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hampercm created an issue. See original summary.

hampercm’s picture

Assigned: hampercm » Unassigned
Status: Active » Needs review
FileSize
2.45 KB
hampercm’s picture

Title: [upstream] "getContent() can only be called once" error using PHP <5.6 » "getContent() can only be called once" error using PHP <5.6
wturrell’s picture

I'd be happy to test this, however it looks like instructions on the simple_oauth project page are out of date, should you feel like updating the Steps to Reproduce.

e.g.:

- URLs are now mostly "access_token" rather than "simple_oauth"
- I can't find anywhere to specify the path of the private/public keypair I'm required to create

hampercm’s picture

@wturrell Those instructions should still be good. Make sure you're using the 2.x branch of the simple_oauth module. Note that you can skip any steps that mention REST or RESTUI as the steps-to-reproduce use JSON API instead.

Anonymous’s picture

Thanks! Now "symfony/psr-http-message-bridge": "^1.0",. What status of issue will be correct?

Anonymous’s picture

Status: Needs review » Reviewed & tested by the community

Proposed resolution done in #2862254: Update non-Symfony dependencies before 8.3.0. So, looks like this issue Fixed.

tstoeckler’s picture

Status: Reviewed & tested by the community » Closed (duplicate)

Yup. Fixing issue status.