summaryrefslogtreecommitdiffstats
path: root/test/redirect-upgrade.js
blob: dbe584065dfcf3af344eb836bcc2afb3158eb953 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict'

const t = require('tap')
const { upgrade } = require('..')
const { startServer } = require('./utils/redirecting-servers')

t.test('should upgrade the connection when no redirects are present', async t => {
  t.plan(2)

  const server = await startServer(t, (req, res) => {
    if (req.url === '/') {
      res.statusCode = 301
      res.setHeader('Location', `http://${server}/end`)
      res.end('REDIRECT')
      return
    }

    res.statusCode = 101
    res.setHeader('Connection', 'upgrade')
    res.setHeader('Upgrade', req.headers.upgrade)
    res.end('')
  })

  const { headers, socket } = await upgrade(`http://${server}/`, {
    method: 'GET',
    protocol: 'foo/1',
    maxRedirections: 10
  })

  socket.end()

  t.equal(headers.connection, 'upgrade')
  t.equal(headers.upgrade, 'foo/1')
})