1 // Copyright Joyent, Inc. and other Node contributors.
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:
11 // The above copyright notice and this permission notice shall be included
12 // in all copies or substantial portions of the Software.
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.
22 var common = require('../common');
23 var assert = require('assert');
24 var http = require('http');
25 var net = require('net');
27 // If an HTTP server is broken and sends data after the end of the response,
28 // node should ignore it and drop the connection.
29 // Demos this bug: https://github.com/ry/node/issues/680
31 var body = 'hello world\r\n';
33 'HTTP/1.1 500 Internal Server Error\r\n' +
34 'Content-Length: ' + body.length + '\r\n' +
35 'Content-Type: text/plain\r\n' +
36 'Date: Fri + 18 Feb 2011 06:22:45 GMT\r\n' +
37 'Host: 10.20.149.2\r\n' +
38 'Access-Control-Allow-Credentials: true\r\n' +
39 'Server: badly broken/0.1 (OS NAME)\r\n' +
43 var gotResponse = false;
46 var server = net.createServer(function (socket) {
49 socket.setEncoding('utf8');
51 socket.on('data', function (chunk) {
54 if (postBody.indexOf('\r\n') > -1) {
55 socket.write(fullResponse);
56 // omg, I wrote the response twice, what a terrible HTTP server I am.
57 socket.end(fullResponse);
63 server.listen(common.PORT, function () {
64 http.get({ port: common.PROXY_PORT }, function (res) {
66 console.log('Got res code: ' + res.statusCode);
68 res.setEncoding('utf8');
69 res.on('data', function (chunk) {
73 res.on('end', function () {
74 console.log('Response ended, read ' + buffer.length + ' bytes');
75 assert.equal(body, buffer);
83 process.on('exit', function () {
84 assert.ok(gotResponse);