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

Fix for discarded form data #954

Closed
wants to merge 1 commit into from

Conversation

rsnyman
Copy link

@rsnyman rsnyman commented May 22, 2019

Attempt to fix a situation where form data is thrown away when the requestBody has no name.

This PR fixes a problem I'm having where a POST requestBody without a name is being discarded. I'm not sure if this is the correct way to do it, but this solves my problem. Please let me know if you know of a better way of doing this.

See issue #935 for more information about this.

Changes proposed in this pull request:

  • Return parameters when the content type is "multipart/form-data"

@prawn-cake prawn-cake mentioned this pull request Jun 21, 2019
@@ -273,6 +273,9 @@ def _get_body_argument(self, body, arguments, has_kwargs, sanitize):

if x_body_name in arguments or has_kwargs:
return {x_body_name: res}
# If the content type is "multipart/form-data" return the properties as-is
if self.consumes[0] == 'multipart/form-data':
return res
return {}
Copy link
Contributor

Choose a reason for hiding this comment

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

I am pretty sure it might be sufficient to just return res in here.
In method that calls the one you modified, request.form.items is put into request_body.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, that's is needed for #987 to work.

Copy link
Author

Choose a reason for hiding this comment

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

I just did it like this because I wasn't entirely sure if a non-empty response was always going to be the correct response. I can most certainly change it though.

Copy link
Contributor

Choose a reason for hiding this comment

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

I pulled that version into #987 and there are some tests failing, so yours might be better TBH.
Rebase on top of master BTW, there are some changes that should make it better with tests and for you to see if direction is fine.

@@ -273,6 +273,9 @@ def _get_body_argument(self, body, arguments, has_kwargs, sanitize):

if x_body_name in arguments or has_kwargs:
return {x_body_name: res}
# If the content type is "multipart/form-data" return the properties as-is
if self.consumes[0] == 'multipart/form-data':
Copy link
Contributor

@kornicameister kornicameister Jul 9, 2019

Choose a reason for hiding this comment

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

I believe it might be better to use this code. connexion maintains own list of what it understands as multipart.

Suggested change
if self.consumes[0] == 'multipart/form-data':
from .. import http_facts
if self.consumes[0] in http_facts.FORM_CONTENT_TYPES:

PS. I am not sure if amounts of dots is OK, but there is for sure a module http_facts in root package.

Copy link
Author

Choose a reason for hiding this comment

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

Ah, that's definitely better than mine :-)

@rsnyman rsnyman force-pushed the fix-multipart-form-params branch from 9341956 to 2f2bed0 Compare July 10, 2019 20:39
@rsnyman rsnyman closed this Jan 16, 2020
@rsnyman rsnyman deleted the fix-multipart-form-params branch January 16, 2020 16:01
@Tohnmeister
Copy link

Why was this pull request closed? It doesn't appear to merged into master/main ever, yet it was a fix for an issue I'm facing with multipart form data.

RichardBruskiewich pushed a commit to STARInformatics/connexion that referenced this pull request Mar 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants