mirror of
https://github.com/denoland/deno.git
synced 2024-12-18 21:35:31 -05:00
fb24fd37c9
This PR enables node compat test cases found passing by using the tool added in #27122 The percentage of passing test case increases from 16.16% to 30.43% by this change.
78 lines
2.2 KiB
JavaScript
78 lines
2.2 KiB
JavaScript
// deno-fmt-ignore-file
|
|
// deno-lint-ignore-file
|
|
|
|
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
|
// Taken from Node 20.11.1
|
|
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
|
|
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
const http = require('http');
|
|
const assert = require('assert');
|
|
const Countdown = require('../common/countdown');
|
|
|
|
// Test that certain response header fields do not repeat.
|
|
// 'content-length' should also be in this list but it is
|
|
// handled differently because multiple content-lengths are
|
|
// an error (see test-http-response-multi-content-length.js).
|
|
const norepeat = [
|
|
'content-type',
|
|
'user-agent',
|
|
'referer',
|
|
'host',
|
|
'authorization',
|
|
'proxy-authorization',
|
|
'if-modified-since',
|
|
'if-unmodified-since',
|
|
'from',
|
|
'location',
|
|
'max-forwards',
|
|
'retry-after',
|
|
'etag',
|
|
'last-modified',
|
|
'server',
|
|
'age',
|
|
'expires',
|
|
];
|
|
const runCount = 2;
|
|
|
|
const server = http.createServer(function(req, res) {
|
|
const num = req.headers['x-num'];
|
|
if (num === '1') {
|
|
for (const name of norepeat) {
|
|
res.setHeader(name, ['A', 'B']);
|
|
}
|
|
res.setHeader('X-A', ['A', 'B']);
|
|
} else if (num === '2') {
|
|
const headers = {};
|
|
for (const name of norepeat) {
|
|
headers[name] = ['A', 'B'];
|
|
}
|
|
headers['X-A'] = ['A', 'B'];
|
|
res.writeHead(200, headers);
|
|
}
|
|
res.end('ok');
|
|
});
|
|
|
|
server.listen(0, common.mustCall(function() {
|
|
const countdown = new Countdown(runCount, () => server.close());
|
|
for (let n = 1; n <= runCount; n++) {
|
|
// This runs twice, the first time, the server will use
|
|
// setHeader, the second time it uses writeHead. The
|
|
// result on the client side should be the same in
|
|
// either case -- only the first instance of the header
|
|
// value should be reported for the header fields listed
|
|
// in the norepeat array.
|
|
http.get(
|
|
{ port: this.address().port, headers: { 'x-num': n } },
|
|
common.mustCall(function(res) {
|
|
countdown.dec();
|
|
for (const name of norepeat) {
|
|
assert.strictEqual(res.headers[name], 'A');
|
|
}
|
|
assert.strictEqual(res.headers['x-a'], 'A, B');
|
|
})
|
|
);
|
|
}
|
|
}));
|