summaryrefslogtreecommitdiff
path: root/test/disabled/test-http-head-request.js
blob: 2dfe20bc3d06d8ad8bb49fab6791ebcb71425f49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
var common = require('../common');
var assert = require('assert');

var assert = require('assert');
var http = require('http');
var util = require('util');

var body = 'hello world';

var server = http.createServer(function(req, res) {
  res.writeHeader(200,
                  {'Content-Length': body.length.toString(),
                    'Content-Type': 'text/plain'
                  });
  console.log('method: ' + req.method);
  if (req.method != 'HEAD') res.write(body);
  res.end();
});
server.listen(common.PORT);

var gotEnd = false;

server.on('listening', function() {
  var request = http.request({
    port: common.PORT,
    method: 'HEAD',
    path: '/'
  }, function(response) {
    console.log('got response');
    response.on('data', function() {
      process.exit(2);
    });
    response.on('end', function() {
      process.exit(0);
    });
  });
  request.end();
});

//give a bit of time for the server to respond before we check it
setTimeout(function() {
  process.exit(1);
}, 2000);