@wiajs/request 3.0.0 → 3.0.1

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 (117) hide show
  1. package/.github/ISSUE_TEMPLATE.md +56 -0
  2. package/.github/PULL_REQUEST_TEMPLATE.md +13 -0
  3. package/.github/stale.yml +19 -0
  4. package/.swcrc +57 -0
  5. package/.travis.yml +21 -0
  6. package/CHANGELOG.md +717 -0
  7. package/CONTRIBUTING.md +81 -0
  8. package/biome.json +44 -0
  9. package/codecov.yml +2 -0
  10. package/disabled.appveyor.yml +36 -0
  11. package/dist/request.cjs +1476 -0
  12. package/dist/request.mjs +1474 -0
  13. package/examples/README.md +135 -0
  14. package/gulpfile.js +71 -0
  15. package/package.json +1 -2
  16. package/release.sh +45 -0
  17. package/tests/browser/karma.conf.js +57 -0
  18. package/tests/browser/ssl/ca.crt +14 -0
  19. package/tests/browser/ssl/server.crt +14 -0
  20. package/tests/browser/ssl/server.key +15 -0
  21. package/tests/browser/start.js +37 -0
  22. package/tests/browser/test.js +34 -0
  23. package/tests/fixtures/har.json +158 -0
  24. package/tests/googledoodle.jpg +0 -0
  25. package/tests/server.js +142 -0
  26. package/tests/squid.conf +76 -0
  27. package/tests/ssl/ca/README.md +8 -0
  28. package/tests/ssl/ca/ca.cnf +20 -0
  29. package/tests/ssl/ca/ca.crl +0 -0
  30. package/tests/ssl/ca/ca.crt +17 -0
  31. package/tests/ssl/ca/ca.csr +13 -0
  32. package/tests/ssl/ca/ca.key +18 -0
  33. package/tests/ssl/ca/ca.srl +1 -0
  34. package/tests/ssl/ca/client-enc.key +30 -0
  35. package/tests/ssl/ca/client.cnf +20 -0
  36. package/tests/ssl/ca/client.crt +20 -0
  37. package/tests/ssl/ca/client.csr +18 -0
  38. package/tests/ssl/ca/client.key +27 -0
  39. package/tests/ssl/ca/gen-all-certs.sh +6 -0
  40. package/tests/ssl/ca/gen-client.sh +25 -0
  41. package/tests/ssl/ca/gen-localhost.sh +22 -0
  42. package/tests/ssl/ca/gen-server.sh +18 -0
  43. package/tests/ssl/ca/localhost.cnf +20 -0
  44. package/tests/ssl/ca/localhost.crt +20 -0
  45. package/tests/ssl/ca/localhost.csr +18 -0
  46. package/tests/ssl/ca/localhost.js +33 -0
  47. package/tests/ssl/ca/localhost.key +27 -0
  48. package/tests/ssl/ca/server.cnf +19 -0
  49. package/tests/ssl/ca/server.crt +25 -0
  50. package/tests/ssl/ca/server.csr +29 -0
  51. package/tests/ssl/ca/server.js +34 -0
  52. package/tests/ssl/ca/server.key +51 -0
  53. package/tests/ssl/npm-ca.crt +16 -0
  54. package/tests/ssl/test.crt +15 -0
  55. package/tests/ssl/test.key +15 -0
  56. package/tests/test-agent.js +102 -0
  57. package/tests/test-agentOptions.js +51 -0
  58. package/tests/test-api.js +33 -0
  59. package/tests/test-aws.js +123 -0
  60. package/tests/test-baseUrl.js +133 -0
  61. package/tests/test-basic-auth.js +221 -0
  62. package/tests/test-bearer-auth.js +187 -0
  63. package/tests/test-body.js +154 -0
  64. package/tests/test-cookies.js +130 -0
  65. package/tests/test-defaults.js +340 -0
  66. package/tests/test-digest-auth.js +232 -0
  67. package/tests/test-emptyBody.js +56 -0
  68. package/tests/test-errors.js +108 -0
  69. package/tests/test-event-forwarding.js +39 -0
  70. package/tests/test-follow-all-303.js +45 -0
  71. package/tests/test-follow-all.js +57 -0
  72. package/tests/test-form-data-error.js +85 -0
  73. package/tests/test-form-data.js +133 -0
  74. package/tests/test-form-urlencoded.js +73 -0
  75. package/tests/test-form.js +101 -0
  76. package/tests/test-gzip.js +296 -0
  77. package/tests/test-har.js +175 -0
  78. package/tests/test-hawk.js +187 -0
  79. package/tests/test-headers.js +305 -0
  80. package/tests/test-http-signature.js +110 -0
  81. package/tests/test-httpModule.js +112 -0
  82. package/tests/test-https.js +116 -0
  83. package/tests/test-isUrl.js +120 -0
  84. package/tests/test-json-request.js +117 -0
  85. package/tests/test-localAddress.js +49 -0
  86. package/tests/test-multipart-encoding.js +147 -0
  87. package/tests/test-multipart.js +129 -0
  88. package/tests/test-node-debug.js +95 -0
  89. package/tests/test-oauth.js +721 -0
  90. package/tests/test-onelineproxy.js +61 -0
  91. package/tests/test-option-reuse.js +54 -0
  92. package/tests/test-options-convenience-method.js +52 -0
  93. package/tests/test-params.js +101 -0
  94. package/tests/test-piped-redirect.js +55 -0
  95. package/tests/test-pipes.js +383 -0
  96. package/tests/test-pool.js +148 -0
  97. package/tests/test-promise.js +53 -0
  98. package/tests/test-proxy-connect.js +80 -0
  99. package/tests/test-proxy.js +304 -0
  100. package/tests/test-qs.js +135 -0
  101. package/tests/test-redirect-auth.js +131 -0
  102. package/tests/test-redirect-complex.js +93 -0
  103. package/tests/test-redirect.js +449 -0
  104. package/tests/test-rfc3986.js +106 -0
  105. package/tests/test-stream.js +36 -0
  106. package/tests/test-timeout.js +260 -0
  107. package/tests/test-timing.js +147 -0
  108. package/tests/test-toJSON.js +45 -0
  109. package/tests/test-tunnel.js +466 -0
  110. package/tests/test-unix.js +74 -0
  111. package/tests/unicycle.jpg +0 -0
  112. package/request.js +0 -1553
  113. package/src/ZlibTransform.js +0 -27
  114. package/src/caseless.js +0 -118
  115. package/src/index.js +0 -122
  116. package/src/request.js +0 -967
  117. package/src/utils.js +0 -274
