2017-01-03 13:16:48 -08:00
|
|
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the
|
|
|
|
// "Software"), to deal in the Software without restriction, including
|
|
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
|
|
// persons to whom the Software is furnished to do so, subject to the
|
|
|
|
// following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included
|
|
|
|
// in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
|
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-07-15 15:43:24 -04:00
|
|
|
const common = require('../common');
|
2016-12-30 18:38:06 -05:00
|
|
|
const assert = require('assert');
|
2011-09-14 16:29:32 +02:00
|
|
|
|
2016-12-30 18:38:06 -05:00
|
|
|
const http = require('http');
|
|
|
|
const net = require('net');
|
2011-09-14 16:29:32 +02:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const server = net.createServer(function(conn) {
|
|
|
|
const body = 'Yet another node.js server.';
|
2011-09-14 16:29:32 +02:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const response =
|
2011-10-04 18:08:18 -04:00
|
|
|
'HTTP/1.1 200 OK\r\n' +
|
|
|
|
'Connection: close\r\n' +
|
2017-07-16 15:55:28 +08:00
|
|
|
`Content-Length: ${body.length}\r\n` +
|
2011-10-04 18:08:18 -04:00
|
|
|
'Content-Type: text/plain;\r\n' +
|
|
|
|
' x-unix-mode=0600;\r\n' +
|
2016-09-18 01:43:49 -04:00
|
|
|
' name="hello.txt"\r\n' +
|
2011-10-04 18:08:18 -04:00
|
|
|
'\r\n' +
|
|
|
|
body;
|
2011-09-14 16:29:32 +02:00
|
|
|
|
2013-02-02 20:52:04 -08:00
|
|
|
conn.end(response);
|
|
|
|
server.close();
|
2011-09-14 16:29:32 +02:00
|
|
|
});
|
|
|
|
|
2016-07-15 15:43:24 -04:00
|
|
|
server.listen(0, common.mustCall(function() {
|
|
|
|
http.get({
|
|
|
|
host: '127.0.0.1',
|
2024-03-14 16:45:42 +01:00
|
|
|
port: this.address().port,
|
|
|
|
insecureHTTPParser: true
|
2016-07-15 15:43:24 -04:00
|
|
|
}, common.mustCall(function(res) {
|
2017-01-08 15:36:25 +00:00
|
|
|
assert.strictEqual(res.headers['content-type'],
|
|
|
|
'text/plain; x-unix-mode=0600; name="hello.txt"');
|
2013-02-02 20:52:04 -08:00
|
|
|
res.destroy();
|
2016-07-15 15:43:24 -04:00
|
|
|
}));
|
|
|
|
}));
|