Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

test: add 'response body with no headers' http test

HTTP/0.9 - fails with a parse error
HTTP/1.0 - works
HTTP/1.1 - fails with an empty response body

See #1711.
  • Loading branch information...
commit 246805d3865dc2d8f81037dc7c43069c537a7ed5 1 parent 3abebfe
Ben Noordhuis bnoordhuis authored felixge committed

Showing 1 changed file with 75 additions and 0 deletions. Show diff stats Hide diff stats

  1. +75 0 test/simple/test-http-response-no-headers.js
75 test/simple/test-http-response-no-headers.js
... ... @@ -0,0 +1,75 @@
  1 +// Copyright Joyent, Inc. and other Node contributors.
  2 +//
  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:
  10 +//
  11 +// The above copyright notice and this permission notice shall be included
  12 +// in all copies or substantial portions of the Software.
  13 +//
  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.
  21 +
  22 +var common = require('../common');
  23 +var assert = require('assert');
  24 +var http = require('http');
  25 +var net = require('net');
  26 +
  27 +var expected = 'I AM THE WALRUS';
  28 +
  29 +var gotExpected = false;
  30 +
  31 +function test(httpVersion, callback) {
  32 + process.on('exit', function() {
  33 + assert(gotExpected);
  34 + });
  35 +
  36 + var server = net.createServer(function(conn) {
  37 + var reply = 'HTTP/' + httpVersion + ' 200 OK\r\n\r\n' + expected;
  38 +
  39 + conn.write(reply, function() {
  40 + conn.destroy();
  41 + })
  42 + });
  43 +
  44 + server.listen(common.PORT, '127.0.0.1', function() {
  45 + var options = {
  46 + host: '127.0.0.1',
  47 + port: common.PORT
  48 + };
  49 +
  50 + var req = http.get(options, function(res) {
  51 + var body = '';
  52 +
  53 + res.on('data', function(data) {
  54 + body += data;
  55 + });
  56 +
  57 + res.on('end', function() {
  58 + assert.equal(body, expected);
  59 + gotExpected = true;
  60 + server.close();
  61 + if (callback) process.nextTick(callback);
  62 + });
  63 + });
  64 +
  65 + req.on('error', function(err) {
  66 + throw err;
  67 + });
  68 + });
  69 +}
  70 +
  71 +test('0.9', function() {
  72 + test('1.0', function() {
  73 + test('1.1');
  74 + });
  75 +});

0 comments on commit 246805d

Please sign in to comment.
Something went wrong with that request. Please try again.