@@ -0,0 +1,135 @@
1
+
2
+ # Authentication
3
+
4
+ ## OAuth
5
+
6
+ ### OAuth1.0 Refresh Token
7
+
8
+ - http://oauth.googlecode.com/svn/spec/ext/session/1.0/drafts/1/spec.html#anchor4
9
+ - https://developer.yahoo.com/oauth/guide/oauth-refreshaccesstoken.html
10
+
11
+ ```js
12
+ request.post('https://api.login.yahoo.com/oauth/v2/get_token', {
13
+ oauth: {
14
+ consumer_key: '...',
15
+ consumer_secret: '...',
16
+ token: '...',
17
+ token_secret: '...',
18
+ session_handle: '...'
19
+ }
20
+ }, function (err, res, body) {
21
+ var result = require('querystring').parse(body)
22
+ // assert.equal(typeof result, 'object')
23
+ })
24
+ ```
25
+
26
+ ### OAuth2 Refresh Token
27
+
28
+ - https://tools.ietf.org/html/draft-ietf-oauth-v2-31#section-6
29
+
30
+ ```js
31
+ request.post('https://accounts.google.com/o/oauth2/token', {
32
+ form: {
33
+ grant_type: 'refresh_token',
34
+ client_id: '...',
35
+ client_secret: '...',
36
+ refresh_token: '...'
37
+ },
38
+ json: true
39
+ }, function (err, res, body) {
40
+ // assert.equal(typeof body, 'object')
41
+ })
42
+ ```
43
+
44
+ # Multipart
45
+
46
+ ## multipart/form-data
47
+
48
+ ### Flickr Image Upload
49
+
50
+ - https://www.flickr.com/services/api/upload.api.html
51
+
52
+ ```js
53
+ request.post('https://up.flickr.com/services/upload', {
54
+ oauth: {
55
+ consumer_key: '...',
56
+ consumer_secret: '...',
57
+ token: '...',
58
+ token_secret: '...'
59
+ },
60
+ // all meta data should be included here for proper signing
61
+ qs: {
62
+ title: 'My cat is awesome',
63
+ description: 'Sent on ' + new Date(),
64
+ is_public: 1
65
+ },
66
+ // again the same meta data + the actual photo
67
+ formData: {
68
+ title: 'My cat is awesome',
69
+ description: 'Sent on ' + new Date(),
70
+ is_public: 1,
71
+ photo:fs.createReadStream('cat.png')
72
+ },
73
+ json: true
74
+ }, function (err, res, body) {
75
+ // assert.equal(typeof body, 'object')
76
+ })
77
+ ```
78
+
79
+ # Streams
80
+
81
+ ## `POST` data
82
+
83
+ Use Request as a Writable stream to easily `POST` Readable streams (like files, other HTTP requests, or otherwise).
84
+
85
+ TL;DR: Pipe a Readable Stream onto Request via:
86
+
87
+ ```
88
+ READABLE.pipe(request.post(URL));
89
+ ```
90
+
91
+ A more detailed example:
92
+
93
+ ```js
94
+ var fs = require('fs')
95
+ , path = require('path')
96
+ , http = require('http')
97
+ , request = require('request')
98
+ , TMP_FILE_PATH = path.join(path.sep, 'tmp', 'foo')
99
+ ;
100
+
101
+ // write a temporary file:
102
+ fs.writeFileSync(TMP_FILE_PATH, 'foo bar baz quk\n');
103
+
104
+ http.createServer(function(req, res) {
105
+ console.log('the server is receiving data!\n');
106
+ req
107
+ .on('end', res.end.bind(res))
108
+ .pipe(process.stdout)
109
+ ;
110
+ }).listen(3000).unref();
111
+
112
+ fs.createReadStream(TMP_FILE_PATH)
113
+ .pipe(request.post('http://127.0.0.1:3000'))
114
+ ;
115
+ ```
116
+
117
+ # Proxys
118
+
119
+ Run tor on the terminal and try the following. (Needs `socks5-http-client` to connect to tor)
120
+
121
+ ```js
122
+ var request = require('../index.js');
123
+ var Agent = require('socks5-http-client/lib/Agent');
124
+
125
+ request.get({
126
+ url: 'http://www.tenreads.io',
127
+ agentClass: Agent,
128
+ agentOptions: {
129
+ socksHost: 'localhost', // Defaults to 'localhost'.
130
+ socksPort: 9050 // Defaults to 1080.
131
+ }
132
+ }, function (err, res) {
133
+ console.log(res.body);
134
+ });
135
+ ```
package/gulpfile.js ADDED
@@ -0,0 +1,71 @@
1
+ /* eslint-disable import/no-extraneous-dependencies */
2
+ import gulp from 'gulp'
3
+ import fs from 'fs-extra'
4
+ import {build} from './script/build.js'
5
+ import configs from './script/config.js'
6
+
7
+ const nodeEnv = process.env.NODE_ENV || 'development'
8
+ const src = './src'
9
+ const out = './dist'
10
+
11
+ console.log(`env:${nodeEnv} src:${src} out:${out}`)
12
+
13
+ if (!fs.existsSync(out)) {
14
+ fs.mkdirSync(out)
15
+ }
16
+
17
+ /**
18
+ * 删除已有发布文件,全部重新生成
19
+ * @returns
20
+ */
21
+ async function clean(cb) {
22
+ // const toRemove = ['*.map'].map(cmd => `rm -rf ${cmd}`);
23
+ // await exec.promise(`cd dist && ${toRemove.join(' && ')}`);
24
+ await fs.emptyDir('./dist/')
25
+ cb && cb()
26
+ }
27
+
28
+ /**
29
+ * 同时生成umd、cjs、esm 三种格式输出文件
30
+ */
31
+ const buildAll = gulp.series(clean, cb => {
32
+ console.log('start build ...')
33
+ build(configs, cb)
34
+ })
35
+
36
+ /**
37
+ * 仅生成cjs 格式
38
+ */
39
+ gulp.task('cjs', cb => {
40
+ console.log('dev cjs...')
41
+ // filter configs
42
+ const cfg = configs.filter(c => c.output.format === 'cjs')
43
+ build(cfg, cb)
44
+ })
45
+
46
+ /**
47
+ * 仅生成 esm 格式
48
+ */
49
+ gulp.task('esm', cb => {
50
+ console.log('dev esm...')
51
+ // filter configs
52
+ const cfg = configs.filter(c => c.output.format === 'esm')
53
+ build(cfg, cb)
54
+ })
55
+
56
+ /**
57
+ * 仅生成 umd 格式
58
+ */
59
+ gulp.task('umd', cb => {
60
+ console.log('dev umd...')
61
+ // filter configs
62
+ const cfg = configs.filter(c => c.output.format === 'umd')
63
+ build(cfg, cb)
64
+ })
65
+
66
+ gulp.task('watch', () => {
67
+ gulp.watch(`${src}/*.js`, gulp.series([buildAll]))
68
+ })
69
+
70
+ export default buildAll
71
+ export {buildAll as build}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@wiajs/request",
3
3
  "description": "Stream HTTP request client.",
4
4
  "keywords": ["http", "simple", "util", "utility"],
5
- "version": "3.0.0",
5
+ "version": "3.0.1",
6
6
  "type": "module",
7
7
  "main": "index.js",
8
8
  "exports": {
@@ -31,7 +31,6 @@
31
31
  "test-browser": "node tests/browser/start.js",
32
32
  "lint": "standard"
33
33
  },
34
- "files": ["src/", "lib/", "index.js", "request.js"],
35
34
  "author": "Sibyl Yu <sibyl@wia.pub>",
36
35
  "contributors": ["Mikeal Rogers <mikeal.rogers@gmail.com>"],
37
36
  "repository": {
package/release.sh ADDED
@@ -0,0 +1,45 @@
1
+ #!/bin/sh
2
+
3
+ if [ -z "`which github-changes`" ]; then
4
+ # specify version because github-changes "is under heavy development. Things
5
+ # may break between releases" until 0.1.0
6
+ echo "First, do: [sudo] npm install -g github-changes@0.0.14"
7
+ exit 1
8
+ fi
9
+
10
+ if [ -d .git/refs/remotes/upstream ]; then
11
+ remote=upstream
12
+ else
13
+ remote=origin
14
+ fi
15
+
16
+ # Increment v2.x.y -> v2.x+1.0
17
+ npm version minor || exit 1
18
+
19
+ # Generate changelog from pull requests
20
+ github-changes -o request -r request \
21
+ --auth --verbose \
22
+ --file CHANGELOG.md \
23
+ --only-pulls --use-commit-body \
24
+ --date-format '(YYYY/MM/DD)' \
25
+ || exit 1
26
+
27
+ # Since the tag for the new version hasn't been pushed yet, any changes in it
28
+ # will be marked as "upcoming"
29
+ version="$(grep '"version"' package.json | cut -d'"' -f4)"
30
+ sed -i -e "s/^### upcoming/### v$version/" CHANGELOG.md
31
+
32
+ # This may fail if no changelog updates
33
+ # TODO: would this ever actually happen? handle it better?
34
+ git add CHANGELOG.md; git commit -m 'Update changelog'
35
+
36
+ # Publish the new version to npm
37
+ npm publish || exit 1
38
+
39
+ # Increment v2.x.0 -> v2.x.1
40
+ # For rationale, see:
41
+ # https://github.com/request/oauth-sign/issues/10#issuecomment-58917018
42
+ npm version patch || exit 1
43
+
44
+ # Push back to the main repo
45
+ git push $remote master --tags || exit 1
@@ -0,0 +1,57 @@
1
+ 'use strict'
2
+ var istanbul = require('browserify-istanbul')
3
+
4
+ module.exports = function (config) {
5
+ config.set({
6
+ client: { requestTestUrl: process.argv[4] },
7
+ basePath: '../..',
8
+ frameworks: ['tap', 'browserify'],
9
+ preprocessors: {
10
+ 'tests/browser/test.js': ['browserify'],
11
+ '*.js,!(tests)/**/*.js': ['coverage']
12
+ },
13
+ files: [
14
+ 'tests/browser/test.js'
15
+ ],
16
+ port: 9876,
17
+
18
+ reporters: ['dots', 'coverage'],
19
+
20
+ colors: true,
21
+
22
+ logLevel: config.LOG_ERROR,
23
+
24
+ autoWatch: false,
25
+
26
+ browsers: ['PhantomJS_without_security'],
27
+
28
+ singleRun: true,
29
+
30
+ plugins: [
31
+ 'karma-phantomjs-launcher',
32
+ 'karma-coverage',
33
+ 'karma-browserify',
34
+ 'karma-tap'
35
+ ],
36
+ browserify: {
37
+ debug: true,
38
+ transform: [istanbul({
39
+ ignore: ['**/node_modules/**', '**/tests/**']
40
+ })]
41
+ },
42
+ coverageReporter: {
43
+ type: 'lcov',
44
+ dir: 'coverage/'
45
+ },
46
+
47
+ // Custom launcher to allowe self signed certs.
48
+ customLaunchers: {
49
+ PhantomJS_without_security: {
50
+ base: 'PhantomJS',
51
+ flags: [
52
+ '--ignore-ssl-errors=true'
53
+ ]
54
+ }
55
+ }
56
+ })
57
+ }
@@ -0,0 +1,14 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIICKTCCAZICCQDB/6lRlsirjzANBgkqhkiG9w0BAQUFADBZMQswCQYDVQQGEwJB
3
+ VTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0
4
+ cyBQdHkgTHRkMRIwEAYDVQQDEwlsb2NhbGhvc3QwHhcNMTUwMTA3MTcwODM2WhcN
5
+ MjUwMTA0MTcwODM2WjBZMQswCQYDVQQGEwJBVTETMBEGA1UECBMKU29tZS1TdGF0
6
+ ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMRIwEAYDVQQDEwls
7
+ b2NhbGhvc3QwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMba6FQ1VkgW8vWa
8
+ FBxV1VdLhQ5HP0eKZ/CyEGG4r89CzfzC0+V3bnFWGBGF2kSJlVjc7eVSSVio383A
9
+ inq3i+86Mavfy18BwcP4I0NqUSvvcV9yduBLUySklJhOlhhHeFUlycQyxuODbrG9
10
+ QOd411c4eccsbDHq5vSnS7AJh6tVAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAI0H3
11
+ bJIUQgnSGyrSHmjoKm66QLBPvQ1Zd7Zxjlg1uFv6glPOhdkeTQx9XQPT/WDG3qmJ
12
+ BdHvQLDtPS9P8vRaiQW1OCP7dQJkVYCxyFbSQiieuzwBAEGtZcLdZbvcp3PKRGbx
13
+ sIrkzyYdAXE1EZ5z7yLVcpWwTKnBnuRz2D0XOk4=
14
+ -----END CERTIFICATE-----
@@ -0,0 +1,14 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIICKTCCAZICCQDl9xx8ZXLMPTANBgkqhkiG9w0BAQUFADBZMQswCQYDVQQGEwJB
3
+ VTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0
4
+ cyBQdHkgTHRkMRIwEAYDVQQDEwlsb2NhbGhvc3QwHhcNMTUwMTA3MTcwOTQ4WhcN
5
+ MjUwMTA0MTcwOTQ4WjBZMQswCQYDVQQGEwJBVTETMBEGA1UECBMKU29tZS1TdGF0
6
+ ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMRIwEAYDVQQDEwls
7
+ b2NhbGhvc3QwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAKWxvvLNi8AcT0wI
8
+ sf+LoWAvtoIV29ypI6j1JRqmsPO433JP/ijLhJLFc6RKXpKs6pd4am82vzk8Bxs3
9
+ VtUXJ0yKh3KMevT7L4X1hw+QxvYAZD6Kl/kaNvKFTuAgcaeSnmnWGjQYLF/i20w7
10
+ 7dpeXDmnNMCKwdg+kLeJdPtW0d+vAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEADL6l
11
+ Z2mDKj4kPyGD58uBGeBHjmcDA2oJcnsHhOiC1u1NuCwQW4RDWs6Ili0GhuHYHP0B
12
+ JDcPw6ZSa1Gx3ZaUJ5yM/+YHpbLev34CjmiwQeG36DF2rAxfoIQk/wI4iWmu1+ed
13
+ 5Wwc0cZAb10uy0ihmMK98yhVQPmkBOEyw2O1xJw=
14
+ -----END CERTIFICATE-----
@@ -0,0 +1,15 @@
1
+ -----BEGIN RSA PRIVATE KEY-----
2
+ MIICXAIBAAKBgQClsb7yzYvAHE9MCLH/i6FgL7aCFdvcqSOo9SUaprDzuN9yT/4o
3
+ y4SSxXOkSl6SrOqXeGpvNr85PAcbN1bVFydMiodyjHr0+y+F9YcPkMb2AGQ+ipf5
4
+ GjbyhU7gIHGnkp5p1ho0GCxf4ttMO+3aXlw5pzTAisHYPpC3iXT7VtHfrwIDAQAB
5
+ AoGBAJa5edmk4NuA5SFlR4YOnl3BCWSMPdQciDPJzFbSC2WpZpm16p1xhMd+lhN9
6
+ E0qZwUzIXQmN46VM1aoMTRDKXxPqujUIvhn7kxMLmD8lajHzFUIhgnp1XQCfxIIV
7
+ sCcnIoP+cbnzP+AegAEPjds/0ngI3YM28UeooqZAmZCHQ0cBAkEAz0go7tCxXqED
8
+ +cY+P2axAKuGR+6srx08g5kONTpUx8jXr4su02F376dxhPB9UXWOJkYiGEBwKEds
9
+ OnUSNTF/RQJBAMyjUzjb/u6sZqTcHd3owes3UsCC+kfSb814qdG3Z9qYX9p55ESu
10
+ hA7Sbjq0WdTHGZdgEexwpfLtTRS8x5ldiGMCQFC3GLlmKqtep92rhLHLm0FXiYKZ
11
+ PkUybU4RW6b+f+UMIHELEcDeQ4Xe/iV2QFZoIGJnDP/El+gXZ92bmOt9ysECQD/i
12
+ zVx28gO5NuJJBdn9jGzOfLs1KMW7YMQY44thYr7Pyzz9yNHYWcn20Arruw++iLLF
13
+ f1L9aBGLHAFZXkb2+FkCQA5/3Z3SgiZrRYX/bWcNe6N65+nGfJv8ZBVsX13pKOxR
14
+ 8JzJLyEmx67IOGZvVgfVABrCHJvTrKlUO3x3mDoEPzI=
15
+ -----END RSA PRIVATE KEY-----
@@ -0,0 +1,37 @@
1
+ 'use strict'
2
+ var spawn = require('child_process').spawn
3
+ var https = require('https')
4
+ var fs = require('fs')
5
+ var path = require('path')
6
+
7
+ var server = https.createServer({
8
+ key: fs.readFileSync(path.join(__dirname, '/ssl/server.key')),
9
+ cert: fs.readFileSync(path.join(__dirname, '/ssl/server.crt')),
10
+ ca: fs.readFileSync(path.join(__dirname, '/ssl/ca.crt')),
11
+ requestCert: true,
12
+ rejectUnauthorized: false
13
+ }, function (req, res) {
14
+ // Set CORS header, since that is something we are testing.
15
+ res.setHeader('Access-Control-Allow-Origin', '*')
16
+ res.writeHead(200)
17
+ res.end('Can you hear the sound of an enormous door slamming in the depths of hell?\n')
18
+ })
19
+ server.listen(0, function () {
20
+ var port = this.address().port
21
+ console.log('Started https server for karma tests on port ' + port)
22
+ // Spawn process for karma.
23
+ var c = spawn('karma', [
24
+ 'start',
25
+ path.join(__dirname, '/karma.conf.js'),
26
+ 'https://localhost:' + port
27
+ ])
28
+ c.stdout.pipe(process.stdout)
29
+ c.stderr.pipe(process.stderr)
30
+ c.on('exit', function (c) {
31
+ // Exit process with karma exit code.
32
+ if (c !== 0) {
33
+ throw new Error('Karma exited with status code ' + c)
34
+ }
35
+ server.close()
36
+ })
37
+ })
@@ -0,0 +1,34 @@
1
+ 'use strict'
2
+
3
+ if (!Function.prototype.bind) {
4
+ // This is because of the fact that phantom.js does not have Function.bind.
5
+ // This is a bug in phantom.js.
6
+ // More info: https://github.com/ariya/phantomjs/issues/10522
7
+ /* eslint no-extend-native:0 */
8
+ Function.prototype.bind = require('function-bind')
9
+ }
10
+
11
+ var tape = require('tape')
12
+ var request = require('../../index')
13
+
14
+ tape('returns on error', function (t) {
15
+ t.plan(1)
16
+ request({
17
+ uri: 'https://stupid.nonexistent.path:port123/\\<-great-idea',
18
+ withCredentials: false
19
+ }, function (error, response) {
20
+ t.equal(typeof error, 'object')
21
+ t.end()
22
+ })
23
+ })
24
+
25
+ tape('succeeds on valid URLs (with https and CORS)', function (t) {
26
+ t.plan(1)
27
+ request({
28
+ uri: __karma__.config.requestTestUrl, // eslint-disable-line no-undef
29
+ withCredentials: false
30
+ }, function (_, response) {
31
+ t.equal(response.statusCode, 200)
32
+ t.end()
33
+ })
34
+ })
@@ -0,0 +1,158 @@
1
+ {
2
+ "application-form-encoded": {
3
+ "method": "POST",
4
+ "headers": [
5
+ {
6
+ "name": "content-type",
7
+ "value": "application/x-www-form-urlencoded"
8
+ }
9
+ ],
10
+ "postData": {
11
+ "mimeType": "application/x-www-form-urlencoded; charset=UTF-8",
12
+ "params": [
13
+ {
14
+ "name": "foo",
15
+ "value": "bar"
16
+ },
17
+ {
18
+ "name": "hello",
19
+ "value": "world"
20
+ }
21
+ ]
22
+ }
23
+ },
24
+
25
+ "application-json": {
26
+ "method": "POST",
27
+ "headers": [
28
+ {
29
+ "name": "content-type",
30
+ "value": "application/json"
31
+ }
32
+ ],
33
+ "postData": {
34
+ "mimeType": "application/json",
35
+ "text": "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}]}"
36
+ }
37
+ },
38
+
39
+ "cookies": {
40
+ "method": "POST",
41
+ "cookies": [
42
+ {
43
+ "name": "foo",
44
+ "value": "bar"
45
+ },
46
+ {
47
+ "name": "bar",
48
+ "value": "baz"
49
+ }
50
+ ]
51
+ },
52
+
53
+ "custom-method": {
54
+ "method": "PROPFIND"
55
+ },
56
+
57
+ "headers": {
58
+ "method": "GET",
59
+ "headers": [
60
+ {
61
+ "name": "x-foo",
62
+ "value": "Bar"
63
+ }
64
+ ]
65
+ },
66
+
67
+ "multipart-data": {
68
+ "method": "POST",
69
+ "headers": [
70
+ {
71
+ "name": "content-type",
72
+ "value": "multipart/form-data"
73
+ }
74
+ ],
75
+ "postData": {
76
+ "mimeType": "multipart/form-data",
77
+ "params": [
78
+ {
79
+ "name": "foo",
80
+ "value": "Hello World",
81
+ "fileName": "hello.txt",
82
+ "contentType": "text/plain"
83
+ }
84
+ ]
85
+ }
86
+ },
87
+
88
+ "multipart-file": {
89
+ "method": "POST",
90
+ "headers": [
91
+ {
92
+ "name": "content-type",
93
+ "value": "multipart/form-data"
94
+ }
95
+ ],
96
+ "postData": {
97
+ "mimeType": "multipart/form-data",
98
+ "params": [
99
+ {
100
+ "name": "foo",
101
+ "fileName": "../tests/unicycle.jpg",
102
+ "contentType": "image/jpeg"
103
+ }
104
+ ]
105
+ }
106
+ },
107
+
108
+ "multipart-form-data": {
109
+ "method": "POST",
110
+ "headers": [
111
+ {
112
+ "name": "content-type",
113
+ "value": "multipart/form-data"
114
+ }
115
+ ],
116
+ "postData": {
117
+ "mimeType": "multipart/form-data",
118
+ "params": [
119
+ {
120
+ "name": "foo",
121
+ "value": "bar"
122
+ }
123
+ ]
124
+ }
125
+ },
126
+
127
+ "query": {
128
+ "method": "GET",
129
+ "queryString": [
130
+ {
131
+ "name": "foo",
132
+ "value": "bar"
133
+ },
134
+ {
135
+ "name": "foo",
136
+ "value": "baz"
137
+ },
138
+ {
139
+ "name": "baz",
140
+ "value": "abc"
141
+ }
142
+ ]
143
+ },
144
+
145
+ "text-plain": {
146
+ "method": "POST",
147
+ "headers": [
148
+ {
149
+ "name": "content-type",
150
+ "value": "text/plain"
151
+ }
152
+ ],
153
+ "postData": {
154
+ "mimeType": "text/plain",
155
+ "text": "Hello World"
156
+ }
157
+ }
158
+ }
Binary file