Skip to content

Conversation

chunweii
Copy link
Contributor

@chunweii chunweii commented Feb 1, 2023

Fixes #244

@coveralls
Copy link
Collaborator

coveralls commented Feb 1, 2023

Coverage Status

Coverage: 94.885% (-0.02%) from 94.901% when pulling db156c8 on chunweii:lazy-reading into 1d92ad2 on gavv:master.

@gavv gavv added the ready for review Pull request can be reviewed label Feb 2, 2023
Copy link
Owner

@gavv gavv left a comment

Choose a reason for hiding this comment

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

Thanks for PR! Please see comments below.

@gavv gavv added needs revision Pull request should be revised by its author and removed ready for review Pull request can be reviewed labels Feb 2, 2023
@gavv gavv force-pushed the master branch 5 times, most recently from d159043 to 7d9207b Compare February 4, 2023 11:47
@chunweii chunweii requested a review from gavv February 5, 2023 15:18
@gavv gavv added ready for review Pull request can be reviewed and removed needs revision Pull request should be revised by its author labels Feb 5, 2023
@gavv
Copy link
Owner

gavv commented Feb 5, 2023

Thanks for update! I'll review the code tomorrow, but here is one preliminary comment: we should wrap body into newBodyWrapper in response constructor, not in getContent. Because it's not guaranteed that getContent will be ever called. And adding newBodyWrapper is needed to ensure that if getContent is not called, the finalizer will close the body. (bodyWrapper has finalizer inside it).

Copy link
Owner

@gavv gavv left a comment

Choose a reason for hiding this comment

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

A few minor comments.

@gavv gavv added needs revision Pull request should be revised by its author and removed ready for review Pull request can be reviewed labels Feb 6, 2023
@chunweii
Copy link
Contributor Author

chunweii commented Feb 6, 2023

Sorry for the test case duplication. My code is ready for review again, @gavv

@chunweii chunweii requested a review from gavv February 6, 2023 16:19
@gavv
Copy link
Owner

gavv commented Feb 8, 2023

Thanks for update! I've added a few small fixes:

  • replaced contentReceived boolean with contentState enum; in addition to two existing states (not read; successfully read) I added a third state indicating that a read was attempted but failed; in this case we also don't want to read body again

  • covered this addition with tests

  • improved mock body a bit for better checks in tests of what was called; now wee test how many times read and close were called

@gavv gavv merged commit ebd494e into gavv:master Feb 8, 2023
@gavv gavv removed the needs revision Pull request should be revised by its author label Feb 8, 2023
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.

Lazy reading of response body
3 participants