spdy-http2 / node-spdy

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

non-200 status codes not working with push #206

Closed jeffkaufman closed 5 years ago

jeffkaufman commented 9 years ago

Following https://www.igvita.com/2013/06/12/innovating-with-http-2.0-server-push/ I'm trying to get a working example of pushing non-200 status codes. I have:

var fs = require('fs'),
    spdy = require('../../');

var options = {
  key: fs.readFileSync('keys/spdy-key.pem'),
  cert: fs.readFileSync('keys/spdy-cert.pem'),
  ca: fs.readFileSync('keys/spdy-csr.pem')
};

spdy.createServer(options, function(req, res) {
  //push JavaScript asset (/newasset.js) to the client                           
  res.push('/newasset.js', {'content-type': 'application/javascript'},
  function(err, stream) {
    stream.end('alert("hello from (redirected) push stream!")');
  });

  // push 301 redirect: /asset.js -> /newasset.js                                
  res.push('/asset.js', {':status': 301, 'Location': '/newasset.js'},
  function(err, stream) {
    stream.end('301 Redirect');
  });

  // write main response body and terminate stream                               
  res.end('<script src="/asset.js"></script>');
}).listen(3232);

In both Chrome and Firefox I see asset.js as loading with status code 200, not 301:

tmp

Looking in net-internals for this stream I see:

t=201621 [st= 0] +SPDY_SESSION  [dt=?]
                  --> host = "localhost:3232"
                  --> proxy = "DIRECT"
t=201621 [st= 0]    SPDY_SESSION_INITIALIZED
                    --> protocol = "spdy/3.1"
                    --> source_dependency = 1368246 (SOCKET)
t=201621 [st= 0]    SPDY_SESSION_SEND_SETTINGS
                    --> settings = ["[id:4 flags:0 value:1000]","[id:7 flags:0 value:10485760]"]
t=201621 [st= 0]    SPDY_STREAM_UPDATE_RECV_WINDOW
                    --> delta = 10420224
                    --> window_size = 10485760
t=201621 [st= 0]    SPDY_SESSION_SENT_WINDOW_UPDATE_FRAME
                    --> delta = 10420224
                    --> stream_id = 0
t=201621 [st= 0]    SPDY_SESSION_UPDATE_STREAMS_SEND_WINDOW_SIZE
                    --> delta_window_size = 983040
t=201621 [st= 0]    SPDY_SESSION_SEND_SETTINGS
                    --> settings = ["[id:7 flags:2 value:1048576]"]
t=201622 [st= 1]    SPDY_SESSION_RECV_SETTINGS
                    --> clear_persisted = false
                    --> host = "localhost:3232"
t=201622 [st= 1]    SPDY_SESSION_UPDATE_STREAMS_SEND_WINDOW_SIZE
                    --> delta_window_size = 0
t=201622 [st= 1]    SPDY_SESSION_RECV_SETTING
                    --> flags = 1
                    --> id = 7
                    --> value = 1048576
t=201622 [st= 1]    SPDY_SESSION_RECEIVED_WINDOW_UPDATE_FRAME
                    --> delta = 983040
                    --> stream_id = 0
t=201622 [st= 1]    SPDY_SESSION_UPDATE_SEND_WINDOW
                    --> delta = 983040
                    --> window_size = 1048576
t=201622 [st= 1]    SPDY_SESSION_SYN_STREAM
                    --> fin = true
                    --> :host: localhost:3232
                        :method: GET
                        :path: /
                        :scheme: https
                        :version: HTTP/1.1
                        accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
                        accept-encoding: gzip, deflate, sdch
                        accept-language: en-US,en;q=0.8,es;q=0.6
                        cache-control: max-age=0
                        cookie: [17 bytes were stripped]
                        user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36
                    --> spdy_priority = 0
                    --> stream_id = 1
                    --> unidirectional = false
t=201631 [st=10]    SPDY_SESSION_PUSHED_SYN_STREAM
                    --> associated_stream = 1
                    --> fin = false
                    --> :host: localhost:3232
                        :method: GET
                        :path: /newasset.js
                        :scheme: https
                        :status: 200
                        :version: HTTP/1.1
                        content-type: application/javascript
                    --> spdy_priority = 7
                    --> stream_id = 2
                    --> unidirectional = true
t=201669 [st=48]    SPDY_SESSION_PUSHED_SYN_STREAM
                    --> associated_stream = 1
                    --> fin = false
                    --> :host: localhost:3232
                        :method: GET
                        :path: /asset.js
                        :scheme: https
                        :status: 200
                        :version: HTTP/1.1
                        location: /newasset.js
                    --> spdy_priority = 7
                    --> stream_id = 4
                    --> unidirectional = true
t=201669 [st=48]    SPDY_SESSION_SYN_REPLY
                    --> fin = false
                    --> :status: 200 OK
                        :version: HTTP/1.1
                        date: Tue, 19 May 2015 18:51:44 GMT
                    --> stream_id = 1
t=201669 [st=48]    SPDY_SESSION_RECV_DATA
                    --> fin = false
                    --> size = 33
                    --> stream_id = 1
t=201669 [st=48]    SPDY_SESSION_UPDATE_RECV_WINDOW
                    --> delta = -33
                    --> window_size = 10485727
t=201669 [st=48]    SPDY_SESSION_RECV_DATA
                    --> fin = false
                    --> size = 45
                    --> stream_id = 2
t=201669 [st=48]    SPDY_SESSION_UPDATE_RECV_WINDOW
                    --> delta = -45
                    --> window_size = 10485682
t=201669 [st=48]    SPDY_SESSION_RECV_DATA
                    --> fin = false
                    --> size = 12
                    --> stream_id = 4
t=201669 [st=48]    SPDY_SESSION_UPDATE_RECV_WINDOW
                    --> delta = -12
                    --> window_size = 10485670
t=201669 [st=48]    SPDY_SESSION_RECV_DATA
                    --> fin = true
                    --> size = 0
                    --> stream_id = 1
t=201669 [st=48]    SPDY_STREAM_UPDATE_RECV_WINDOW
                    --> delta = 33
                    --> window_size = 10485703
t=201670 [st=49]    SPDY_SESSION_RECV_DATA
                    --> fin = true
                    --> size = 0
                    --> stream_id = 2
t=201670 [st=49]    SPDY_SESSION_RECV_DATA
                    --> fin = true
                    --> size = 0
                    --> stream_id = 4
t=201710 [st=89]    SPDY_STREAM_ADOPTED_PUSH_STREAM
                    --> stream_id = 4
                    --> url = "https://localhost:3232/asset.js"
t=201711 [st=90]    SPDY_STREAM_UPDATE_RECV_WINDOW
                    --> delta = 12
                    --> window_size = 10485715

You can see that Chrome is receiving a status code of 200 when it gets the location: /newasset.js.

I'm using latest master, d22e2d5be66b3d04da31b5f38818812040d52b2d

indutny commented 8 years ago

Does it work now with the latest 2.x node-spdy?

shekhei commented 8 years ago

I suspect it is due to lib/spdy/response.js

the push function actually sets the status to 200, its not working for me.

jacobheun commented 5 years ago

Closed due to age, I do believe this is fixed though. Feel free to comment/reopen if this is still and issue.