HEX
Server: nginx/1.24.0
System: Linux nowruzgan 6.8.0-57-generic #59-Ubuntu SMP PREEMPT_DYNAMIC Sat Mar 15 17:40:59 UTC 2025 x86_64
User: babak (1000)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: /var/dev/nowruzgan/admin/node_modules/parse-headers/test.js
var test = require('tape')
  , parse = require('./parse-headers')

  , headers1 = [
        ''
      , 'Date: Sun, 17 Aug 2014 16:24:52 GMT'
      , 'Content-Type: text/html; charset=utf-8'
      , 'Transfer-Encoding: chunked'
      , ''
    ]
  , headers2 = [
        ''
      , 'Date: Sun, 17 Aug 2014 16:24:52 GMT'
      , 'Content-Type: text/html; charset=utf-8'
      , 'Transfer-Encoding: chunked'
      , 'Set-Cookie: Foo'
      , 'set-Cookie: bar'
      , 'set-cookie: bong'
    ]

test('sanity check', function (t) {

  t.deepEqual(parse(), {})
  t.deepEqual(parse(''), {})
  t.end()
})

test('simple', function (t) {
  t.deepEqual(
      parse(headers1.join('\r\n'))
    , {
          date: 'Sun, 17 Aug 2014 16:24:52 GMT'
        , 'content-type': 'text/html; charset=utf-8'
        , 'transfer-encoding': 'chunked'
      }
  )
  t.deepEqual(
      parse(headers1.join('\n'))
    , {
          date: 'Sun, 17 Aug 2014 16:24:52 GMT'
        , 'content-type': 'text/html; charset=utf-8'
        , 'transfer-encoding': 'chunked'
      }
  )

  t.end()
})

test('duplicate keys', function (t) {
  t.deepEqual(
      parse(headers2.join('\r\n'))
    , {
          date: 'Sun, 17 Aug 2014 16:24:52 GMT'
        , 'content-type': 'text/html; charset=utf-8'
        , 'transfer-encoding': 'chunked'
        , 'set-cookie': [ 'Foo', 'bar', 'bong' ]
      }
  )
  t.deepEqual(
      parse(headers2.join('\n'))
    , {
          date: 'Sun, 17 Aug 2014 16:24:52 GMT'
        , 'content-type': 'text/html; charset=utf-8'
        , 'transfer-encoding': 'chunked'
        , 'set-cookie': [ 'Foo', 'bar', 'bong' ]
      }
  )

  t.end()
})