blob: 614bb39b1f15969dca12bbb5ab4cf21062953f90 (
plain) (
blame)
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
|
'use strict';
var assert = require('assert');
var PassThrough = require('stream').PassThrough;
var getResponse = require('./get-mock-response.js');
require('../index.js')._request = function (method, url, options, callback) {
assert(typeof callback === 'function');
var duplex = !(method === 'GET' || method === 'DELETE' || method === 'HEAD');
if (duplex) {
return {
end: function (body) {
gotResponse(getResponse(method, url, options.headers, body, {isClient: false}));
}
};
} else {
gotResponse(getResponse(method, url, options.headers, null, {isClient: false}));
}
function gotResponse(res) {
var stream = new PassThrough();
stream.end(res.body);
res.body = stream;
callback(null, res);
}
};
|