diff --git a/modules/ringo/jsgi/connector.js b/modules/ringo/jsgi/connector.js index 9705a6f5..5ed20b2e 100644 --- a/modules/ringo/jsgi/connector.js +++ b/modules/ringo/jsgi/connector.js @@ -126,16 +126,17 @@ const writeHeaders = (servletResponse, headers) => { }; const writeBody = (response, body, charset) => { - if (body && typeof body.forEach == "function") { + if (body && typeof body.forEach === "function") { const output = response.getOutputStream(); - body.forEach(part => { + const writer = (part) => { if (!(part instanceof binary.Binary)) { part = binary.toByteString(part, charset); } output.write(part); - }); - if (typeof body.close == "function") { - body.close(); + }; + body.forEach(writer); + if (typeof body.close === "function") { + body.close(writer); } } else { throw new Error("Response body doesn't implement forEach: " + body);