@wiajs/request 3.0.1 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/package.json +2 -2
  2. package/.github/ISSUE_TEMPLATE.md +0 -56
  3. package/.github/PULL_REQUEST_TEMPLATE.md +0 -13
  4. package/.github/stale.yml +0 -19
  5. package/.swcrc +0 -57
  6. package/.travis.yml +0 -21
  7. package/CONTRIBUTING.md +0 -81
  8. package/biome.json +0 -44
  9. package/codecov.yml +0 -2
  10. package/disabled.appveyor.yml +0 -36
  11. package/examples/README.md +0 -135
  12. package/gulpfile.js +0 -71
  13. package/release.sh +0 -45
  14. package/tests/browser/karma.conf.js +0 -57
  15. package/tests/browser/ssl/ca.crt +0 -14
  16. package/tests/browser/ssl/server.crt +0 -14
  17. package/tests/browser/ssl/server.key +0 -15
  18. package/tests/browser/start.js +0 -37
  19. package/tests/browser/test.js +0 -34
  20. package/tests/fixtures/har.json +0 -158
  21. package/tests/googledoodle.jpg +0 -0
  22. package/tests/server.js +0 -142
  23. package/tests/squid.conf +0 -76
  24. package/tests/ssl/ca/README.md +0 -8
  25. package/tests/ssl/ca/ca.cnf +0 -20
  26. package/tests/ssl/ca/ca.crl +0 -0
  27. package/tests/ssl/ca/ca.crt +0 -17
  28. package/tests/ssl/ca/ca.csr +0 -13
  29. package/tests/ssl/ca/ca.key +0 -18
  30. package/tests/ssl/ca/ca.srl +0 -1
  31. package/tests/ssl/ca/client-enc.key +0 -30
  32. package/tests/ssl/ca/client.cnf +0 -20
  33. package/tests/ssl/ca/client.crt +0 -20
  34. package/tests/ssl/ca/client.csr +0 -18
  35. package/tests/ssl/ca/client.key +0 -27
  36. package/tests/ssl/ca/gen-all-certs.sh +0 -6
  37. package/tests/ssl/ca/gen-client.sh +0 -25
  38. package/tests/ssl/ca/gen-localhost.sh +0 -22
  39. package/tests/ssl/ca/gen-server.sh +0 -18
  40. package/tests/ssl/ca/localhost.cnf +0 -20
  41. package/tests/ssl/ca/localhost.crt +0 -20
  42. package/tests/ssl/ca/localhost.csr +0 -18
  43. package/tests/ssl/ca/localhost.js +0 -33
  44. package/tests/ssl/ca/localhost.key +0 -27
  45. package/tests/ssl/ca/server.cnf +0 -19
  46. package/tests/ssl/ca/server.crt +0 -25
  47. package/tests/ssl/ca/server.csr +0 -29
  48. package/tests/ssl/ca/server.js +0 -34
  49. package/tests/ssl/ca/server.key +0 -51
  50. package/tests/ssl/npm-ca.crt +0 -16
  51. package/tests/ssl/test.crt +0 -15
  52. package/tests/ssl/test.key +0 -15
  53. package/tests/test-agent.js +0 -102
  54. package/tests/test-agentOptions.js +0 -51
  55. package/tests/test-api.js +0 -33
  56. package/tests/test-aws.js +0 -123
  57. package/tests/test-baseUrl.js +0 -133
  58. package/tests/test-basic-auth.js +0 -221
  59. package/tests/test-bearer-auth.js +0 -187
  60. package/tests/test-body.js +0 -154
  61. package/tests/test-cookies.js +0 -130
  62. package/tests/test-defaults.js +0 -340
  63. package/tests/test-digest-auth.js +0 -232
  64. package/tests/test-emptyBody.js +0 -56
  65. package/tests/test-errors.js +0 -108
  66. package/tests/test-event-forwarding.js +0 -39
  67. package/tests/test-follow-all-303.js +0 -45
  68. package/tests/test-follow-all.js +0 -57
  69. package/tests/test-form-data-error.js +0 -85
  70. package/tests/test-form-data.js +0 -133
  71. package/tests/test-form-urlencoded.js +0 -73
  72. package/tests/test-form.js +0 -101
  73. package/tests/test-gzip.js +0 -296
  74. package/tests/test-har.js +0 -175
  75. package/tests/test-hawk.js +0 -187
  76. package/tests/test-headers.js +0 -305
  77. package/tests/test-http-signature.js +0 -110
  78. package/tests/test-httpModule.js +0 -112
  79. package/tests/test-https.js +0 -116
  80. package/tests/test-isUrl.js +0 -120
  81. package/tests/test-json-request.js +0 -117
  82. package/tests/test-localAddress.js +0 -49
  83. package/tests/test-multipart-encoding.js +0 -147
  84. package/tests/test-multipart.js +0 -129
  85. package/tests/test-node-debug.js +0 -95
  86. package/tests/test-oauth.js +0 -721
  87. package/tests/test-onelineproxy.js +0 -61
  88. package/tests/test-option-reuse.js +0 -54
  89. package/tests/test-options-convenience-method.js +0 -52
  90. package/tests/test-params.js +0 -101
  91. package/tests/test-piped-redirect.js +0 -55
  92. package/tests/test-pipes.js +0 -383
  93. package/tests/test-pool.js +0 -148
  94. package/tests/test-promise.js +0 -53
  95. package/tests/test-proxy-connect.js +0 -80
  96. package/tests/test-proxy.js +0 -304
  97. package/tests/test-qs.js +0 -135
  98. package/tests/test-redirect-auth.js +0 -131
  99. package/tests/test-redirect-complex.js +0 -93
  100. package/tests/test-redirect.js +0 -449
  101. package/tests/test-rfc3986.js +0 -106
  102. package/tests/test-stream.js +0 -36
  103. package/tests/test-timeout.js +0 -260
  104. package/tests/test-timing.js +0 -147
  105. package/tests/test-toJSON.js +0 -45
  106. package/tests/test-tunnel.js +0 -466
  107. package/tests/test-unix.js +0 -74
  108. package/tests/unicycle.jpg +0 -0
@@ -1,110 +0,0 @@
1
- 'use strict'
2
-
3
- var http = require('http')
4
- var request = require('../index')
5
- var httpSignature = require('http-signature')
6
- var tape = require('tape')
7
-
8
- var privateKeyPEMs = {}
9
-
10
- privateKeyPEMs['key-1'] =
11
- '-----BEGIN RSA PRIVATE KEY-----\n' +
12
- 'MIIEpAIBAAKCAQEAzWSJl+Z9Bqv00FVL5N3+JCUoqmQPjIlya1BbeqQroNQ5yG1i\n' +
13
- 'VbYTTnMRa1zQtR6r2fNvWeg94DvxivxIG9diDMnrzijAnYlTLOl84CK2vOxkj5b6\n' +
14
- '8zrLH9b/Gd6NOHsywo8IjvXvCeTfca5WUHcuVi2lT9VjygFs1ILG4RyeX1BXUumu\n' +
15
- 'Y8fzmposxLYdMxCqUTzAn0u9Saq2H2OVj5u114wS7OQPigu6G99dpn/iPHa3zBm8\n' +
16
- '7baBWDbqZWRW0BP3K6eqq8sut1+NLhNW8ADPTdnO/SO+kvXy7fqd8atSn+HlQcx6\n' +
17
- 'tW42dhXf3E9uE7K78eZtW0KvfyNGAjsI1Fft2QIDAQABAoIBAG1exe3/LEBrPLfb\n' +
18
- 'U8iRdY0lxFvHYIhDgIwohC3wUdMYb5SMurpNdEZn+7Sh/fkUVgp/GKJViu1mvh52\n' +
19
- 'bKd2r52DwG9NQBQjVgkqY/auRYSglIPpr8PpYNSZlcneunCDGeqEY9hMmXc5Ssqs\n' +
20
- 'PQYoEKKPN+IlDTg6PguDgAfLR4IUvt9KXVvmB/SSgV9tSeTy35LECt1Lq3ozbUgu\n' +
21
- '30HZI3U6/7H+X22Pxxf8vzBtzkg5rRCLgv+OeNPo16xMnqbutt4TeqEkxRv5rtOo\n' +
22
- '/A1i9khBeki0OJAFJsE82qnaSZodaRsxic59VnN8sWBwEKAt87tEu5A3K3j4XSDU\n' +
23
- '/avZxAECgYEA+pS3DvpiQLtHlaO3nAH6MxHRrREOARXWRDe5nUQuUNpS1xq9wte6\n' +
24
- 'DkFtba0UCvDLic08xvReTCbo9kH0y6zEy3zMpZuJlKbcWCkZf4S5miYPI0RTZtF8\n' +
25
- 'yps6hWqzYFSiO9hMYws9k4OJLxX0x3sLK7iNZ32ujcSrkPBSiBr0gxkCgYEA0dWl\n' +
26
- '637K41AJ/zy0FP0syq+r4eIkfqv+/t6y2aQVUBvxJYrj9ci6XHBqoxpDV8lufVYj\n' +
27
- 'fUAfeI9/MZaWvQJRbnYLre0I6PJfLuCBIL5eflO77BGso165AF7QJZ+fwtgKv3zv\n' +
28
- 'ZX75eudCSS/cFo0po9hlbcLMT4B82zEkgT8E2MECgYEAnz+3/wrdOmpLGiyL2dff\n' +
29
- '3GjsqmJ2VfY8z+niSrI0BSpbD11tT9Ct67VlCBjA7hsOH6uRfpd6/kaUMzzDiFVq\n' +
30
- 'VDAiFvV8QD6zNkwYalQ9aFvbrvwTTPrBpjl0vamMCiJ/YC0cjq1sGr2zh3sar1Ph\n' +
31
- 'S43kP+s97dcZeelhaiJHVrECgYEAsx61q/loJ/LDFeYzs1cLTVn4V7I7hQY9fkOM\n' +
32
- 'WM0AhInVqD6PqdfXfeFYpjJdGisQ7l0BnoGGW9vir+nkcyPvb2PFRIr6+B8tsU5j\n' +
33
- '7BeVgjDoUfQkcrEBK5fEBtnj/ud9BUkY8oMZZBjVNLRuI7IMwZiPvMp0rcj4zAN/\n' +
34
- 'LfUlpgECgYArBvFcBxSkNAzR3Rtteud1YDboSKluRM37Ey5plrn4BS0DD0jm++aD\n' +
35
- '0pG2Hsik000hibw92lCkzvvBVAqF8BuAcnPlAeYfsOaa97PGEjSKEN5bJVWZ9/om\n' +
36
- '9FV1axotRN2XWlwrhixZLEaagkREXhgQc540FS5O8IaI2Vpa80Atzg==\n' +
37
- '-----END RSA PRIVATE KEY-----'
38
-
39
- var publicKeyPEMs = {}
40
-
41
- publicKeyPEMs['key-1'] =
42
- '-----BEGIN PUBLIC KEY-----\n' +
43
- 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzWSJl+Z9Bqv00FVL5N3+\n' +
44
- 'JCUoqmQPjIlya1BbeqQroNQ5yG1iVbYTTnMRa1zQtR6r2fNvWeg94DvxivxIG9di\n' +
45
- 'DMnrzijAnYlTLOl84CK2vOxkj5b68zrLH9b/Gd6NOHsywo8IjvXvCeTfca5WUHcu\n' +
46
- 'Vi2lT9VjygFs1ILG4RyeX1BXUumuY8fzmposxLYdMxCqUTzAn0u9Saq2H2OVj5u1\n' +
47
- '14wS7OQPigu6G99dpn/iPHa3zBm87baBWDbqZWRW0BP3K6eqq8sut1+NLhNW8ADP\n' +
48
- 'TdnO/SO+kvXy7fqd8atSn+HlQcx6tW42dhXf3E9uE7K78eZtW0KvfyNGAjsI1Fft\n' +
49
- '2QIDAQAB\n' +
50
- '-----END PUBLIC KEY-----'
51
-
52
- publicKeyPEMs['key-2'] =
53
- '-----BEGIN PUBLIC KEY-----\n' +
54
- 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqp04VVr9OThli9b35Omz\n' +
55
- 'VqSfWbsoQuRrgyWsrNRn3XkFmbWw4FzZwQ42OgGMzQ84Ta4d9zGKKQyFriTiPjPf\n' +
56
- 'xhhrsaJnDuybcpVhcr7UNKjSZ0S59tU3hpRiEz6hO+Nc/OSSLkvalG0VKrxOln7J\n' +
57
- 'LK/h3rNS/l6wDZ5S/KqsI6CYtV2ZLpn3ahLrizvEYNY038Qcm38qMWx+VJAvZ4di\n' +
58
- 'qqmW7RLIsLT59SWmpXdhFKnkYYGhxrk1Mwl22dBTJNY5SbriU5G3gWgzYkm8pgHr\n' +
59
- '6CtrXch9ciJAcDJehPrKXNvNDOdUh8EW3fekNJerF1lWcwQg44/12v8sDPyfbaKB\n' +
60
- 'dQIDAQAB\n' +
61
- '-----END PUBLIC KEY-----'
62
-
63
- var server = http.createServer(function (req, res) {
64
- var parsed = httpSignature.parseRequest(req)
65
- var publicKeyPEM = publicKeyPEMs[parsed.keyId]
66
- var verified = httpSignature.verifySignature(parsed, publicKeyPEM)
67
- res.writeHead(verified ? 200 : 400)
68
- res.end()
69
- })
70
-
71
- tape('setup', function (t) {
72
- server.listen(0, function () {
73
- server.url = 'http://localhost:' + this.address().port
74
- t.end()
75
- })
76
- })
77
-
78
- tape('correct key', function (t) {
79
- var options = {
80
- httpSignature: {
81
- keyId: 'key-1',
82
- key: privateKeyPEMs['key-1']
83
- }
84
- }
85
- request(server.url, options, function (err, res, body) {
86
- t.equal(err, null)
87
- t.equal(200, res.statusCode)
88
- t.end()
89
- })
90
- })
91
-
92
- tape('incorrect key', function (t) {
93
- var options = {
94
- httpSignature: {
95
- keyId: 'key-2',
96
- key: privateKeyPEMs['key-1']
97
- }
98
- }
99
- request(server.url, options, function (err, res, body) {
100
- t.equal(err, null)
101
- t.equal(400, res.statusCode)
102
- t.end()
103
- })
104
- })
105
-
106
- tape('cleanup', function (t) {
107
- server.close(function () {
108
- t.end()
109
- })
110
- })
@@ -1,112 +0,0 @@
1
- 'use strict'
2
-
3
- var http = require('http')
4
- var https = require('https')
5
- var destroyable = require('server-destroy')
6
- var server = require('./server')
7
- var request = require('../index')
8
- var tape = require('tape')
9
-
10
- var fauxRequestsMade
11
-
12
- function clearFauxRequests () {
13
- fauxRequestsMade = { http: 0, https: 0 }
14
- }
15
-
16
- function wrapRequest (name, module) {
17
- // Just like the http or https module, but note when a request is made.
18
- var wrapped = {}
19
- Object.keys(module).forEach(function (key) {
20
- var value = module[key]
21
-
22
- if (key === 'request') {
23
- wrapped[key] = function (/* options, callback */) {
24
- fauxRequestsMade[name] += 1
25
- return value.apply(this, arguments)
26
- }
27
- } else {
28
- wrapped[key] = value
29
- }
30
- })
31
-
32
- return wrapped
33
- }
34
-
35
- var fauxHTTP = wrapRequest('http', http)
36
- var fauxHTTPS = wrapRequest('https', https)
37
- var plainServer = server.createServer()
38
- var httpsServer = server.createSSLServer()
39
-
40
- destroyable(plainServer)
41
- destroyable(httpsServer)
42
-
43
- tape('setup', function (t) {
44
- plainServer.listen(0, function () {
45
- plainServer.on('/plain', function (req, res) {
46
- res.writeHead(200)
47
- res.end('plain')
48
- })
49
- plainServer.on('/to_https', function (req, res) {
50
- res.writeHead(301, { 'location': 'https://localhost:' + httpsServer.port + '/https' })
51
- res.end()
52
- })
53
-
54
- httpsServer.listen(0, function () {
55
- httpsServer.on('/https', function (req, res) {
56
- res.writeHead(200)
57
- res.end('https')
58
- })
59
- httpsServer.on('/to_plain', function (req, res) {
60
- res.writeHead(302, { 'location': 'http://localhost:' + plainServer.port + '/plain' })
61
- res.end()
62
- })
63
-
64
- t.end()
65
- })
66
- })
67
- })
68
-
69
- function runTests (name, httpModules) {
70
- tape(name, function (t) {
71
- var toHttps = 'http://localhost:' + plainServer.port + '/to_https'
72
- var toPlain = 'https://localhost:' + httpsServer.port + '/to_plain'
73
- var options = { httpModules: httpModules, strictSSL: false }
74
- var modulesTest = httpModules || {}
75
-
76
- clearFauxRequests()
77
-
78
- request(toHttps, options, function (err, res, body) {
79
- t.equal(err, null)
80
- t.equal(res.statusCode, 200)
81
- t.equal(body, 'https', 'Received HTTPS server body')
82
-
83
- t.equal(fauxRequestsMade.http, modulesTest['http:'] ? 1 : 0)
84
- t.equal(fauxRequestsMade.https, modulesTest['https:'] ? 1 : 0)
85
-
86
- request(toPlain, options, function (err, res, body) {
87
- t.equal(err, null)
88
- t.equal(res.statusCode, 200)
89
- t.equal(body, 'plain', 'Received HTTPS server body')
90
-
91
- t.equal(fauxRequestsMade.http, modulesTest['http:'] ? 2 : 0)
92
- t.equal(fauxRequestsMade.https, modulesTest['https:'] ? 2 : 0)
93
-
94
- t.end()
95
- })
96
- })
97
- })
98
- }
99
-
100
- runTests('undefined')
101
- runTests('empty', {})
102
- runTests('http only', { 'http:': fauxHTTP })
103
- runTests('https only', { 'https:': fauxHTTPS })
104
- runTests('http and https', { 'http:': fauxHTTP, 'https:': fauxHTTPS })
105
-
106
- tape('cleanup', function (t) {
107
- plainServer.destroy(function () {
108
- httpsServer.destroy(function () {
109
- t.end()
110
- })
111
- })
112
- })
@@ -1,116 +0,0 @@
1
- 'use strict'
2
-
3
- // a test where we validate the siguature of the keys
4
- // otherwise exactly the same as the ssl test
5
-
6
- var server = require('./server')
7
- var request = require('../index')
8
- var fs = require('fs')
9
- var path = require('path')
10
- var tape = require('tape')
11
-
12
- var s = server.createSSLServer()
13
- var caFile = path.resolve(__dirname, 'ssl/ca/ca.crt')
14
- var ca = fs.readFileSync(caFile)
15
- var opts = {
16
- ciphers: 'AES256-SHA',
17
- key: path.resolve(__dirname, 'ssl/ca/server.key'),
18
- cert: path.resolve(__dirname, 'ssl/ca/server.crt')
19
- }
20
- var sStrict = server.createSSLServer(opts)
21
-
22
- function runAllTests (strict, s) {
23
- var strictMsg = (strict ? 'strict ' : 'relaxed ')
24
-
25
- tape(strictMsg + 'setup', function (t) {
26
- s.listen(0, function () {
27
- t.end()
28
- })
29
- })
30
-
31
- function runTest (name, test) {
32
- tape(strictMsg + name, function (t) {
33
- s.on('/' + name, test.resp)
34
- test.uri = s.url + '/' + name
35
- if (strict) {
36
- test.strictSSL = true
37
- test.ca = ca
38
- test.headers = { host: 'testing.request.mikealrogers.com' }
39
- } else {
40
- test.rejectUnauthorized = false
41
- }
42
- request(test, function (err, resp, body) {
43
- t.equal(err, null)
44
- if (test.expectBody) {
45
- t.deepEqual(test.expectBody, body)
46
- }
47
- t.end()
48
- })
49
- })
50
- }
51
-
52
- runTest('testGet', {
53
- resp: server.createGetResponse('TESTING!'), expectBody: 'TESTING!'
54
- })
55
-
56
- runTest('testGetChunkBreak', {
57
- resp: server.createChunkResponse(
58
- [ Buffer.from([239]),
59
- Buffer.from([163]),
60
- Buffer.from([191]),
61
- Buffer.from([206]),
62
- Buffer.from([169]),
63
- Buffer.from([226]),
64
- Buffer.from([152]),
65
- Buffer.from([131])
66
- ]),
67
- expectBody: '\uf8ff\u03a9\u2603'
68
- })
69
-
70
- runTest('testGetJSON', {
71
- resp: server.createGetResponse('{"test":true}', 'application/json'), json: true, expectBody: {'test': true}
72
- })
73
-
74
- runTest('testPutString', {
75
- resp: server.createPostValidator('PUTTINGDATA'), method: 'PUT', body: 'PUTTINGDATA'
76
- })
77
-
78
- runTest('testPutBuffer', {
79
- resp: server.createPostValidator('PUTTINGDATA'), method: 'PUT', body: Buffer.from('PUTTINGDATA')
80
- })
81
-
82
- runTest('testPutJSON', {
83
- resp: server.createPostValidator(JSON.stringify({foo: 'bar'})), method: 'PUT', json: {foo: 'bar'}
84
- })
85
-
86
- runTest('testPutMultipart', {
87
- resp: server.createPostValidator(
88
- '--__BOUNDARY__\r\n' +
89
- 'content-type: text/html\r\n' +
90
- '\r\n' +
91
- '<html><body>Oh hi.</body></html>' +
92
- '\r\n--__BOUNDARY__\r\n\r\n' +
93
- 'Oh hi.' +
94
- '\r\n--__BOUNDARY__--'
95
- ),
96
- method: 'PUT',
97
- multipart: [ {'content-type': 'text/html', 'body': '<html><body>Oh hi.</body></html>'},
98
- {'body': 'Oh hi.'}
99
- ]
100
- })
101
-
102
- tape(strictMsg + 'cleanup', function (t) {
103
- s.close(function () {
104
- t.end()
105
- })
106
- })
107
- }
108
-
109
- runAllTests(false, s)
110
-
111
- if (!process.env.running_under_istanbul) {
112
- // somehow this test modifies the process state
113
- // test coverage runs all tests in a single process via tape
114
- // executing this test causes one of the tests in test-tunnel.js to throw
115
- runAllTests(true, sStrict)
116
- }
@@ -1,120 +0,0 @@
1
- 'use strict'
2
-
3
- var http = require('http')
4
- var request = require('../index')
5
- var tape = require('tape')
6
-
7
- var s = http.createServer(function (req, res) {
8
- res.statusCode = 200
9
- res.end('ok')
10
- })
11
-
12
- tape('setup', function (t) {
13
- s.listen(0, function () {
14
- s.port = this.address().port
15
- s.url = 'http://localhost:' + s.port
16
- t.end()
17
- })
18
- })
19
-
20
- tape('lowercase', function (t) {
21
- request(s.url, function (err, resp, body) {
22
- t.equal(err, null)
23
- t.equal(body, 'ok')
24
- t.end()
25
- })
26
- })
27
-
28
- tape('uppercase', function (t) {
29
- request(s.url.replace('http', 'HTTP'), function (err, resp, body) {
30
- t.equal(err, null)
31
- t.equal(body, 'ok')
32
- t.end()
33
- })
34
- })
35
-
36
- tape('mixedcase', function (t) {
37
- request(s.url.replace('http', 'HtTp'), function (err, resp, body) {
38
- t.equal(err, null)
39
- t.equal(body, 'ok')
40
- t.end()
41
- })
42
- })
43
-
44
- tape('hostname and port', function (t) {
45
- request({
46
- uri: {
47
- protocol: 'http:',
48
- hostname: 'localhost',
49
- port: s.port
50
- }
51
- }, function (err, res, body) {
52
- t.equal(err, null)
53
- t.equal(body, 'ok')
54
- t.end()
55
- })
56
- })
57
-
58
- tape('hostname and port 1', function (t) {
59
- request({
60
- uri: {
61
- protocol: 'http:',
62
- hostname: 'localhost',
63
- port: s.port
64
- }
65
- }, function (err, res, body) {
66
- t.equal(err, null)
67
- t.equal(body, 'ok')
68
- t.end()
69
- })
70
- })
71
-
72
- tape('hostname and port 2', function (t) {
73
- request({
74
- protocol: 'http:',
75
- hostname: 'localhost',
76
- port: s.port
77
- }, {
78
- // need this empty options object, otherwise request thinks no uri was set
79
- }, function (err, res, body) {
80
- t.equal(err, null)
81
- t.equal(body, 'ok')
82
- t.end()
83
- })
84
- })
85
-
86
- tape('hostname and port 3', function (t) {
87
- request({
88
- protocol: 'http:',
89
- hostname: 'localhost',
90
- port: s.port
91
- }, function (err, res, body) {
92
- t.notEqual(err, null)
93
- t.equal(err.message, 'options.uri is a required argument')
94
- t.equal(body, undefined)
95
- t.end()
96
- })
97
- })
98
-
99
- tape('hostname and query string', function (t) {
100
- request({
101
- uri: {
102
- protocol: 'http:',
103
- hostname: 'localhost',
104
- port: s.port
105
- },
106
- qs: {
107
- test: 'test'
108
- }
109
- }, function (err, res, body) {
110
- t.equal(err, null)
111
- t.equal(body, 'ok')
112
- t.end()
113
- })
114
- })
115
-
116
- tape('cleanup', function (t) {
117
- s.close(function () {
118
- t.end()
119
- })
120
- })
@@ -1,117 +0,0 @@
1
- 'use strict'
2
-
3
- var server = require('./server')
4
- var request = require('../index')
5
- var tape = require('tape')
6
-
7
- var s = server.createServer()
8
-
9
- tape('setup', function (t) {
10
- s.listen(0, function () {
11
- t.end()
12
- })
13
- })
14
-
15
- function testJSONValue (testId, value) {
16
- tape('test ' + testId, function (t) {
17
- var testUrl = '/' + testId
18
- s.on(testUrl, server.createPostJSONValidator(value, 'application/json'))
19
- var opts = {
20
- method: 'PUT',
21
- uri: s.url + testUrl,
22
- json: true,
23
- body: value
24
- }
25
- request(opts, function (err, resp, body) {
26
- t.equal(err, null)
27
- t.equal(resp.statusCode, 200)
28
- t.deepEqual(body, value)
29
- t.end()
30
- })
31
- })
32
- }
33
-
34
- function testJSONValueReviver (testId, value, reviver, revivedValue) {
35
- tape('test ' + testId, function (t) {
36
- var testUrl = '/' + testId
37
- s.on(testUrl, server.createPostJSONValidator(value, 'application/json'))
38
- var opts = {
39
- method: 'PUT',
40
- uri: s.url + testUrl,
41
- json: true,
42
- jsonReviver: reviver,
43
- body: value
44
- }
45
- request(opts, function (err, resp, body) {
46
- t.equal(err, null)
47
- t.equal(resp.statusCode, 200)
48
- t.deepEqual(body, revivedValue)
49
- t.end()
50
- })
51
- })
52
- }
53
-
54
- function testJSONValueReplacer (testId, value, replacer, replacedValue) {
55
- tape('test ' + testId, function (t) {
56
- var testUrl = '/' + testId
57
- s.on(testUrl, server.createPostJSONValidator(replacedValue, 'application/json'))
58
- var opts = {
59
- method: 'PUT',
60
- uri: s.url + testUrl,
61
- json: true,
62
- jsonReplacer: replacer,
63
- body: value
64
- }
65
- request(opts, function (err, resp, body) {
66
- t.equal(err, null)
67
- t.equal(resp.statusCode, 200)
68
- t.deepEqual(body, replacedValue)
69
- t.end()
70
- })
71
- })
72
- }
73
-
74
- testJSONValue('jsonNull', null)
75
- testJSONValue('jsonTrue', true)
76
- testJSONValue('jsonFalse', false)
77
- testJSONValue('jsonNumber', -289365.2938)
78
- testJSONValue('jsonString', 'some string')
79
- testJSONValue('jsonArray', ['value1', 2, null, 8925.53289, true, false, ['array'], { object: 'property' }])
80
- testJSONValue('jsonObject', {
81
- trueProperty: true,
82
- falseProperty: false,
83
- numberProperty: -98346.34698,
84
- stringProperty: 'string',
85
- nullProperty: null,
86
- arrayProperty: ['array'],
87
- objectProperty: { object: 'property' }
88
- })
89
-
90
- testJSONValueReviver('jsonReviver', -48269.592, function (k, v) {
91
- return v * -1
92
- }, 48269.592)
93
- testJSONValueReviver('jsonReviverInvalid', -48269.592, 'invalid reviver', -48269.592)
94
-
95
- testJSONValueReplacer('jsonReplacer', -48269.592, function (k, v) {
96
- return v * -1
97
- }, 48269.592)
98
- testJSONValueReplacer('jsonReplacerInvalid', -48269.592, 'invalid replacer', -48269.592)
99
- testJSONValueReplacer('jsonReplacerObject', {foo: 'bar'}, function (k, v) {
100
- return v.toUpperCase ? v.toUpperCase() : v
101
- }, {foo: 'BAR'})
102
-
103
- tape('missing body', function (t) {
104
- s.on('/missing-body', function (req, res) {
105
- t.equal(req.headers['content-type'], undefined)
106
- res.end()
107
- })
108
- request({url: s.url + '/missing-body', json: true}, function () {
109
- t.end()
110
- })
111
- })
112
-
113
- tape('cleanup', function (t) {
114
- s.close(function () {
115
- t.end()
116
- })
117
- })
@@ -1,49 +0,0 @@
1
- 'use strict'
2
- var request = require('../index')
3
- var tape = require('tape')
4
-
5
- tape('bind to invalid address', function (t) {
6
- request.get({
7
- uri: 'http://www.google.com',
8
- localAddress: '1.2.3.4'
9
- }, function (err, res) {
10
- t.notEqual(err, null)
11
- t.equal(true, /bind EADDRNOTAVAIL/.test(err.message))
12
- t.equal(res, undefined)
13
- t.end()
14
- })
15
- })
16
-
17
- tape('bind to local address', function (t) {
18
- request.get({
19
- uri: 'http://www.google.com',
20
- localAddress: '127.0.0.1'
21
- }, function (err, res) {
22
- t.notEqual(err, null)
23
- t.equal(res, undefined)
24
- t.end()
25
- })
26
- })
27
-
28
- tape('bind to local address on redirect', function (t) {
29
- var os = require('os')
30
- var localInterfaces = os.networkInterfaces()
31
- var localIPS = []
32
- Object.keys(localInterfaces).forEach(function (ifname) {
33
- localInterfaces[ifname].forEach(function (iface) {
34
- if (iface.family !== 'IPv4' || iface.internal !== false) {
35
- // skip over internal (i.e. 127.0.0.1) and non-ipv4 addresses
36
- return
37
- }
38
- localIPS.push(iface.address)
39
- })
40
- })
41
- request.get({
42
- uri: 'http://google.com', // redirects to 'http://google.com'
43
- localAddress: localIPS[0]
44
- }, function (err, res) {
45
- t.equal(err, null)
46
- t.equal(res.request.localAddress, localIPS[0])
47
- t.end()
48
- })
49
- })