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

Add multipart coromethod to web request handler #1074

Merged
merged 1 commit into from
Sep 11, 2016
Merged

Add multipart coromethod to web request handler #1074

merged 1 commit into from
Sep 11, 2016

Conversation

kxepal
Copy link
Member

@kxepal kxepal commented Aug 13, 2016

This fixes #1067

@kxepal
Copy link
Member Author

kxepal commented Aug 13, 2016

cc @yinzuojie

@codecov-io
Copy link

codecov-io commented Aug 13, 2016

Current coverage is 98.40% (diff: 100%)

Merging #1074 into master will increase coverage by <.01%

@@             master      #1074   diff @@
==========================================
  Files            28         28          
  Lines          6496       6501     +5   
  Methods           0          0          
  Messages          0          0          
  Branches       1091       1092     +1   
==========================================
+ Hits           6392       6397     +5   
  Misses           54         54          
  Partials         50         50          

Powered by Codecov. Last update 44d4b27...ebede79

@asvetlov
Copy link
Member

We need an usage example in web.rst

def multipart(self, *, reader=multipart.MultipartReader):
"""Return async iterator to process BODY as multipart."""
if not self.content_type.startswith('multipart/'):
warnings.warn('Attempt to process multipart request with'
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to use .multipart() for application/x-www-form-urlencoded data?

Copy link
Member Author

Choose a reason for hiding this comment

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

application/x-www-form-urlencoded - is about key=value&anotherkey=anothervalue format. It's not multipart thing. You probably mean multipart/form-data which is used to transfer binary data like files.

From the spec:

This attribute specifies the content type used to submit the form to the server (when the value of method is "post"). The default value for this attribute is "application/x-www-form-urlencoded". The value "multipart/form-data" should be used in combination with the INPUT element, type="file".

Copy link
Member Author

Choose a reason for hiding this comment

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

For application/x-www-form-urlencoded I think we can have just .form() which returns MultiDictProxy(MultiDict()) as like .post() and can be called multiple times.

Copy link
Member

Choose a reason for hiding this comment

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

I mean if Content-Type is not started with multipart/ it's maybe not a warning but an exception?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, that's bad idea since content-type validation must be done before any read method call. Raising exception means we have double ctype validation. Also, people may use custom content-type for their requests like applicaiton/vnd+multipart or whatever which won't pass this check.

The reason of this warning is to notify that things may go wrong, but since you call that method we think that you know what are you doing. May be it's practically useless though.

Copy link
Member

Choose a reason for hiding this comment

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

Understood

@asvetlov
Copy link
Member

@kxepal could you add a test for fixing coverage issue.
I really don't want to reduce coverage level but very appreciate to increase it :)

@kxepal
Copy link
Member Author

kxepal commented Aug 25, 2016

@asvetlov Sorry, yes. And an example. I'll return to the issue in few days.

@asvetlov
Copy link
Member

thanks. I would like to have this PR in next release.

@kxepal
Copy link
Member Author

kxepal commented Sep 11, 2016

@asvetlov Done, sorry for delay. It seems windows tests fails for connector due to IPv4 vs IPv6. Is that known issue?

@asvetlov
Copy link
Member

I've added broken test yesterday, will fix it today ASAP.

@kxepal
Copy link
Member Author

kxepal commented Sep 11, 2016

Ok, thanks!

@asvetlov
Copy link
Member

I've fixed tests.
@kxepal could you take a look on coverage for new patch.
I have a dream to reach %100 sometimes, every coverage decrease moves us away from the target.

@asvetlov
Copy link
Member

Hmm, from first glance all your changes should be covered.

@kxepal
Copy link
Member Author

kxepal commented Sep 11, 2016

@asvetlov Yes, there shouldn't be a coverage misses. 100% is a really good goal!

@asvetlov
Copy link
Member

Looks good!
Please merge and update CHANGES.

@asvetlov
Copy link
Member

But I still don't see a way to process 2GB file without reading the whole content in memory.
multipart has methods for iterating over parts but consumes the part at all.
reader.read_chunk(size) doesn't respect size parameter :)

@kxepal
Copy link
Member Author

kxepal commented Sep 11, 2016

@asvetlov Hm...you scary me.

read_chunk does respects that size parameter. And then all depends on what kind of request we process.

If it provides content length we basically read from content which is StreamReader of something of that kind. I don't recall any kind of buffering within it implementation, right?

Same story we do for chunked transfer, but with a tiny buffer equals a single chunk size since we eventually can read more than we need in single shot, so we need the way to roll back.

Did I miss something?

@asvetlov
Copy link
Member

Aah, sorry.
You are right. Nevermind.

@kxepal
Copy link
Member Author

kxepal commented Sep 11, 2016

Great! You just saved travis from test on transferring 2GiB of data ((:

But I found that I'm not able to pass more than 8MiB of data over test client using generator as data emitter. No errors around and warning, just bunch of data get missed. Throwing all of them with single big blob of data works right. That's all strange.

@kxepal
Copy link
Member Author

kxepal commented Sep 11, 2016

Finally. I was chasing wrong reason of failure /)_-

@kxepal kxepal merged commit 9c0d03a into aio-libs:master Sep 11, 2016
@asvetlov
Copy link
Member

Thanks!

@lock
Copy link

lock bot commented Oct 29, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

will there be huge file upload support ?
3 participants