mirror of https://github.com/lukechilds/node.git
Browse Source
PR-URL: https://github.com/nodejs/node-private/pull/26 Reviewed-By: Rod Vagg <r@va.gg> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>process-exit-stdio-flushing
James M Snell
9 years ago
5 changed files with 92 additions and 97 deletions
@ -1,87 +0,0 @@ |
|||||
'use strict'; |
|
||||
const common = require('../common'); |
|
||||
const assert = require('assert'); |
|
||||
const http = require('http'); |
|
||||
|
|
||||
var testIndex = 0; |
|
||||
const testCount = 2 * 4 * 6; |
|
||||
const responseBody = 'Hi mars!'; |
|
||||
|
|
||||
var server = http.createServer(function(req, res) { |
|
||||
function reply(header) { |
|
||||
switch (testIndex % 4) { |
|
||||
case 0: |
|
||||
res.writeHead(200, { a: header, b: header }); |
|
||||
break; |
|
||||
case 1: |
|
||||
res.setHeader('a', header); |
|
||||
res.setHeader('b', header); |
|
||||
res.writeHead(200); |
|
||||
break; |
|
||||
case 2: |
|
||||
res.setHeader('a', header); |
|
||||
res.writeHead(200, { b: header }); |
|
||||
break; |
|
||||
case 3: |
|
||||
res.setHeader('a', [header]); |
|
||||
res.writeHead(200, { b: header }); |
|
||||
break; |
|
||||
default: |
|
||||
assert.fail(null, null, 'unreachable'); |
|
||||
} |
|
||||
res.write(responseBody); |
|
||||
if (testIndex % 8 < 4) { |
|
||||
res.addTrailers({ ta: header, tb: header }); |
|
||||
} else { |
|
||||
res.addTrailers([['ta', header], ['tb', header]]); |
|
||||
} |
|
||||
res.end(); |
|
||||
} |
|
||||
switch ((testIndex / 8) | 0) { |
|
||||
case 0: |
|
||||
reply('foo \r\ninvalid: bar'); |
|
||||
break; |
|
||||
case 1: |
|
||||
reply('foo \ninvalid: bar'); |
|
||||
break; |
|
||||
case 2: |
|
||||
reply('foo \rinvalid: bar'); |
|
||||
break; |
|
||||
case 3: |
|
||||
reply('foo \n\n\ninvalid: bar'); |
|
||||
break; |
|
||||
case 4: |
|
||||
reply('foo \r\n \r\n \r\ninvalid: bar'); |
|
||||
break; |
|
||||
case 5: |
|
||||
reply('foo \r \n \r \n \r \ninvalid: bar'); |
|
||||
break; |
|
||||
default: |
|
||||
assert(false); |
|
||||
} |
|
||||
if (++testIndex === testCount) { |
|
||||
server.close(); |
|
||||
} |
|
||||
}); |
|
||||
|
|
||||
server.listen(common.PORT, common.mustCall(function() { |
|
||||
for (var i = 0; i < testCount; i++) { |
|
||||
http.get({ port: common.PORT, path: '/' }, common.mustCall(function(res) { |
|
||||
assert.strictEqual(res.headers.a, 'foo invalid: bar'); |
|
||||
assert.strictEqual(res.headers.b, 'foo invalid: bar'); |
|
||||
assert.strictEqual(res.headers.foo, undefined); |
|
||||
assert.strictEqual(res.headers.invalid, undefined); |
|
||||
var data = ''; |
|
||||
res.setEncoding('utf8'); |
|
||||
res.on('data', function(s) { data += s; }); |
|
||||
res.on('end', common.mustCall(function() { |
|
||||
assert.equal(data, responseBody); |
|
||||
assert.strictEqual(res.trailers.ta, 'foo invalid: bar'); |
|
||||
assert.strictEqual(res.trailers.tb, 'foo invalid: bar'); |
|
||||
assert.strictEqual(res.trailers.foo, undefined); |
|
||||
assert.strictEqual(res.trailers.invalid, undefined); |
|
||||
})); |
|
||||
res.resume(); |
|
||||
})); |
|
||||
} |
|
||||
})); |
|
@ -0,0 +1,55 @@ |
|||||
|
'use strict'; |
||||
|
|
||||
|
const common = require('../common'); |
||||
|
const http = require('http'); |
||||
|
const net = require('net'); |
||||
|
const url = require('url'); |
||||
|
const assert = require('assert'); |
||||
|
|
||||
|
// Response splitting example, credit: Amit Klein, Safebreach
|
||||
|
const str = '/welcome?lang=bar%c4%8d%c4%8aContentLength:%200%c4%8d%c4%8a%c' + |
||||
|
'4%8d%c4%8aHTTP/1.1%20200%20OK%c4%8d%c4%8aContentLength:%202' + |
||||
|
'0%c4%8d%c4%8aLastModified:%20Mon,%2027%20Oct%202003%2014:50:18' + |
||||
|
'%20GMT%c4%8d%c4%8aContentType:%20text/html%c4%8d%c4%8a%c4%8' + |
||||
|
'd%c4%8a%3chtml%3eGotcha!%3c/html%3e'; |
||||
|
|
||||
|
// Response splitting example, credit: Сковорода Никита Андреевич (@ChALkeR)
|
||||
|
const x = 'fooഊSet-Cookie: foo=barഊഊ<script>alert("Hi!")</script>'; |
||||
|
const y = 'foo⠊Set-Cookie: foo=bar'; |
||||
|
|
||||
|
var count = 0; |
||||
|
|
||||
|
const server = http.createServer((req, res) => { |
||||
|
switch (count++) { |
||||
|
case 0: |
||||
|
const loc = url.parse(req.url, true).query.lang; |
||||
|
assert.throws(common.mustCall(() => { |
||||
|
res.writeHead(302, {Location: `/foo?lang=${loc}`}); |
||||
|
})); |
||||
|
break; |
||||
|
case 1: |
||||
|
assert.throws(common.mustCall(() => { |
||||
|
res.writeHead(200, {'foo' : x}); |
||||
|
})); |
||||
|
break; |
||||
|
case 2: |
||||
|
assert.throws(common.mustCall(() => { |
||||
|
res.writeHead(200, {'foo' : y}); |
||||
|
})); |
||||
|
break; |
||||
|
default: |
||||
|
assert.fail(null, null, 'should not get to here.'); |
||||
|
} |
||||
|
if (count === 3) |
||||
|
server.close(); |
||||
|
res.end('ok'); |
||||
|
}); |
||||
|
server.listen(common.PORT, () => { |
||||
|
const end = 'HTTP/1.1\r\n\r\n'; |
||||
|
const client = net.connect({port: common.PORT}, () => { |
||||
|
client.write(`GET ${str} ${end}`); |
||||
|
client.write(`GET / ${end}`); |
||||
|
client.write(`GET / ${end}`); |
||||
|
client.end(); |
||||
|
}); |
||||
|
}); |
Loading…
Reference in new issue