spdy-http2 / node-spdy

SPDY server on Node.js
2.81k stars 196 forks source link

Stream chunks. Help. #299

Closed Hosar closed 7 years ago

Hosar commented 7 years ago

First, thank you for this awesome work.

I've been working with node-spdy and it works really fine. Now I want to stream a set of chunks of information. What I'm doing is as follow:

// first set the header to transfer chunked
res.set({
        'Content-Type': 'text/plain',
        'Connection': 'Transfer-Encoding',
        'Transfer-Encoding': 'chunked'
      });

// second, write and flush the chunks to the response.
      fromArray.obj(information).pipe(through.obj(function (chunk, enc, cb) {

          res.write(JSON.stringify(chunk));
          res.flush();
          cb();        

      })).on('finish', () => {        
        res.end();
      });

This works fine, but the request is changing the protocol to http/1.1 (img). Is there a better way to do the same, but with http2 ?

Thanks in advance.

chunks

pavel commented 7 years ago

As per HTTP/2 spec some headers are forbidden:

An HTTP/2.0 request or response MUST NOT include any of the following header fields: Connection, Host, Keep-Alive, Proxy-Connection, Transfer-Encoding, and Upgrade

This means that for HTTP/2 you won't be able to use

'Connection': 'Transfer-Encoding', 'Transfer-Encoding': 'chunked'

My personal opinion is that you should not chunk your data manually, HTTP/2 should handle this for you. I guess you should just remove Connection and Transfer-Encoding headers from your response.

daviddias commented 7 years ago

@pavel thank you for answering this one.

@Hosar do you consider your needs fulfilled? Am I good to close this one?

Hosar commented 7 years ago

Yeap sure, thank for your help!