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

Provide request body in request info. #811

Merged
merged 8 commits into from
Oct 23, 2018
Prev Previous commit
Next Next commit
Improve comment on sequential QIODevice in network_manager.py.
  • Loading branch information
ArturGaspar committed Oct 19, 2018
commit 7899025134dcabb16a65506f538101e86176c4f4
8 changes: 4 additions & 4 deletions splash/network_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ def _get_request_body(self, request, outgoing_data):
if outgoing_data is not None:
Copy link
Member

Choose a reason for hiding this comment

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

It is often easier to read functions when special cases are handled first:

if outgoing_data is None:
    return None
# ... the rest

this also provides more horizontal space (less nesting).

size = None
if outgoing_data.isSequential():
# In a sequential QIODevice, size() will return the value of
# bytesAvailable(), which is only the size of the QIODevice
# buffer, not the size of the whole data. Until a read attempt,
# it is zero.
# In a sequential QIODevice, size() returns the value of
# bytesAvailable(), which is only the size of the data in the
# QIODevice buffer and not the total size of the output. Until
Copy link
Member

Choose a reason for hiding this comment

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

Do you know if tests trigger this behavior (data with a size larger than a buffer)? It seems new tests only use very small request bodies.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I added a test for it.

# a read attempt, the buffer is empty and size() returns zero.
#
# In requests generated by Qt WebKit, outgoing_data is a
# WebCore::FormDataIODevice object, which is sequential. Its
Expand Down