♻️ Backport ResponseReaderto v0.3 #439
Merged
Merged
Conversation
This also allows us to check against the concatenated buffer, rather than the smaller line buffer. That distinction doesn't really matter now, since we always read an entire line at once. But it will matter if we read partial lines.
IMO, this refactoring makes `get_response` much easier to understand. Which will be useful, because I'm about to complicate it. 😉
We know exactly how much memory we're going to need, so we can allocate this up-front, and save a few malloc/memcpy calls on larger literals.
This feels a lot more self-documenting than returning nil then breaking when nil is returned. Also, it lets me refactor the return values for the get_response_line/get_response_literal methods, or throw from even deeper in the stack.
It's nice to extract a little bit of the complexity from the core `Net::IMAP` class. But my primary motivation was so that I could directly test this code quickly and in isolation from needing to simulate a full IMAP connection.
`Net::IMAP::Config` was introduced by `net-imap` v0.4.
This avoids the need to pass these to every method that uses them.
That's not a big deal now, but it simplifies the next few changes.
Also added a missing test for empty literals: "{0}\r\n"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backports the following to
v0.3-stable:Net::IMAP#get_response(internal) #422get_response#433includes backport fixes from ♻️ Extract ResponseReader from get_response (backport #433) #434)