-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
HTTPClient multipart/form-data request issues #35443
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @n3o77 did you find a solution? I'm dealing with the same problem |
@martinbertinat my quick and dirty solution was just a preg_replace on the result of $formData->bodyToString(). I actually think it's a bug in the mime component which needs to be fixed. But i'm not sure if that's only an issue with HTTP requests as this component is also used for emails and maybe other stuff as well. I'm not very familiar with a lot of these specs so i hoped that someone who worked on the mime component could chime in if this was intended or not. I'm happy to create a PR to fix it. |
Up for a PR anyone, with tests? |
Regarding the boundary (defined here), because of the I'm wondering if that format generally makes sense as it also leaks the client used to make the request. For reference how curl, firefox, chrome and safari handle the boundary: Curl: Because of this i would suggest doing something similar like And maybe even have a public setter to overwrite the value. Any feedback would be nice, if others agree i'm happy to create a PR. |
Is there any improvement regarding this problem? |
@n3o77 which server do you use, that parses the MIME parts and fails in this situation? |
@nicolas-grekas unfortunately not a server available to the public. I also don't have any specs about the software used etc.. |
Hi, I've the same issue on several products that expose HTTP APIs : Dalim Twist (written in Java) Marklogic (written in C I guess...?). |
@wiser then can you please confirm that the linked patch fixes the issue for you too? |
@nicolas-grekas Unfortunately not :( |
OK thanks. Then please open a separate issue as this one is closed, and your issue looks different. |
@nicolas-grekas the PR does not solve this issue at all. The inital issue described from me is not related to the boundary header but to the |
You described there was an issue with the boundary, and it's fixed now, isn't it? |
@nicolas-grekas The issue with the name in the content-type is that it's not in the http spec. No browser does this. But it's required in e-mails as otherwise the attached files won't be displayed with a proper name in all clients. So i guess the only solution is to not use the symfony/mime component for this case and use something else. I'm happy to work on PR but would love some feedback first how it should roughly be implemented so i'm not wasting too much time. Should this then be an own component, should it be in the http client or another solution? |
@n3o77 @nicolas-grekas As I also have issues with this lib so I check on rfc2388, rfc7233 and rfc7578 if I can find any helping informations. |
Closing as a duplicate of #37500 |
This PR was merged into the 4.4 branch. Discussion ---------- [Mime] Fix compat with HTTP requests | Q | A | ------------- | --- | Branch? | 4.4 <!-- see below --> | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #37500, Fix #36738, Fix #35443 | License | MIT | Doc PR | n/a Commits ------- 52e7d7c [Mime] Fix compat with HTTP requests
Symfony version(s) affected: 4.4.3
Description
I'm communicating with an API and ran in some problems when I tried to upload files with the HTTPClient.
How to reproduce
Unfortunately it's not a public API so i can't provide the exact examples but i'm basically doing what's described in the docs:
Possible Solution
The problem is because in the data part the content-type has an additional token
name=file
(see below). At least if i remove it from the request everything works fine. I was looking in the rfc7233 and rfc7578 spec but couldn't really find anything about this, but not sure if i'm just missing it or looking in the wrong spec.The second issue I ran into was that the boundary in the request headers is enclosed in quotes, which also causes propblems. Again, couldn't really find something about that but it's not in the request when i'm just using curl in the terminal.
Doesn't work:
Works:
Are these problems in the symfony mime client or in the API i'm working with?
The text was updated successfully, but these errors were encountered: