Skip to content
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

multipart/form-data PATCH request produces http-request snippet with no request body #933

Closed
beuss opened this issue Jun 19, 2024 · 3 comments
Labels
Milestone

Comments

@beuss
Copy link

beuss commented Jun 19, 2024

When documenting a multipart/form-data request using PATCH method, we end up with only headers in http-request snippet.
It looks like switch to multipart is only handled for PUT/POST (org.springframework.restdocs.http.HttpRequestSnippet#getRequestBody). Is there any reason for this? I didn't find any restriction about multipart and PATCH in https://datatracker.ietf.org/doc/html/rfc5789
Anyway, the restriction on PUT/POST looks like a little excessive, if body content is empty but we've parts, it's likely that we want those parts to be included in the generated snippet.

@codespearhead
Copy link

Media type multipart/form-data is only defined for the POST method as per RFC 2616:

Note: The "multipart/form-data" type has been specifically defined for carrying form data suitable for processing via the POST request method, as described in RFC 1867 [15]

Which is clarified by errata RFC 5789:

the operation does not modify the resource identified by the Request-URI in a predictable way that's defined by the semantics of the PATCH media type, POST should be considered instead of PATCH or PUT.

That's why MDN web docs says PATCH shouldn't be used for binary data, as stated by this answer:

PATCH is not for uploading binary data (like what you want with the image), see: https://developer.mozilla.org/en-US/docs/web/http/methods/patch (Allowed in HTML Forms: No)

This issue should be closed in my opinion.

@beuss
Copy link
Author

beuss commented Jul 2, 2024

1 - Well "specifically designed", doesn't mean "restricted to", I don't see any normative content in the note (no "SHOULD/MUST not be used with other HTTP methods" or so). Moreover HttpRequestSnippet already handles parts for PUT requests

2 - Don't see how multipart/form-data implies that the resource isn't modified in a predictable way

3 - The answer you quote finishes by

Uploading binary data (like images) has to be done with POST always, PUT or PATCH are used to modify the attributes of the ressource.

Don't see why a resource cannot embed binary data. Moreover, MDN isn't a normative document

@wilkinsona
Copy link
Member

I agree, @beuss. I see no reason to close this issue.

@wilkinsona wilkinsona added type: bug A bug and removed status: waiting-for-triage Untriaged issue labels Jul 2, 2024
@wilkinsona wilkinsona added this to the 3.0.2 milestone Jul 2, 2024
@wilkinsona wilkinsona changed the title multipart/form-data PATCH request produces no request body multipart/form-data PATCH request produces http-request snippet with no request body Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants