2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-05-29 09:06:56 +02:00
|
|
|
require('../common');
|
2013-08-06 03:41:17 +02:00
|
|
|
var assert = require('assert');
|
|
|
|
|
|
|
|
var http = require('http');
|
|
|
|
|
|
|
|
http.createServer(function(req, res) {
|
|
|
|
var expectRawHeaders = [
|
|
|
|
'Host',
|
2016-05-29 09:06:56 +02:00
|
|
|
`localhost:${this.address().port}`,
|
2013-08-06 03:41:17 +02:00
|
|
|
'transfer-ENCODING',
|
|
|
|
'CHUNKED',
|
|
|
|
'x-BaR',
|
|
|
|
'yoyoyo',
|
|
|
|
'Connection',
|
2013-08-18 03:50:59 +02:00
|
|
|
'close'
|
2013-08-06 03:41:17 +02:00
|
|
|
];
|
|
|
|
var expectHeaders = {
|
2016-05-29 09:06:56 +02:00
|
|
|
host: `localhost:${this.address().port}`,
|
2013-08-06 03:41:17 +02:00
|
|
|
'transfer-encoding': 'CHUNKED',
|
|
|
|
'x-bar': 'yoyoyo',
|
2013-08-18 03:50:59 +02:00
|
|
|
connection: 'close'
|
2013-08-06 03:41:17 +02:00
|
|
|
};
|
|
|
|
var expectRawTrailers = [
|
|
|
|
'x-bAr',
|
|
|
|
'yOyOyOy',
|
|
|
|
'x-baR',
|
|
|
|
'OyOyOyO',
|
|
|
|
'X-bAr',
|
|
|
|
'yOyOyOy',
|
|
|
|
'X-baR',
|
|
|
|
'OyOyOyO'
|
|
|
|
];
|
|
|
|
var expectTrailers = { 'x-bar': 'yOyOyOy, OyOyOyO, yOyOyOy, OyOyOyO' };
|
|
|
|
|
2016-05-29 09:06:56 +02:00
|
|
|
this.close();
|
|
|
|
|
2016-04-20 00:37:45 +02:00
|
|
|
assert.deepStrictEqual(req.rawHeaders, expectRawHeaders);
|
|
|
|
assert.deepStrictEqual(req.headers, expectHeaders);
|
2013-08-06 03:41:17 +02:00
|
|
|
|
|
|
|
req.on('end', function() {
|
2016-04-20 00:37:45 +02:00
|
|
|
assert.deepStrictEqual(req.rawTrailers, expectRawTrailers);
|
|
|
|
assert.deepStrictEqual(req.trailers, expectTrailers);
|
2013-08-06 03:41:17 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
req.resume();
|
2015-03-03 21:01:26 +01:00
|
|
|
res.setHeader('Trailer', 'x-foo');
|
2013-08-06 03:41:17 +02:00
|
|
|
res.addTrailers([
|
|
|
|
['x-fOo', 'xOxOxOx'],
|
|
|
|
['x-foO', 'OxOxOxO'],
|
|
|
|
['X-fOo', 'xOxOxOx'],
|
|
|
|
['X-foO', 'OxOxOxO']
|
|
|
|
]);
|
|
|
|
res.end('x f o o');
|
2016-05-29 09:06:56 +02:00
|
|
|
}).listen(0, function() {
|
|
|
|
var req = http.request({ port: this.address().port, path: '/' });
|
2013-08-06 03:41:17 +02:00
|
|
|
req.addTrailers([
|
|
|
|
['x-bAr', 'yOyOyOy'],
|
|
|
|
['x-baR', 'OyOyOyO'],
|
|
|
|
['X-bAr', 'yOyOyOy'],
|
|
|
|
['X-baR', 'OyOyOyO']
|
|
|
|
]);
|
|
|
|
req.setHeader('transfer-ENCODING', 'CHUNKED');
|
|
|
|
req.setHeader('x-BaR', 'yoyoyo');
|
|
|
|
req.end('y b a r');
|
|
|
|
req.on('response', function(res) {
|
|
|
|
var expectRawHeaders = [
|
2015-03-03 21:01:26 +01:00
|
|
|
'Trailer',
|
|
|
|
'x-foo',
|
2013-08-06 03:41:17 +02:00
|
|
|
'Date',
|
|
|
|
null,
|
|
|
|
'Connection',
|
2013-08-18 03:50:59 +02:00
|
|
|
'close',
|
2013-08-06 03:41:17 +02:00
|
|
|
'Transfer-Encoding',
|
|
|
|
'chunked'
|
|
|
|
];
|
|
|
|
var expectHeaders = {
|
2015-03-03 21:01:26 +01:00
|
|
|
trailer: 'x-foo',
|
2013-08-06 03:41:17 +02:00
|
|
|
date: null,
|
2013-08-18 03:50:59 +02:00
|
|
|
connection: 'close',
|
2013-08-06 03:41:17 +02:00
|
|
|
'transfer-encoding': 'chunked'
|
|
|
|
};
|
2015-03-03 21:01:26 +01:00
|
|
|
res.rawHeaders[3] = null;
|
2013-08-06 03:41:17 +02:00
|
|
|
res.headers.date = null;
|
2016-04-20 00:37:45 +02:00
|
|
|
assert.deepStrictEqual(res.rawHeaders, expectRawHeaders);
|
|
|
|
assert.deepStrictEqual(res.headers, expectHeaders);
|
2013-08-06 03:41:17 +02:00
|
|
|
res.on('end', function() {
|
|
|
|
var expectRawTrailers = [
|
|
|
|
'x-fOo',
|
|
|
|
'xOxOxOx',
|
|
|
|
'x-foO',
|
|
|
|
'OxOxOxO',
|
|
|
|
'X-fOo',
|
|
|
|
'xOxOxOx',
|
|
|
|
'X-foO',
|
|
|
|
'OxOxOxO'
|
|
|
|
];
|
|
|
|
var expectTrailers = { 'x-foo': 'xOxOxOx, OxOxOxO, xOxOxOx, OxOxOxO' };
|
|
|
|
|
2016-04-20 00:37:45 +02:00
|
|
|
assert.deepStrictEqual(res.rawTrailers, expectRawTrailers);
|
|
|
|
assert.deepStrictEqual(res.trailers, expectTrailers);
|
2013-08-06 03:41:17 +02:00
|
|
|
console.log('ok');
|
|
|
|
});
|
|
|
|
res.resume();
|
|
|
|
});
|
|
|
|
});
|