`pipe()` calls `end()` for you a the end of the source stream. So that
leaves solution 1 with mistake.
res is a writable stream and therefore does not emit "end" events.
I would suggest write the HEAD of your response before piping to it.
var raw = fs.createReadStream(filePath);
var encoding = 'deflate' ;
res.writeHead(200, {
'content-encoding' : encoding,
'Content-Type': contentType + '; charset=utf-8'
});
raw.pipe(zlib.createDeflate()).pipe(res);
If IE fails, then you probably need to tell us which version of IE you are
targetting. I would suppose some IEs don't work well with deflate and
prefer gzip, and there might also be some problems with chunked encoding.
On Tuesday, 10 February 2015 13:40:01 UTC+1, Jan Maybach wrote:
>
> I am struggling with this code:
>
> All with:
> http.createServer( function( req,res) {}
> wrapped around...
>
> If I do this, Chrome and Internet Explorer keep blank:
>
> var raw = fs.createReadStream(filePath);
> var encoding = 'deflate' ;
> raw.pipe(zlib.createDeflate()).pipe(res);
> res.writeHead(200, {
> 'content-encoding' : encoding,
> 'Content-Type': contentType + '; charset=utf-8'
> });
> res.end()
>
> If I do this, Chrome loads, IE fails:
>
> var raw = fs.createReadStream(filePath);
> var encoding = 'deflate' ;
> raw.pipe(zlib.createDeflate()).pipe(res);
> res.writeHead(200, {
> 'content-encoding' : encoding,
> 'Content-Type': contentType + '; charset=utf-8'
> });
> If I do this, there is no "end" event on the "res"
>
> var raw = fs.createReadStream(filePath);
> var encoding = 'deflate' ;
> raw.pipe(zlib.createDeflate()).pipe(res);
> res.writeHead(200, {
> 'content-encoding' : encoding,
> 'Content-Type': contentType + '; charset=utf-8'
> });
> res.on('end', res.end )
>
> If I do this, the server crashes with:
> - http.js:919
>
> this._implicitHeader();
>
> ^
>
> TypeError: Object #<ReadStream> has no method '_implicitHeader'
>
> at ReadStream.OutgoingMessage.end (http.js:919:10)
>
> at ReadStream.emit (events.js:117:20)
>
> at _stream_readable.js:944:16
>
> at process._tickCallback (node.js:442:13)
> var raw = fs.createReadStream(filePath);
> var encoding = 'deflate' ;
> raw.pipe(zlib.createDeflate()).pipe(res);
> res.writeHead(200, {
> 'content-encoding' : encoding,
> 'Content-Type': contentType + '; charset=utf-8'
> });
> raw.on('end', res.end )
>
>
> I am in the know about the Node.js documentation, where it says:
> - "The method, response.end(), MUST be called on each response."
> http://nodejs.org/api/http.html#http_response_end_data_encoding_callback
> ...
>
>
> What can I do?
>
>
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/5f71fbef-6e36-4d6f-a747-3bd5851edaa2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.