| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c740cb6 commit 76f0556
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,11 +1,10 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - require('../common'); | ||
| 2 | + const common = require('../common'); | ||
| 3 | 3 | const http = require('http'); | |
| 4 | 4 | const assert = require('assert'); | |
| 5 | 5 | const httpServer = http.createServer(reqHandler); | |
| 6 | 6 | ||
| 7 | 7 | function reqHandler(req, res) { | |
| 8 | - console.log('Got request: ' + req.headers.host + ' ' + req.url); | ||
| 9 | 8 | if (req.url === '/setHostFalse5') { | |
| 10 | 9 | assert.equal(req.headers.host, undefined); | |
| 11 | 10 | } else { | |
@@ -14,14 +13,9 @@ function reqHandler(req, res) { | |||
| 14 | 13 | req.headers.host); | |
| 15 | 14 | } | |
| 16 | 15 | res.writeHead(200, {}); | |
| 17 | - //process.nextTick(function() { res.end('ok'); }); | ||
| 18 | 16 | res.end('ok'); | |
| 19 | 17 | } | |
| 20 | 18 | ||
| 21 | - function thrower(er) { | ||
| 22 | - throw er; | ||
| 23 | - } | ||
| 24 | - | ||
| 25 | 19 | testHttp(); | |
| 26 | 20 | ||
| 27 | 21 | function testHttp() { | |
@@ -30,61 +24,52 @@ function testHttp() { | |||
| 30 | 24 | ||
| 31 | 25 | function cb(res) { | |
| 32 | 26 | counter--; | |
| 33 | - console.log('back from http request. counter = ' + counter); | ||
| 34 | 27 | if (counter === 0) { | |
| 35 | 28 | httpServer.close(); | |
| 36 | 29 | } | |
| 37 | 30 | res.resume(); | |
| 38 | 31 | } | |
| 39 | 32 | ||
| 40 | - httpServer.listen(0, function(er) { | ||
| 41 | - console.error(`test http server listening on ${this.address().port}`); | ||
| 42 | - | ||
| 43 | - if (er) throw er; | ||
| 44 | - | ||
| 33 | + httpServer.listen(0, (er) => { | ||
| 34 | + assert.ifError(er); | ||
| 45 | 35 | http.get({ | |
| 46 | 36 | method: 'GET', | |
| 47 | 37 | path: '/' + (counter++), | |
| 48 | 38 | host: 'localhost', | |
| 49 | - //agent: false, | ||
| 50 | - port: this.address().port, | ||
| 39 | + port: httpServer.address().port, | ||
| 51 | 40 | rejectUnauthorized: false | |
| 52 | - }, cb).on('error', thrower); | ||
| 41 | + }, cb).on('error', common.fail); | ||
| 53 | 42 | ||
| 54 | 43 | http.request({ | |
| 55 | 44 | method: 'GET', | |
| 56 | 45 | path: '/' + (counter++), | |
| 57 | 46 | host: 'localhost', | |
| 58 | - //agent: false, | ||
| 59 | - port: this.address().port, | ||
| 47 | + port: httpServer.address().port, | ||
| 60 | 48 | rejectUnauthorized: false | |
| 61 | - }, cb).on('error', thrower).end(); | ||
| 49 | + }, cb).on('error', common.fail).end(); | ||
| 62 | 50 | ||
| 63 | 51 | http.request({ | |
| 64 | 52 | method: 'POST', | |
| 65 | 53 | path: '/' + (counter++), | |
| 66 | 54 | host: 'localhost', | |
| 67 | - //agent: false, | ||
| 68 | - port: this.address().port, | ||
| 55 | + port: httpServer.address().port, | ||
| 69 | 56 | rejectUnauthorized: false | |
| 70 | - }, cb).on('error', thrower).end(); | ||
| 57 | + }, cb).on('error', common.fail).end(); | ||
| 71 | 58 | ||
| 72 | 59 | http.request({ | |
| 73 | 60 | method: 'PUT', | |
| 74 | 61 | path: '/' + (counter++), | |
| 75 | 62 | host: 'localhost', | |
| 76 | - //agent: false, | ||
| 77 | - port: this.address().port, | ||
| 63 | + port: httpServer.address().port, | ||
| 78 | 64 | rejectUnauthorized: false | |
| 79 | - }, cb).on('error', thrower).end(); | ||
| 65 | + }, cb).on('error', common.fail).end(); | ||
| 80 | 66 | ||
| 81 | 67 | http.request({ | |
| 82 | 68 | method: 'DELETE', | |
| 83 | 69 | path: '/' + (counter++), | |
| 84 | 70 | host: 'localhost', | |
| 85 | - //agent: false, | ||
| 86 | - port: this.address().port, | ||
| 71 | + port: httpServer.address().port, | ||
| 87 | 72 | rejectUnauthorized: false | |
| 88 | - }, cb).on('error', thrower).end(); | ||
| 73 | + }, cb).on('error', common.fail).end(); | ||
| 89 | 74 | }); | |
| 90 | 75 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments