Sha256: 2a8232402c4618f30a84765c39a505ac8211628db4e87a76c894e5da22def4b9

Contents?: true

Size: 1.09 KB

Versions: 43

Compression:

Stored size: 1.09 KB

Contents

var Buffer = require('buffer').Buffer
var fs = require('fs')
var test = require('tape')

var http = require('../..')

test('abort before response', function (t) {
	var req = http.get('/basic.txt', function (res) {
		t.fail('unexpected response')
	})
	req.abort()
	t.end()
})

test('abort on response', function (t) {
	var req = http.get('/basic.txt', function (res) {
		req.abort()
		t.end()

		res.on('end', function () {
			t.fail('unexpected end')
		})

		res.on('data', function (data) {
			t.fail('unexpected data')
		})
	})
})

test('abort on data', function (t) {
	var req = http.get('/browserify.png?copies=5', function (res) {
		var firstData = true
		var failOnData = false

		res.on('end', function () {
			t.fail('unexpected end')
		})

		res.on('data', function (data) {
			if (failOnData)
				t.fail('unexpected data')
			else if (firstData) {
				firstData = false
				req.abort()
				t.end()
				process.nextTick(function () {
					// Wait for any data that may have been queued
					// in the stream before considering data events
					// as errors
					failOnData = true
				})
			}
		})
	})
})

Version data entries

43 entries across 42 versions & 15 rubygems

Version Path
brwy_rails-0.0.3 test/dummy/node_modules/stream-http/test/browser/abort.js
brwy_rails-0.0.2 test/dummy/node_modules/stream-http/test/browser/abort.js
brwy_rails-0.0.1 test/dummy/node_modules/stream-http/test/browser/abort.js