Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test-http-head-request.js « parallel « test - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: de94dfb8b7d6e7601de395cc302ab59528176be3 (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
'use strict';
const common = require('../common');
const http = require('http');

const body = 'hello world\n';

function test(headers) {
  const server = http.createServer(function(req, res) {
    console.error('req: %s headers: %j', req.method, headers);
    res.writeHead(200, headers);
    res.end();
    server.close();
  });

  server.listen(0, common.mustCall(function() {
    const request = http.request({
      port: this.address().port,
      method: 'HEAD',
      path: '/'
    }, common.mustCall(function(response) {
      console.error('response start');
      response.on('end', common.mustCall(function() {
        console.error('response end');
      }));
      response.resume();
    }));
    request.end();
  }));
}

test({
  'Transfer-Encoding': 'chunked'
});
test({
  'Content-Length': body.length
});