| 28 | |
| 29 | class FakeAgent extends http.Agent { |
| 30 | createConnection() { |
| 31 | const s = new Duplex(); |
| 32 | let once = false; |
| 33 | |
| 34 | s._read = function() { |
| 35 | if (once) |
| 36 | return this.push(null); |
| 37 | once = true; |
| 38 | |
| 39 | this.push('HTTP/1.1 200 Ok\r\nTransfer-Encoding: chunked\r\n\r\n'); |
| 40 | this.push('b\r\nhello world\r\n'); |
| 41 | this.readable = false; |
| 42 | this.push('0\r\n\r\n'); |
| 43 | }; |
| 44 | |
| 45 | // Blackhole |
| 46 | s._write = function(data, enc, cb) { |
| 47 | cb(); |
| 48 | }; |
| 49 | |
| 50 | s.destroy = s.destroySoon = function() { |
| 51 | this.writable = false; |
| 52 | }; |
| 53 | |
| 54 | return s; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | let received = ''; |