1// Copyright Joyent, Inc. and other Node contributors.
2//
3// Permission is hereby granted, free of charge, to any person obtaining a
4// copy of this software and associated documentation files (the
5// "Software"), to deal in the Software without restriction, including
6// without limitation the rights to use, copy, modify, merge, publish,
7// distribute, sublicense, and/or sell copies of the Software, and to permit
8// persons to whom the Software is furnished to do so, subject to the
9// following conditions:
10//
11// The above copyright notice and this permission notice shall be included
12// in all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20// USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22'use strict';
23// Verify that the HTTP server implementation handles multiple instances
24// of the same header as per RFC2616: joining the handful of fields by ', '
25// that support it, and dropping duplicates for other fields.
26
27require('../common');
28const assert = require('assert');
29const http = require('http');
30
31const server = http.createServer(function(req, res) {
32  assert.strictEqual(req.headers.accept, 'abc, def, ghijklmnopqrst');
33  assert.strictEqual(req.headers.host, 'foo');
34  assert.strictEqual(req.headers['www-authenticate'], 'foo, bar, baz');
35  assert.strictEqual(req.headers['proxy-authenticate'], 'foo, bar, baz');
36  assert.strictEqual(req.headers['x-foo'], 'bingo');
37  assert.strictEqual(req.headers['x-bar'], 'banjo, bango');
38  assert.strictEqual(req.headers['sec-websocket-protocol'], 'chat, share');
39  assert.strictEqual(req.headers['sec-websocket-extensions'],
40                     'foo; 1, bar; 2, baz');
41  assert.strictEqual(req.headers.constructor, 'foo, bar, baz');
42
43  res.writeHead(200, { 'Content-Type': 'text/plain' });
44  res.end('EOF');
45
46  server.close();
47});
48
49server.listen(0, function() {
50  http.get({
51    host: 'localhost',
52    port: this.address().port,
53    path: '/',
54    headers: [
55      ['accept', 'abc'],
56      ['accept', 'def'],
57      ['Accept', 'ghijklmnopqrst'],
58      ['host', 'foo'],
59      ['Host', 'bar'],
60      ['hOst', 'baz'],
61      ['www-authenticate', 'foo'],
62      ['WWW-Authenticate', 'bar'],
63      ['WWW-AUTHENTICATE', 'baz'],
64      ['proxy-authenticate', 'foo'],
65      ['Proxy-Authenticate', 'bar'],
66      ['PROXY-AUTHENTICATE', 'baz'],
67      ['x-foo', 'bingo'],
68      ['x-bar', 'banjo'],
69      ['x-bar', 'bango'],
70      ['sec-websocket-protocol', 'chat'],
71      ['sec-websocket-protocol', 'share'],
72      ['sec-websocket-extensions', 'foo; 1'],
73      ['sec-websocket-extensions', 'bar; 2'],
74      ['sec-websocket-extensions', 'baz'],
75      ['constructor', 'foo'],
76      ['constructor', 'bar'],
77      ['constructor', 'baz'],
78    ]
79  });
80});
81