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

raise 413 from request.post() not ValueError #3093

Merged
merged 3 commits into from
Jun 19, 2018
Merged

raise 413 from request.post() not ValueError #3093

merged 3 commits into from
Jun 19, 2018

Conversation

samuelcolvin
Copy link
Member

@samuelcolvin samuelcolvin commented Jun 19, 2018

What do these changes do?

Raise 413 "Payload Too Large" rather than raising ValueError in request.post()

Are there changes in behavior for the user?

post will raise HTTPRequestEntityTooLarge rather than ValueError

Related issue number

fix #3087

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • Add a new news fragment into the CHANGES folder
    • name it <issue_id>.<type> for example (588.bugfix)
    • if you don't have an issue_id change it to the pr id after creating the pr
    • ensure type is one of the following:
      • .feature: Signifying a new feature.
      • .bugfix: Signifying a bug fix.
      • .doc: Signifying a documentation improvement.
      • .removal: Signifying a deprecation or removal of public API.
      • .misc: A ticket has been closed, but it is not of interest to users.
    • Make sure to use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files."

@samuelcolvin
Copy link
Member Author

by the way, when I run make test, I'm getting

tests/test_helpers.py:319: in <module>
    class TestCReify(ReifyMixin):
tests/test_helpers.py:320: in TestCReify
    reify = helpers.reify_c
E   AttributeError: module 'aiohttp.helpers' has no attribute 'reify_c'

This seems to be new, I wasn't getting it before.

@asvetlov
Copy link
Member

Perhaps you didn't compile cython extensions.
make test should do it.
Also please don't forget git submodule init / git submodule update

@samuelcolvin
Copy link
Member Author

samuelcolvin commented Jun 19, 2018

git submodule init / git submodule update was what I needed. Thank you.

@@ -605,8 +604,7 @@ def body_exists(self) -> bool:
out.add(field.name, value)
size += len(value)
if 0 < max_size < size:
raise ValueError(
'Maximum request body size exceeded')
raise HTTPRequestEntityTooLarge
Copy link
Member

Choose a reason for hiding this comment

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

May be add some message like what size was expected and which one is actual? That's good for debug.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense.
We do it for too large headers already.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, so something like Maximum request body size exceeded: 1234 > 123?

Copy link
Member Author

Choose a reason for hiding this comment

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

Or perhaps clearer Maximum request body size 123 exceeded, actual body size 1234?

Copy link
Member

Choose a reason for hiding this comment

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

I like the second

Copy link
Member

Choose a reason for hiding this comment

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

👍 the second. A bit verbose, but that wouldn't hurt.

@codecov-io
Copy link

codecov-io commented Jun 19, 2018

Codecov Report

Merging #3093 into master will increase coverage by 0.19%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #3093      +/-   ##
=========================================
+ Coverage   98.01%   98.2%   +0.19%     
=========================================
  Files          43      43              
  Lines        7807    8199     +392     
  Branches     1352    1525     +173     
=========================================
+ Hits         7652    8052     +400     
+ Misses         56      53       -3     
+ Partials       99      94       -5
Impacted Files Coverage Δ
aiohttp/web_exceptions.py 100% <100%> (ø) ⬆️
aiohttp/web_request.py 99.24% <100%> (+0.56%) ⬆️
aiohttp/typedefs.py 100% <0%> (ø) ⬆️
aiohttp/client_reqrep.py 99.01% <0%> (+1.59%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 69f5c56...18cd968. Read the comment docs.

raise ValueError(
'Maximum request body size exceeded')
raise HTTPRequestEntityTooLarge(
max_size=max_size, actual_size=size)
Copy link
Member

Choose a reason for hiding this comment

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

That style is a bit different from above:

+                if self._client_max_size:
+                    body_size = len(body)
+                    if body_size >= self._client_max_size:
+                        raise HTTPRequestEntityTooLarge(
+                            max_size=self._client_max_size,
+                            actual_size=body_size
+                        )

Let's be consistent.

@asvetlov asvetlov merged commit 983aa5f into aio-libs:master Jun 19, 2018
@asvetlov
Copy link
Member

thanks!

@samuelcolvin samuelcolvin deleted the post-413 branch June 19, 2018 13:05
@lock
Copy link

lock bot commented Oct 28, 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].
[new issue]: https://github.com/aio-libs/aiohttp/issues/new

@lock lock bot added the outdated label Oct 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 28, 2019
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bot:chronographer:provided There is a change note present in this PR outdated
Projects
None yet
Development

Successfully merging this pull request may close these issues.

request.post() should raise HTTPRequestEntityTooLarge same as request.read()
4 participants