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');
|
|
|
|
const http = require('http');
|
|
|
|
const net = require('net');
|
2010-07-07 18:43:39 +02:00
|
|
|
|
2017-07-14 15:05:24 -07:00
|
|
|
const server = http.createServer(common.mustCall((req, res) => {
|
2017-01-08 15:36:25 +00:00
|
|
|
assert.strictEqual('GET', req.method);
|
|
|
|
assert.strictEqual('/blah', req.url);
|
2016-04-19 15:37:45 -07:00
|
|
|
assert.deepStrictEqual({
|
2017-07-14 15:05:24 -07:00
|
|
|
host: 'example.org:443',
|
|
|
|
origin: 'http://example.org',
|
2010-12-06 01:33:52 +03:00
|
|
|
cookie: ''
|
2010-07-07 18:43:39 +02:00
|
|
|
}, req.headers);
|
2016-07-15 15:43:24 -04:00
|
|
|
}));
|
2010-07-07 18:43:39 +02:00
|
|
|
|
|
|
|
|
2017-07-14 15:05:24 -07:00
|
|
|
server.listen(0, common.mustCall(() => {
|
|
|
|
const c = net.createConnection(server.address().port);
|
2017-09-11 11:00:10 +09:00
|
|
|
let received = '';
|
2010-07-07 18:43:39 +02:00
|
|
|
|
2017-07-14 15:05:24 -07:00
|
|
|
c.on('connect', common.mustCall(() => {
|
2010-12-06 01:33:52 +03:00
|
|
|
c.write('GET /blah HTTP/1.1\r\n' +
|
2017-07-14 15:05:24 -07:00
|
|
|
'Host: example.org:443\r\n' +
|
2010-12-06 01:33:52 +03:00
|
|
|
'Cookie:\r\n' +
|
2017-07-14 15:05:24 -07:00
|
|
|
'Origin: http://example.org\r\n' +
|
2010-12-06 01:33:52 +03:00
|
|
|
'\r\n\r\nhello world'
|
|
|
|
);
|
2017-07-14 15:05:24 -07:00
|
|
|
}));
|
2017-09-11 11:00:10 +09:00
|
|
|
c.on('data', common.mustCall((data) => {
|
|
|
|
received += data.toString();
|
|
|
|
}));
|
|
|
|
c.on('end', common.mustCall(() => {
|
|
|
|
assert.strictEqual('HTTP/1.1 400 Bad Request\r\n\r\n', received);
|
|
|
|
c.end();
|
|
|
|
}));
|
2017-07-14 15:05:24 -07:00
|
|
|
c.on('close', common.mustCall(() => server.close()));
|
|
|
|
}));
|