Skip to content

Commit

Permalink
modified response.stream to close the stream after consuming it
Browse files Browse the repository at this point in the history
this is vital when using file-based streams (i.e. created with `fs.open
()`).
  • Loading branch information
grob committed Mar 6, 2017
1 parent 4917ca6 commit 21cacc4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion modules/ringo/jsgi/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,15 @@ Object.defineProperty(JsgiResponse.prototype, "stream", {
}

this.headers["content-type"] = contentType || "application/octet-stream";
this.body = stream;
this.body = {
forEach: function(fn) {
try {
stream.forEach(fn);
} finally {
stream.close();
}
}
};

return this;
}
Expand Down

4 comments on commit 21cacc4

@botic
Copy link
Member

@botic botic commented on 21cacc4 Mar 10, 2017

Choose a reason for hiding this comment

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

thx, since there is no auto-close after a forEach call in the JSGI connector.

@botic
Copy link
Member

@botic botic commented on 21cacc4 Mar 10, 2017

Choose a reason for hiding this comment

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

This needs also a change in the test, which relies on a stream object as response.body. See #368

     [java]      + Running testStream ... FAILED 
     [java]    Expected 8, got undefined
     [java]    at /Users/philipp/Code/ringojs/test/ringo/jsgi/response_test.js:146
     [java]    at /Users/philipp/Code/ringojs/test/all.js:28

@grob
Copy link
Member Author

@grob grob commented on 21cacc4 Mar 10, 2017

Choose a reason for hiding this comment

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

ah, of course! i'll adapt the test.

@botic
Copy link
Member

@botic botic commented on 21cacc4 Mar 10, 2017

Choose a reason for hiding this comment

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

Merci!

Please sign in to comment.