diff options
| author | 8cy <[email protected]> | 2020-04-03 02:48:28 -0700 |
|---|---|---|
| committer | 8cy <[email protected]> | 2020-04-03 02:48:28 -0700 |
| commit | f9159ea2d994e14180fb02ab562f0119513e67cf (patch) | |
| tree | 09d14cdf05456567156738b681379d4bccd64e5c /node_modules/sync-request | |
| parent | 2020/04/03, 02:42, V1.2.1 (diff) | |
| download | s5nical-f9159ea2d994e14180fb02ab562f0119513e67cf.tar.xz s5nical-f9159ea2d994e14180fb02ab562f0119513e67cf.zip | |
2020/04/03, 02:47, V1.2.2
Diffstat (limited to 'node_modules/sync-request')
| -rw-r--r-- | node_modules/sync-request/.npmignore | 13 | ||||
| -rw-r--r-- | node_modules/sync-request/.travis.yml | 5 | ||||
| -rw-r--r-- | node_modules/sync-request/LICENSE | 19 | ||||
| -rw-r--r-- | node_modules/sync-request/README.md | 114 | ||||
| -rw-r--r-- | node_modules/sync-request/browser.js | 64 | ||||
| -rw-r--r-- | node_modules/sync-request/index.js | 33 | ||||
| -rw-r--r-- | node_modules/sync-request/lib/json-buffer/LICENSE | 22 | ||||
| -rw-r--r-- | node_modules/sync-request/lib/json-buffer/README.md | 1 | ||||
| -rw-r--r-- | node_modules/sync-request/lib/json-buffer/index.js | 55 | ||||
| -rw-r--r-- | node_modules/sync-request/lib/worker.js | 20 | ||||
| -rw-r--r-- | node_modules/sync-request/package.json | 66 | ||||
| -rw-r--r-- | node_modules/sync-request/test/external-test.js | 31 | ||||
| -rw-r--r-- | node_modules/sync-request/test/fake-server.js | 42 | ||||
| -rw-r--r-- | node_modules/sync-request/test/index.js | 25 | ||||
| -rw-r--r-- | node_modules/sync-request/test/internal-test.js | 30 |
15 files changed, 0 insertions, 540 deletions
diff --git a/node_modules/sync-request/.npmignore b/node_modules/sync-request/.npmignore deleted file mode 100644 index b83202d..0000000 --- a/node_modules/sync-request/.npmignore +++ /dev/null @@ -1,13 +0,0 @@ -lib-cov -*.seed -*.log -*.csv -*.dat -*.out -*.pid -*.gz -pids -logs -results -npm-debug.log -node_modules diff --git a/node_modules/sync-request/.travis.yml b/node_modules/sync-request/.travis.yml deleted file mode 100644 index e2afa8c..0000000 --- a/node_modules/sync-request/.travis.yml +++ /dev/null @@ -1,5 +0,0 @@ -language: node_js -node_js: - - "0.12" - - "4.0" - - "4.1" diff --git a/node_modules/sync-request/LICENSE b/node_modules/sync-request/LICENSE deleted file mode 100644 index 27cc9f3..0000000 --- a/node_modules/sync-request/LICENSE +++ /dev/null @@ -1,19 +0,0 @@ -Copyright (c) 2014 Forbes Lindesay - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE.
\ No newline at end of file diff --git a/node_modules/sync-request/README.md b/node_modules/sync-request/README.md deleted file mode 100644 index 2200820..0000000 --- a/node_modules/sync-request/README.md +++ /dev/null @@ -1,114 +0,0 @@ -# sync-request - -Make synchronous web requests with cross platform support. - -**N.B.** You should **not** be using this in a production application. In a node.js application you will find that you are completely unable to scale your server. In a client application you will find that sync-request causes the app to hang/freeze. Synchronous web requests are the number one cause of browser crashes. For production apps, you should use [then-request](https://github.com/then/then-request), which is exactly the same except that it is asynchronous. - -[](https://travis-ci.org/ForbesLindesay/sync-request) -[](https://david-dm.org/ForbesLindesay/sync-request) -[](https://www.npmjs.org/package/sync-request) - -## Installation - - npm install sync-request - -## Usage - -```js -request(method, url, options) -``` - -e.g. - -- GET request without options - -```js -var request = require('sync-request'); -var res = request('GET', 'http://example.com'); -console.log(res.getBody()); -``` - -- GET request with options - -```js -var request = require('sync-request'); -var res = request('GET', 'https://example.com', { - 'headers': { - 'user-agent': 'example-user-agent' - } -}); -console.log(res.getBody()); -``` - -- POST request to a JSON endpoint - -```js -var request = require('sync-request'); -var res = request('POST', 'https://example.com/create-user', { - json: { username: 'ForbesLindesay' } -}); -var user = JSON.parse(res.getBody('utf8')); -``` - -**Method:** - -An HTTP method (e.g. `GET`, `POST`, `PUT`, `DELETE` or `HEAD`). It is not case sensitive. - -**URL:** - -A url as a string (e.g. `http://example.com`). Relative URLs are allowed in the browser. - -**Options:** - - - `qs` - an object containing querystring values to be appended to the uri - - `headers` - http headers (default: `{}`) - - `body` - body for PATCH, POST and PUT requests. Must be a `Buffer` or `String` (only strings are accepted client side) - - `json` - sets `body` but to JSON representation of value and adds `Content-type: application/json`. Does not have any affect on how the response is treated. - - `cache` - Set this to `'file'` to enable a local cache of content. A separate process is still spawned even for cache requests. This option is only used if running in node.js - - `followRedirects` - defaults to `true` but can be explicitly set to `false` on node.js to prevent then-request following redirects automatically. - - `maxRedirects` - sets the maximum number of redirects to follow before erroring on node.js (default: `Infinity`) - - `gzip` - defaults to `true` but can be explicitly set to `false` on node.js to prevent then-request automatically supporting the gzip encoding on responses. - - `timeout` (default: `false`) - times out if no response is returned within the given number of milliseconds. - - `socketTimeout` (default: `false`) - calls `req.setTimeout` internally which causes the request to timeout if no new data is seen for the given number of milliseconds. This option is ignored in the browser. - - `retry` (default: `false`) - retry GET requests. Set this to `true` to retry when the request errors or returns a status code greater than or equal to 400 - - `retryDelay` (default: `200`) - the delay between retries in milliseconds - - `maxRetries` (default: `5`) - the number of times to retry before giving up. - -These options are passed through to [then-request](https://github.com/then/then-request), so any options that work for then-request should work for sync-request (with the exception of custom and memory caching strategies, and passing functions for handling retries). - -**Returns:** - -A `Response` object. - -Note that even for status codes that represent an error, the request function will still return a response. You can call `getBody` if you want to error on invalid status codes. The response has the following properties: - - - `statusCode` - a number representing the HTTP status code - - `headers` - http response headers - - `body` - a string if in the browser or a buffer if on the server - -It also has a method `res.getBody(encoding?)` which looks like: - -```js -function getBody(encoding) { - if (this.statusCode >= 300) { - var err = new Error('Server responded with status code ' + this.statusCode + ':\n' + this.body.toString(encoding)); - err.statusCode = this.statusCode; - err.headers = this.headers; - err.body = this.body; - throw err; - } - return encoding ? this.body.toString(encoding) : this.body; -} -``` - -## How is this possible? - -Internally, this uses a separate worker process that is run using either [childProcess.spawnSync](http://nodejs.org/docs/v0.11.13/api/child_process.html#child_process_child_process_spawnsync_command_args_options) if available, or falling back to [spawn-sync](https://www.npmjs.org/package/spawn-sync) if not. The fallback will attempt to install a native module for synchronous execution, and fall back to doing busy waiting for a file to exist. All this ultimatley means that the module is totally cross platform and does not require native code compilation support. - -The worker then makes the actual request using [then-request](https://www.npmjs.org/package/then-request) so this has almost exactly the same API as that. - -This can also be used in a web browser via browserify because xhr has built in support for synchronous execution. Note that this is not recommended as it will be blocking. - -## License - - MIT diff --git a/node_modules/sync-request/browser.js b/node_modules/sync-request/browser.js deleted file mode 100644 index e652e0c..0000000 --- a/node_modules/sync-request/browser.js +++ /dev/null @@ -1,64 +0,0 @@ -'use strict'; - -var Response = require('http-response-object'); -var handleQs = require('then-request/lib/handle-qs.js'); - -module.exports = doRequest; -function doRequest(method, url, options) { - var xhr = new XMLHttpRequest(); - - // check types of arguments - - if (typeof method !== 'string') { - throw new TypeError('The method must be a string.'); - } - if (typeof url !== 'string') { - throw new TypeError('The URL/path must be a string.'); - } - if (options === null || options === undefined) { - options = {}; - } - if (typeof options !== 'object') { - throw new TypeError('Options must be an object (or null).'); - } - - method = method.toUpperCase(); - options.headers = options.headers || {}; - - // handle cross domain - - var match; - var crossDomain = !!((match = /^([\w-]+:)?\/\/([^\/]+)/.exec(options.uri)) && (match[2] != location.host)); - if (!crossDomain) options.headers['X-Requested-With'] = 'XMLHttpRequest'; - - // handle query string - if (options.qs) { - url = handleQs(url, options.qs); - } - - // handle json body - if (options.json) { - options.body = JSON.stringify(options.json); - options.headers['content-type'] = 'application/json'; - } - - // method, url, async - xhr.open(method, url, false); - - for (var name in options.headers) { - xhr.setRequestHeader(name.toLowerCase(), options.headers[name]); - } - - // avoid sending empty string (#319) - xhr.send(options.body ? options.body : null); - - - var headers = {}; - xhr.getAllResponseHeaders().split('\r\n').forEach(function (header) { - var h = header.split(':'); - if (h.length > 1) { - headers[h[0].toLowerCase()] = h.slice(1).join(':').trim(); - } - }); - return new Response(xhr.status, headers, xhr.responseText); -} diff --git a/node_modules/sync-request/index.js b/node_modules/sync-request/index.js deleted file mode 100644 index e4990d1..0000000 --- a/node_modules/sync-request/index.js +++ /dev/null @@ -1,33 +0,0 @@ -'use strict'; - -var fs = require('fs'); -var spawnSync = require('child_process').spawnSync || require('spawn-sync'); -var HttpResponse = require('http-response-object'); -require('concat-stream'); -require('then-request'); -var JSON = require('./lib/json-buffer'); - -Function('', fs.readFileSync(require.resolve('./lib/worker.js'), 'utf8')); - -module.exports = doRequest; -function doRequest(method, url, options) { - var req = JSON.stringify({ - method: method, - url: url, - options: options - }); - var res = spawnSync(process.execPath, [require.resolve('./lib/worker.js')], {input: req}); - if (res.status !== 0) { - throw new Error(res.stderr.toString()); - } - if (res.error) { - if (typeof res.error === 'string') res.error = new Error(res.error); - throw res.error; - } - var response = JSON.parse(res.stdout); - if (response.success) { - return new HttpResponse(response.response.statusCode, response.response.headers, response.response.body, response.response.url); - } else { - throw new Error(response.error.message || response.error || response); - } -} diff --git a/node_modules/sync-request/lib/json-buffer/LICENSE b/node_modules/sync-request/lib/json-buffer/LICENSE deleted file mode 100644 index 4732cb1..0000000 --- a/node_modules/sync-request/lib/json-buffer/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -Copyright (c) 2013 Dominic Tarr - -Permission is hereby granted, free of charge, -to any person obtaining a copy of this software and -associated documentation files (the "Software"), to -deal in the Software without restriction, including -without limitation the rights to use, copy, modify, -merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom -the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR -ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/sync-request/lib/json-buffer/README.md b/node_modules/sync-request/lib/json-buffer/README.md deleted file mode 100644 index 5311c0a..0000000 --- a/node_modules/sync-request/lib/json-buffer/README.md +++ /dev/null @@ -1 +0,0 @@ -Code based on https://github.com/dominictarr/json-buffer but adapted to be simpler to run in a purely node.js environment diff --git a/node_modules/sync-request/lib/json-buffer/index.js b/node_modules/sync-request/lib/json-buffer/index.js deleted file mode 100644 index 453b543..0000000 --- a/node_modules/sync-request/lib/json-buffer/index.js +++ /dev/null @@ -1,55 +0,0 @@ -'use strict'; - -//TODO: handle reviver/dehydrate function like normal -//and handle indentation, like normal. -//if anyone needs this... please send pull request. - -exports.stringify = function stringify (o) { - if(o && Buffer.isBuffer(o)) - return JSON.stringify(':base64:' + o.toString('base64')) - - if(o && o.toJSON) - o = o.toJSON() - - if(o && 'object' === typeof o) { - var s = '' - var array = Array.isArray(o) - s = array ? '[' : '{' - var first = true - - for(var k in o) { - var ignore = 'function' == typeof o[k] || (!array && 'undefined' === typeof o[k]) - if(Object.hasOwnProperty.call(o, k) && !ignore) { - if(!first) - s += ',' - first = false - if (array) { - s += stringify(o[k]) - } else if (o[k] !== void(0)) { - s += stringify(k) + ':' + stringify(o[k]) - } - } - } - - s += array ? ']' : '}' - - return s - } else if ('string' === typeof o) { - return JSON.stringify(/^:/.test(o) ? ':' + o : o) - } else if ('undefined' === typeof o) { - return 'null'; - } else - return JSON.stringify(o) -} - -exports.parse = function (s) { - return JSON.parse(s, function (key, value) { - if('string' === typeof value) { - if(/^:base64:/.test(value)) - return new Buffer(value.substring(8), 'base64') - else - return /^:/.test(value) ? value.substring(1) : value - } - return value - }) -} diff --git a/node_modules/sync-request/lib/worker.js b/node_modules/sync-request/lib/worker.js deleted file mode 100644 index 04ff0f3..0000000 --- a/node_modules/sync-request/lib/worker.js +++ /dev/null @@ -1,20 +0,0 @@ -'use strict'; - -var concat = require('concat-stream'); -var request = require('then-request'); -var JSON = require('./json-buffer'); - -function respond(data) { - process.stdout.write(JSON.stringify(data), function() { - process.exit(0); - }); -} - -process.stdin.pipe(concat(function (stdin) { - var req = JSON.parse(stdin.toString()); - request(req.method, req.url, req.options).done(function (response) { - respond({success: true, response: response}); - }, function (err) { - respond({success: false, error: { message: err.message }}); - }); -})); diff --git a/node_modules/sync-request/package.json b/node_modules/sync-request/package.json deleted file mode 100644 index 132300c..0000000 --- a/node_modules/sync-request/package.json +++ /dev/null @@ -1,66 +0,0 @@ -{ - "_from": "sync-request@^2.1.0", - "_id": "[email protected]", - "_inBundle": false, - "_integrity": "sha1-p70sES+glGPrkUnP8OnUKMR5do8=", - "_location": "/sync-request", - "_phantomChildren": {}, - "_requested": { - "type": "range", - "registry": true, - "raw": "sync-request@^2.1.0", - "name": "sync-request", - "escapedName": "sync-request", - "rawSpec": "^2.1.0", - "saveSpec": null, - "fetchSpec": "^2.1.0" - }, - "_requiredBy": [ - "/is-image-url" - ], - "_resolved": "https://registry.npmjs.org/sync-request/-/sync-request-2.2.0.tgz", - "_shasum": "a7bd2c112fa09463eb9149cff0e9d428c479768f", - "_spec": "sync-request@^2.1.0", - "_where": "E:\\Documents\\GitHub\\s5nical\\node_modules\\is-image-url", - "author": { - "name": "ForbesLindesay" - }, - "browser": "./browser.js", - "bugs": { - "url": "https://github.com/ForbesLindesay/sync-request/issues" - }, - "bundleDependencies": false, - "dependencies": { - "concat-stream": "^1.4.7", - "http-response-object": "^1.0.1", - "spawn-sync": "^1.0.1", - "then-request": "^2.0.1" - }, - "deprecated": false, - "description": "Make synchronous web requests", - "devDependencies": { - "body-parser": "^1.14.1", - "express": "^4.13.3", - "morgan": "^1.6.1" - }, - "homepage": "https://github.com/ForbesLindesay/sync-request#readme", - "keywords": [ - "request", - "http", - "https", - "cache", - "browserify", - "synchronous", - "sync" - ], - "license": "MIT", - "name": "sync-request", - "repository": { - "type": "git", - "url": "git+https://github.com/ForbesLindesay/sync-request.git" - }, - "scripts": { - "test": "node test" - }, - "version": "2.2.0" -} diff --git a/node_modules/sync-request/test/external-test.js b/node_modules/sync-request/test/external-test.js deleted file mode 100644 index b80880c..0000000 --- a/node_modules/sync-request/test/external-test.js +++ /dev/null @@ -1,31 +0,0 @@ -var request = require('../'); - -// Test GET request -console.dir('http://nodejs.org'); -var res = request('GET', 'http://nodejs.org'); - -console.log(res); -console.log("Reponse Body Length: ", res.getBody().length); - -// Test HTTPS POST request -console.dir('https://talk.to/'); -var res = request('POST', 'http://httpbin.org/post', { body: '<body/>' }); - -console.log(res); -console.log("Reponse Body Length: ", res.getBody().length); - -console.dir('https://apache.org'); -var errored = false; -try { - // Test unauthorized HTTPS GET request - var res = request('GET', 'https://apache.org'); - console.log(res); - console.log("Reponse Body: ", res.body.toString()); - errored = true; -} catch(ex) { - console.log("Successully rejected unauthorized host: https://apache.org/"); -} -if (errored) - throw new Error('Should have rejected unauthorized https get request'); - - diff --git a/node_modules/sync-request/test/fake-server.js b/node_modules/sync-request/test/fake-server.js deleted file mode 100644 index 2f359ad..0000000 --- a/node_modules/sync-request/test/fake-server.js +++ /dev/null @@ -1,42 +0,0 @@ -'use strict'; -var express = require('express'), - bodyParser = require('body-parser'), - morgan = require('morgan'), - PORT = 3030; - -var app = express(); - -// parse application/x-www-form-urlencoded -app.use(bodyParser.urlencoded({ extended: false })); - -// parse application/json -app.use(bodyParser.json()); - -// configure log -app.use(morgan('dev')); - -var started = false; -exports.isStarted = function() { return started }; - -var server; -process.on('message', function(m) { - if (m === 'start') { - server = app.listen(PORT, function () { - started = true; - console.log('fake server started', PORT); - return process.send('started');// m.cb && setTimeout(m.cb, 1000); - }); - } else { - server.close(function () { - started = false; - console.log('fake server stopped', PORT); - return process.send('closed') && process.exit(0); - }); - } -}); - -['get', 'post', 'put', 'delete'].forEach(function(method) { - app.route('/internal-test')[method](function(req, res){ - res.send('ok'); - }); -});
\ No newline at end of file diff --git a/node_modules/sync-request/test/index.js b/node_modules/sync-request/test/index.js deleted file mode 100644 index 0a21c6c..0000000 --- a/node_modules/sync-request/test/index.js +++ /dev/null @@ -1,25 +0,0 @@ -'use strict'; -var child = require('child_process'), - fork = child.fork, - server = fork(__dirname+ '/fake-server'); - -server.on('message', function(m) { - if (m === 'started') { - console.log('#############################'); - console.log('#### init internal test #####'); - console.log('#############################'); - - require('./internal-test'); - - server.send('stop'); - } else { - console.log('#############################'); - console.log('#### init external test #####'); - console.log('#############################'); - - require('./external-test'); - - process.exit(0); - } -}); -server.send('start'); diff --git a/node_modules/sync-request/test/internal-test.js b/node_modules/sync-request/test/internal-test.js deleted file mode 100644 index 04af989..0000000 --- a/node_modules/sync-request/test/internal-test.js +++ /dev/null @@ -1,30 +0,0 @@ -var request = require('../'); - -// Test GET request -console.log('GET', 'http://localhost:3030/internal-test'); -var res = request('GET', 'http://localhost:3030/internal-test', {timeout: 2000}); - -console.log(res); -console.log("Reponse Body Length: ", res.getBody().length); - -// Test HTTPS POST request -console.log('POST', 'http://localhost:3030/internal-test'); -var res = request('POST', 'http://localhost:3030/internal-test', {timeout: 2000, body: '<body/>' }); - -console.log(res); -console.log("Reponse Body Length: ", res.getBody().length); - -// Test PUT request -console.log('PUT', 'http://localhost:3030/internal-test'); -var res = request('PUT', 'http://localhost:3030/internal-test', {timeout: 2000, body: '<body/>' }); - -console.log(res); -console.log("Reponse Body Length: ", res.getBody().length); - -// Test HTTPS DELETE request -console.log('DELETE', 'http://localhost:3030/internal-test'); -var res = request('DELETE', 'http://localhost:3030/internal-test', {timeout: 2000}); - -console.log(res); -console.log("Reponse Body Length: ", res.getBody().length); - |