Support MimeParse
-ing on things other than Strings
, and allow mixing and matching MimeRender
destination types
#9
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.
Hey!
This PR adds a couple of nifty features. One is that you can now
MimeParse
stuff other than Strings -- handy for when your request body might not be valid UTF-8 (e.g., is binary). Additionally, you can now mix and match different kinds ofMimeRender
instances -- previously, if some routesMimeRender
ed down to aString
and others to aByteString
, for example -- you'd get a type mismatch (MimeRender a b String
vsMimeRender c d ByteString
) since not all of the finalrendered
types were the same, and the compiler picked whichever came first.To enable the latter, I had to generalize how responses are written to the output stream (hence the
ResponseWriter
type), and needed to add an NPM package to facilitate testing (stream-buffers
, which allow you to treat aBuffer
as a node stream).You may find there is no obvious test for the mix-and-match MimeRender functionality -- the test is the test suite itself compiling! Note that MagicContentType now
MimeRender
s to a ByteString, whereas there are remaining HTML and JSON endpoints whichMimeRender
toString
: