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] Stream request body in HttplugClient and Psr18Client#58856

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:7.2fromKurtThiemann:7.2
Nov 13, 2024

Conversation

KurtThiemann
Copy link
Contributor

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

Currently,Psr18Client andHttplugClient will simply callgetContents() on the stream, loading the entire stream content into a string before passing it to the underlyingHttpClient. When sending a request with a large body, this can lead to the PHP process running out of memory.
This pull request changes both clients to instead pass a Closure that reads from the request body stream to the underlyingHttpClient.

The HttpClient documentation states that "each time, the closure should return a string smaller than the amount requested as argument", which would mean that if the closure was called requesting a size of 10 bytes, you are only allowed to return at most 9 bytes. I assume that is an inaccuracy in the docs, but please correct me if I'm wrong here.
I'm also not fully sure whether this would be considered a new feature or a bug fix.

ro0NL and W0rma reacted with eyes emoji
@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has acontribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (seehttps://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (seehttps://symfony.com/releases)
  • Features and deprecations must be submitted against the 7.2 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@nicolas-grekas
Copy link
Member

(please rebase, not merge)

@KurtThiemann
Copy link
ContributorAuthor

Sorry, should be fixed

Any idea what's up with the tests? I'd say I'm reasonably confident I'm not responsible for all the failures here...

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.

Works for me as an improvement, thus for 7.2

@nicolas-grekas
Copy link
Member

Note that this means the content-length won't be sent anymore and the chunked encoding will be used instead.
Maybe something that could be fixed by asking the stream its size?

@KurtThiemann
Copy link
ContributorAuthor

The Content-Length header should now be added if$stream->getSize() doesn't return null. This way, the behavior should now be the same as before, except for streams of unknown length, which before had a Content-Length header and now don't.

@KurtThiemann
Copy link
ContributorAuthor

Not sure if we'd want to do something about the duplicate code in Psr18Client and HttplugClient

@nicolas-grekas
Copy link
Member

Thank you@KurtThiemann.

@nicolas-grekasnicolas-grekas merged commitbbdf0e0 intosymfony:7.2Nov 13, 2024
1 check was pending
@stof
Copy link
Member

The HttpClient documentation states that "each time, the closure should return a string smaller than the amount requested as argument", which would mean that if the closure was called requesting a size of 10 bytes, you are only allowed to return at most 9 bytes. I assume that is an inaccuracy in the docs, but please correct me if I'm wrong here.
I'm also not fully sure whether this would be considered a new feature or a bug fix.

I think that the documentation should saysmaller or equal rather thansmaller

nicolas-grekas added a commit that referenced this pull requestDec 2, 2024
…ct HTTP method in CurlHttpClient (KurtThiemann)This PR was submitted for the 7.2 branch but it was squashed and merged into the 6.4 branch instead.Discussion----------[HttpClient] Always set CURLOPT_CUSTOMREQUEST to the correct HTTP method in CurlHttpClient| Q             | A| ------------- | ---| Branch?       | 7.2| Bug fix?      | yes| New feature?  | no| Deprecations? | no| Issues        |Fix#59043| License       | MITCurrently, when sending a `HEAD` request and using a closure as the request body using `CurlHttpClient`, a `PUT` request instead of a HEAD request will be sent. This is because `CURLOPT_NOBODY` is set to make a `HEAD` request, but is overwritten by `CURLOPT_UPLOAD`, which is necessary to make curl call `CURLOPT_READFUNCTION`, but also sets the HTTP method to `PUT`.The solution I am suggesting is to just always set `CURLOPT_CUSTOMREQUEST`, so the correct HTTP method will be used, no matter what other options are added.This is mainly an issue in the PSR-18 wrapper, since PSR requests always have a request body stream, even if the body is empty. Since#58856, `Psr18Client` always passes a closure as the request body to the underlying HTTP client instead of just reading the entire request body stream into a string, as that made it impossible to upload large files.While it would be possible to add an exception to `Psr18Client` to only add the request body if the method used commonly has a body, I think the better solution is to ensure that  `CurlHttpClient` always actually sends the type of request that it is asked to send.Commits-------bfdf5d9 [HttpClient] Always set CURLOPT_CUSTOMREQUEST to the correct HTTP method in CurlHttpClient
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
7.2
Development

Successfully merging this pull request may close these issues.

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

[8]ページ先頭

©2009-2025 Movatter.jp