Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[HttpClient] Ignore RuntimeExceptions thrown when rewinding the PSR-7 created in HttplugWaitLoop::createPsr7Response#58901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
nicolas-grekas merged 1 commit intosymfony:6.4fromKurtThiemann:psr7-seek-catch
Jan 8, 2025

Conversation

KurtThiemann
Copy link
Contributor

@KurtThiemannKurtThiemann commentedNov 16, 2024
edited by nicolas-grekas
Loading

QA
Branch?6.4
Bug fix?yes
New feature?no
Deprecations?no
Issues-
LicenseMIT

To create a PSR-7 response from a regular Symfony HTTP response in Psr18Client and HttplugClient, the static methodHttplugWaitLoop::createPsr7Response is used. It also converts the response body stream to a PSR-7 stream, which generally happens in two steps: First, theResponseStreamInterface is made into a resource using a custom stream wrapper, and then this resource is made into a PSR-7 stream using thecreateStreamFromResource of whatever stream factory is used.

Finally, if the resulting PSR-7 stream is seekable, it is rewound to its start. Depending on the used stream implementation, it is, however, possible that calling->seek(0) throws an exception, despite->isSeekable() returning true. This is because the way some PSR-7 stream implementations check if the underlying resource is seekable is by looking at theseekable stream meta property. For custom stream wrappers, this metadata value appears to be always true, no matter if the stream wrapper implements seeking or not.

Some stream implementations, like the one in nyholm/psr7, prevent this by just trying to callfseek on the resource when the stream is first created and considering it not seekable if the operation fails. Other implementations like guzzle/psr7 don't do this extra check, which is why using the Symfony Psr18Client with a Guzzle stream factory fails. Since the Psr18Client automatically discovers stream factory implementations if none is specified, the Guzzle implementation can become the default if Guzzle happens to be installed in the project.

The solution I'm proposing here is to simply ignore any RuntimeException thrown when trying to seek to the start of the stream. Since rewinding the stream is already optional, this shouldn't cause any issues.

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I guess we should do the same in Psr18Client and HttplugClient when seek(0) is called.

… created in HttplugWaitLoop::createPsr7Response
@nicolas-grekas
Copy link
Member

Thank you@KurtThiemann.

@nicolas-grekasnicolas-grekas merged commite3950a4 intosymfony:6.4Jan 8, 2025
8 checks passed
This was referencedJan 29, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@lyrixxlyrixxAwaiting requested review from lyrixx

@ycerutoycerutoAwaiting requested review from yceruto

@chalasrchalasrAwaiting requested review from chalasr

@dunglasdunglasAwaiting requested review from dunglas

@OskarStarkOskarStarkAwaiting requested review from OskarStark

@jderussejderusseAwaiting requested review from jderusse

@xabbuhxabbuhAwaiting requested review from xabbuh

Assignees
No one assigned
Projects
None yet
Milestone
6.4
Development

Successfully merging this pull request may close these issues.

4 participants
@KurtThiemann@nicolas-grekas@fabpot@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp