Skip to content

Commit 2cadcf1

Browse files
committed
Remove our useless atEnd handler, since it was interim to begin with. Protip: "this is not correct" in a comment means it is very likely to contain a bug :)
1 parent 700a169 commit 2cadcf1

File tree

1 file changed

+4
-18
lines changed

1 file changed

+4
-18
lines changed

index.js

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ module.exports = {
6868
//
6969
// If we forget to call next(), our stream will just never end
7070
// and things may hang.
71+
//
72+
// The second function is optional, used if we need to do anything at
73+
// the end of the stream. We don't, since we just pipe any remainder
74+
// on blindly to our caller.
7175

7276
// For simplicity, we're going to _completely_ ignore that binary
7377
// data like images are a thing that could ever exist.
@@ -151,24 +155,6 @@ module.exports = {
151155
}
152156

153157
next(); // Ready for next chunk.
154-
}, function atEnd(next) {
155-
// through2 takes 2 functions: forEachChunk and atEnd -- this is the second one,
156-
// it gets called when the data incoming to through2 ends. Any clean-up or final
157-
// actions we need to take before we stop getting called happen here.
158-
159-
// there's still a stream 'end' event that has to happen, after this stream will
160-
// do no more. We don't want a race between our cleanup and the caller's last read
161-
// or the end event. They may assume they got it all if end was emitted before this,
162-
// but we had one more thing to do, so we have to tell through2 we're not just done,
163-
// but done-done.
164-
//
165-
// If we had no atEnd, it would just send 'end' when we're done. But we had one thing
166-
// pending.
167-
168-
// So if we had leftovers, let's put them in headers. This isn't correct, but
169-
// vanishing data in a closure variable is no good either.
170-
response.rawHeaders.push(partial);
171-
next();
172158
})).pipe(response);
173159
// Whatever comes out of our header-splitting stream parser must be the
174160
// body. Because that's what we designed, right?

0 commit comments

Comments
 (0)