mirror of
				https://github.com/1disk/edp445.git
				synced 2024-08-14 22:47:02 +00:00 
			
		
		
		
	Changed alot of things.
This commit is contained in:
		
							parent
							
								
									a5a0523e5a
								
							
						
					
					
						commit
						3513d5390c
					
				
					 2016 changed files with 336930 additions and 9 deletions
				
			
		
							
								
								
									
										19
									
								
								node_modules/form-data/License
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								node_modules/form-data/License
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,19 @@ | |||
| Copyright (c) 2012 Felix Geisendörfer (felix@debuggable.com) and contributors | ||||
| 
 | ||||
|  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. | ||||
							
								
								
									
										234
									
								
								node_modules/form-data/README.md
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										234
									
								
								node_modules/form-data/README.md
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,234 @@ | |||
| # Form-Data [](https://www.npmjs.com/package/form-data) [](https://gitter.im/form-data/form-data) | ||||
| 
 | ||||
| A library to create readable ```"multipart/form-data"``` streams. Can be used to submit forms and file uploads to other web applications. | ||||
| 
 | ||||
| The API of this library is inspired by the [XMLHttpRequest-2 FormData Interface][xhr2-fd]. | ||||
| 
 | ||||
| [xhr2-fd]: http://dev.w3.org/2006/webapi/XMLHttpRequest-2/Overview.html#the-formdata-interface | ||||
| 
 | ||||
| [](https://travis-ci.org/form-data/form-data) | ||||
| [](https://travis-ci.org/form-data/form-data) | ||||
| [](https://ci.appveyor.com/project/alexindigo/form-data) | ||||
| 
 | ||||
| [](https://coveralls.io/github/form-data/form-data?branch=master) | ||||
| [](https://david-dm.org/form-data/form-data) | ||||
| [](https://www.bithound.io/github/form-data/form-data) | ||||
| 
 | ||||
| ## Install | ||||
| 
 | ||||
| ``` | ||||
| npm install --save form-data | ||||
| ``` | ||||
| 
 | ||||
| ## Usage | ||||
| 
 | ||||
| In this example we are constructing a form with 3 fields that contain a string, | ||||
| a buffer and a file stream. | ||||
| 
 | ||||
| ``` javascript | ||||
| var FormData = require('form-data'); | ||||
| var fs = require('fs'); | ||||
| 
 | ||||
| var form = new FormData(); | ||||
| form.append('my_field', 'my value'); | ||||
| form.append('my_buffer', new Buffer(10)); | ||||
| form.append('my_file', fs.createReadStream('/foo/bar.jpg')); | ||||
| ``` | ||||
| 
 | ||||
| Also you can use http-response stream: | ||||
| 
 | ||||
| ``` javascript | ||||
| var FormData = require('form-data'); | ||||
| var http = require('http'); | ||||
| 
 | ||||
| var form = new FormData(); | ||||
| 
 | ||||
| http.request('http://nodejs.org/images/logo.png', function(response) { | ||||
|   form.append('my_field', 'my value'); | ||||
|   form.append('my_buffer', new Buffer(10)); | ||||
|   form.append('my_logo', response); | ||||
| }); | ||||
| ``` | ||||
| 
 | ||||
| Or @mikeal's [request](https://github.com/request/request) stream: | ||||
| 
 | ||||
| ``` javascript | ||||
| var FormData = require('form-data'); | ||||
| var request = require('request'); | ||||
| 
 | ||||
| var form = new FormData(); | ||||
| 
 | ||||
| form.append('my_field', 'my value'); | ||||
| form.append('my_buffer', new Buffer(10)); | ||||
| form.append('my_logo', request('http://nodejs.org/images/logo.png')); | ||||
| ``` | ||||
| 
 | ||||
| In order to submit this form to a web application, call ```submit(url, [callback])``` method: | ||||
| 
 | ||||
| ``` javascript | ||||
| form.submit('http://example.org/', function(err, res) { | ||||
|   // res – response object (http.IncomingMessage)  // | ||||
|   res.resume(); | ||||
| }); | ||||
| 
 | ||||
| ``` | ||||
| 
 | ||||
| For more advanced request manipulations ```submit()``` method returns ```http.ClientRequest``` object, or you can choose from one of the alternative submission methods. | ||||
| 
 | ||||
| ### Custom options | ||||
| 
 | ||||
| You can provide custom options, such as `maxDataSize`: | ||||
| 
 | ||||
| ``` javascript | ||||
| var FormData = require('form-data'); | ||||
| 
 | ||||
| var form = new FormData({ maxDataSize: 20971520 }); | ||||
| form.append('my_field', 'my value'); | ||||
| form.append('my_buffer', /* something big */); | ||||
| ``` | ||||
| 
 | ||||
| List of available options could be found in [combined-stream](https://github.com/felixge/node-combined-stream/blob/master/lib/combined_stream.js#L7-L15) | ||||
| 
 | ||||
| ### Alternative submission methods | ||||
| 
 | ||||
| You can use node's http client interface: | ||||
| 
 | ||||
| ``` javascript | ||||
| var http = require('http'); | ||||
| 
 | ||||
| var request = http.request({ | ||||
|   method: 'post', | ||||
|   host: 'example.org', | ||||
|   path: '/upload', | ||||
|   headers: form.getHeaders() | ||||
| }); | ||||
| 
 | ||||
| form.pipe(request); | ||||
| 
 | ||||
| request.on('response', function(res) { | ||||
|   console.log(res.statusCode); | ||||
| }); | ||||
| ``` | ||||
| 
 | ||||
| Or if you would prefer the `'Content-Length'` header to be set for you: | ||||
| 
 | ||||
| ``` javascript | ||||
| form.submit('example.org/upload', function(err, res) { | ||||
|   console.log(res.statusCode); | ||||
| }); | ||||
| ``` | ||||
| 
 | ||||
| To use custom headers and pre-known length in parts: | ||||
| 
 | ||||
| ``` javascript | ||||
| var CRLF = '\r\n'; | ||||
| var form = new FormData(); | ||||
| 
 | ||||
| var options = { | ||||
|   header: CRLF + '--' + form.getBoundary() + CRLF + 'X-Custom-Header: 123' + CRLF + CRLF, | ||||
|   knownLength: 1 | ||||
| }; | ||||
| 
 | ||||
| form.append('my_buffer', buffer, options); | ||||
| 
 | ||||
| form.submit('http://example.com/', function(err, res) { | ||||
|   if (err) throw err; | ||||
|   console.log('Done'); | ||||
| }); | ||||
| ``` | ||||
| 
 | ||||
| Form-Data can recognize and fetch all the required information from common types of streams (```fs.readStream```, ```http.response``` and ```mikeal's request```), for some other types of streams you'd need to provide "file"-related information manually: | ||||
| 
 | ||||
| ``` javascript | ||||
| someModule.stream(function(err, stdout, stderr) { | ||||
|   if (err) throw err; | ||||
| 
 | ||||
|   var form = new FormData(); | ||||
| 
 | ||||
|   form.append('file', stdout, { | ||||
|     filename: 'unicycle.jpg', // ... or: | ||||
|     filepath: 'photos/toys/unicycle.jpg', | ||||
|     contentType: 'image/jpeg', | ||||
|     knownLength: 19806 | ||||
|   }); | ||||
| 
 | ||||
|   form.submit('http://example.com/', function(err, res) { | ||||
|     if (err) throw err; | ||||
|     console.log('Done'); | ||||
|   }); | ||||
| }); | ||||
| ``` | ||||
| 
 | ||||
| The `filepath` property overrides `filename` and may contain a relative path. This is typically used when uploading [multiple files from a directory](https://wicg.github.io/entries-api/#dom-htmlinputelement-webkitdirectory). | ||||
| 
 | ||||
| For edge cases, like POST request to URL with query string or to pass HTTP auth credentials, object can be passed to `form.submit()` as first parameter: | ||||
| 
 | ||||
| ``` javascript | ||||
| form.submit({ | ||||
|   host: 'example.com', | ||||
|   path: '/probably.php?extra=params', | ||||
|   auth: 'username:password' | ||||
| }, function(err, res) { | ||||
|   console.log(res.statusCode); | ||||
| }); | ||||
| ``` | ||||
| 
 | ||||
| In case you need to also send custom HTTP headers with the POST request, you can use the `headers` key in first parameter of `form.submit()`: | ||||
| 
 | ||||
| ``` javascript | ||||
| form.submit({ | ||||
|   host: 'example.com', | ||||
|   path: '/surelynot.php', | ||||
|   headers: {'x-test-header': 'test-header-value'} | ||||
| }, function(err, res) { | ||||
|   console.log(res.statusCode); | ||||
| }); | ||||
| ``` | ||||
| 
 | ||||
| ### Integration with other libraries | ||||
| 
 | ||||
| #### Request | ||||
| 
 | ||||
| Form submission using  [request](https://github.com/request/request): | ||||
| 
 | ||||
| ```javascript | ||||
| var formData = { | ||||
|   my_field: 'my_value', | ||||
|   my_file: fs.createReadStream(__dirname + '/unicycle.jpg'), | ||||
| }; | ||||
| 
 | ||||
| request.post({url:'http://service.com/upload', formData: formData}, function(err, httpResponse, body) { | ||||
|   if (err) { | ||||
|     return console.error('upload failed:', err); | ||||
|   } | ||||
|   console.log('Upload successful!  Server responded with:', body); | ||||
| }); | ||||
| ``` | ||||
| 
 | ||||
| For more details see [request readme](https://github.com/request/request#multipartform-data-multipart-form-uploads). | ||||
| 
 | ||||
| #### node-fetch | ||||
| 
 | ||||
| You can also submit a form using [node-fetch](https://github.com/bitinn/node-fetch): | ||||
| 
 | ||||
| ```javascript | ||||
| var form = new FormData(); | ||||
| 
 | ||||
| form.append('a', 1); | ||||
| 
 | ||||
| fetch('http://example.com', { method: 'POST', body: form }) | ||||
|     .then(function(res) { | ||||
|         return res.json(); | ||||
|     }).then(function(json) { | ||||
|         console.log(json); | ||||
|     }); | ||||
| ``` | ||||
| 
 | ||||
| ## Notes | ||||
| 
 | ||||
| - ```getLengthSync()``` method DOESN'T calculate length for streams, use ```knownLength``` options as workaround. | ||||
| - Starting version `2.x` FormData has dropped support for `node@0.10.x`. | ||||
| 
 | ||||
| ## License | ||||
| 
 | ||||
| Form-Data is released under the [MIT](License) license. | ||||
							
								
								
									
										234
									
								
								node_modules/form-data/README.md.bak
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										234
									
								
								node_modules/form-data/README.md.bak
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,234 @@ | |||
| # Form-Data [](https://www.npmjs.com/package/form-data) [](https://gitter.im/form-data/form-data) | ||||
| 
 | ||||
| A library to create readable ```"multipart/form-data"``` streams. Can be used to submit forms and file uploads to other web applications. | ||||
| 
 | ||||
| The API of this library is inspired by the [XMLHttpRequest-2 FormData Interface][xhr2-fd]. | ||||
| 
 | ||||
| [xhr2-fd]: http://dev.w3.org/2006/webapi/XMLHttpRequest-2/Overview.html#the-formdata-interface | ||||
| 
 | ||||
| [](https://travis-ci.org/form-data/form-data) | ||||
| [](https://travis-ci.org/form-data/form-data) | ||||
| [](https://ci.appveyor.com/project/alexindigo/form-data) | ||||
| 
 | ||||
| [](https://coveralls.io/github/form-data/form-data?branch=master) | ||||
| [](https://david-dm.org/form-data/form-data) | ||||
| [](https://www.bithound.io/github/form-data/form-data) | ||||
| 
 | ||||
| ## Install | ||||
| 
 | ||||
| ``` | ||||
| npm install --save form-data | ||||
| ``` | ||||
| 
 | ||||
| ## Usage | ||||
| 
 | ||||
| In this example we are constructing a form with 3 fields that contain a string, | ||||
| a buffer and a file stream. | ||||
| 
 | ||||
| ``` javascript | ||||
| var FormData = require('form-data'); | ||||
| var fs = require('fs'); | ||||
| 
 | ||||
| var form = new FormData(); | ||||
| form.append('my_field', 'my value'); | ||||
| form.append('my_buffer', new Buffer(10)); | ||||
| form.append('my_file', fs.createReadStream('/foo/bar.jpg')); | ||||
| ``` | ||||
| 
 | ||||
| Also you can use http-response stream: | ||||
| 
 | ||||
| ``` javascript | ||||
| var FormData = require('form-data'); | ||||
| var http = require('http'); | ||||
| 
 | ||||
| var form = new FormData(); | ||||
| 
 | ||||
| http.request('http://nodejs.org/images/logo.png', function(response) { | ||||
|   form.append('my_field', 'my value'); | ||||
|   form.append('my_buffer', new Buffer(10)); | ||||
|   form.append('my_logo', response); | ||||
| }); | ||||
| ``` | ||||
| 
 | ||||
| Or @mikeal's [request](https://github.com/request/request) stream: | ||||
| 
 | ||||
| ``` javascript | ||||
| var FormData = require('form-data'); | ||||
| var request = require('request'); | ||||
| 
 | ||||
| var form = new FormData(); | ||||
| 
 | ||||
| form.append('my_field', 'my value'); | ||||
| form.append('my_buffer', new Buffer(10)); | ||||
| form.append('my_logo', request('http://nodejs.org/images/logo.png')); | ||||
| ``` | ||||
| 
 | ||||
| In order to submit this form to a web application, call ```submit(url, [callback])``` method: | ||||
| 
 | ||||
| ``` javascript | ||||
| form.submit('http://example.org/', function(err, res) { | ||||
|   // res – response object (http.IncomingMessage)  // | ||||
|   res.resume(); | ||||
| }); | ||||
| 
 | ||||
| ``` | ||||
| 
 | ||||
| For more advanced request manipulations ```submit()``` method returns ```http.ClientRequest``` object, or you can choose from one of the alternative submission methods. | ||||
| 
 | ||||
| ### Custom options | ||||
| 
 | ||||
| You can provide custom options, such as `maxDataSize`: | ||||
| 
 | ||||
| ``` javascript | ||||
| var FormData = require('form-data'); | ||||
| 
 | ||||
| var form = new FormData({ maxDataSize: 20971520 }); | ||||
| form.append('my_field', 'my value'); | ||||
| form.append('my_buffer', /* something big */); | ||||
| ``` | ||||
| 
 | ||||
| List of available options could be found in [combined-stream](https://github.com/felixge/node-combined-stream/blob/master/lib/combined_stream.js#L7-L15) | ||||
| 
 | ||||
| ### Alternative submission methods | ||||
| 
 | ||||
| You can use node's http client interface: | ||||
| 
 | ||||
| ``` javascript | ||||
| var http = require('http'); | ||||
| 
 | ||||
| var request = http.request({ | ||||
|   method: 'post', | ||||
|   host: 'example.org', | ||||
|   path: '/upload', | ||||
|   headers: form.getHeaders() | ||||
| }); | ||||
| 
 | ||||
| form.pipe(request); | ||||
| 
 | ||||
| request.on('response', function(res) { | ||||
|   console.log(res.statusCode); | ||||
| }); | ||||
| ``` | ||||
| 
 | ||||
| Or if you would prefer the `'Content-Length'` header to be set for you: | ||||
| 
 | ||||
| ``` javascript | ||||
| form.submit('example.org/upload', function(err, res) { | ||||
|   console.log(res.statusCode); | ||||
| }); | ||||
| ``` | ||||
| 
 | ||||
| To use custom headers and pre-known length in parts: | ||||
| 
 | ||||
| ``` javascript | ||||
| var CRLF = '\r\n'; | ||||
| var form = new FormData(); | ||||
| 
 | ||||
| var options = { | ||||
|   header: CRLF + '--' + form.getBoundary() + CRLF + 'X-Custom-Header: 123' + CRLF + CRLF, | ||||
|   knownLength: 1 | ||||
| }; | ||||
| 
 | ||||
| form.append('my_buffer', buffer, options); | ||||
| 
 | ||||
| form.submit('http://example.com/', function(err, res) { | ||||
|   if (err) throw err; | ||||
|   console.log('Done'); | ||||
| }); | ||||
| ``` | ||||
| 
 | ||||
| Form-Data can recognize and fetch all the required information from common types of streams (```fs.readStream```, ```http.response``` and ```mikeal's request```), for some other types of streams you'd need to provide "file"-related information manually: | ||||
| 
 | ||||
| ``` javascript | ||||
| someModule.stream(function(err, stdout, stderr) { | ||||
|   if (err) throw err; | ||||
| 
 | ||||
|   var form = new FormData(); | ||||
| 
 | ||||
|   form.append('file', stdout, { | ||||
|     filename: 'unicycle.jpg', // ... or: | ||||
|     filepath: 'photos/toys/unicycle.jpg', | ||||
|     contentType: 'image/jpeg', | ||||
|     knownLength: 19806 | ||||
|   }); | ||||
| 
 | ||||
|   form.submit('http://example.com/', function(err, res) { | ||||
|     if (err) throw err; | ||||
|     console.log('Done'); | ||||
|   }); | ||||
| }); | ||||
| ``` | ||||
| 
 | ||||
| The `filepath` property overrides `filename` and may contain a relative path. This is typically used when uploading [multiple files from a directory](https://wicg.github.io/entries-api/#dom-htmlinputelement-webkitdirectory). | ||||
| 
 | ||||
| For edge cases, like POST request to URL with query string or to pass HTTP auth credentials, object can be passed to `form.submit()` as first parameter: | ||||
| 
 | ||||
| ``` javascript | ||||
| form.submit({ | ||||
|   host: 'example.com', | ||||
|   path: '/probably.php?extra=params', | ||||
|   auth: 'username:password' | ||||
| }, function(err, res) { | ||||
|   console.log(res.statusCode); | ||||
| }); | ||||
| ``` | ||||
| 
 | ||||
| In case you need to also send custom HTTP headers with the POST request, you can use the `headers` key in first parameter of `form.submit()`: | ||||
| 
 | ||||
| ``` javascript | ||||
| form.submit({ | ||||
|   host: 'example.com', | ||||
|   path: '/surelynot.php', | ||||
|   headers: {'x-test-header': 'test-header-value'} | ||||
| }, function(err, res) { | ||||
|   console.log(res.statusCode); | ||||
| }); | ||||
| ``` | ||||
| 
 | ||||
| ### Integration with other libraries | ||||
| 
 | ||||
| #### Request | ||||
| 
 | ||||
| Form submission using  [request](https://github.com/request/request): | ||||
| 
 | ||||
| ```javascript | ||||
| var formData = { | ||||
|   my_field: 'my_value', | ||||
|   my_file: fs.createReadStream(__dirname + '/unicycle.jpg'), | ||||
| }; | ||||
| 
 | ||||
| request.post({url:'http://service.com/upload', formData: formData}, function(err, httpResponse, body) { | ||||
|   if (err) { | ||||
|     return console.error('upload failed:', err); | ||||
|   } | ||||
|   console.log('Upload successful!  Server responded with:', body); | ||||
| }); | ||||
| ``` | ||||
| 
 | ||||
| For more details see [request readme](https://github.com/request/request#multipartform-data-multipart-form-uploads). | ||||
| 
 | ||||
| #### node-fetch | ||||
| 
 | ||||
| You can also submit a form using [node-fetch](https://github.com/bitinn/node-fetch): | ||||
| 
 | ||||
| ```javascript | ||||
| var form = new FormData(); | ||||
| 
 | ||||
| form.append('a', 1); | ||||
| 
 | ||||
| fetch('http://example.com', { method: 'POST', body: form }) | ||||
|     .then(function(res) { | ||||
|         return res.json(); | ||||
|     }).then(function(json) { | ||||
|         console.log(json); | ||||
|     }); | ||||
| ``` | ||||
| 
 | ||||
| ## Notes | ||||
| 
 | ||||
| - ```getLengthSync()``` method DOESN'T calculate length for streams, use ```knownLength``` options as workaround. | ||||
| - Starting version `2.x` FormData has dropped support for `node@0.10.x`. | ||||
| 
 | ||||
| ## License | ||||
| 
 | ||||
| Form-Data is released under the [MIT](License) license. | ||||
							
								
								
									
										2
									
								
								node_modules/form-data/lib/browser.js
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								node_modules/form-data/lib/browser.js
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,2 @@ | |||
| /* eslint-env browser */ | ||||
| module.exports = typeof self == 'object' ? self.FormData : window.FormData; | ||||
							
								
								
									
										457
									
								
								node_modules/form-data/lib/form_data.js
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										457
									
								
								node_modules/form-data/lib/form_data.js
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,457 @@ | |||
| var CombinedStream = require('combined-stream'); | ||||
| var util = require('util'); | ||||
| var path = require('path'); | ||||
| var http = require('http'); | ||||
| var https = require('https'); | ||||
| var parseUrl = require('url').parse; | ||||
| var fs = require('fs'); | ||||
| var mime = require('mime-types'); | ||||
| var asynckit = require('asynckit'); | ||||
| var populate = require('./populate.js'); | ||||
| 
 | ||||
| // Public API
 | ||||
| module.exports = FormData; | ||||
| 
 | ||||
| // make it a Stream
 | ||||
| util.inherits(FormData, CombinedStream); | ||||
| 
 | ||||
| /** | ||||
|  * Create readable "multipart/form-data" streams. | ||||
|  * Can be used to submit forms | ||||
|  * and file uploads to other web applications. | ||||
|  * | ||||
|  * @constructor | ||||
|  * @param {Object} options - Properties to be added/overriden for FormData and CombinedStream | ||||
|  */ | ||||
| function FormData(options) { | ||||
|   if (!(this instanceof FormData)) { | ||||
|     return new FormData(); | ||||
|   } | ||||
| 
 | ||||
|   this._overheadLength = 0; | ||||
|   this._valueLength = 0; | ||||
|   this._valuesToMeasure = []; | ||||
| 
 | ||||
|   CombinedStream.call(this); | ||||
| 
 | ||||
|   options = options || {}; | ||||
|   for (var option in options) { | ||||
|     this[option] = options[option]; | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| FormData.LINE_BREAK = '\r\n'; | ||||
| FormData.DEFAULT_CONTENT_TYPE = 'application/octet-stream'; | ||||
| 
 | ||||
| FormData.prototype.append = function(field, value, options) { | ||||
| 
 | ||||
|   options = options || {}; | ||||
| 
 | ||||
|   // allow filename as single option
 | ||||
|   if (typeof options == 'string') { | ||||
|     options = {filename: options}; | ||||
|   } | ||||
| 
 | ||||
|   var append = CombinedStream.prototype.append.bind(this); | ||||
| 
 | ||||
|   // all that streamy business can't handle numbers
 | ||||
|   if (typeof value == 'number') { | ||||
|     value = '' + value; | ||||
|   } | ||||
| 
 | ||||
|   // https://github.com/felixge/node-form-data/issues/38
 | ||||
|   if (util.isArray(value)) { | ||||
|     // Please convert your array into string
 | ||||
|     // the way web server expects it
 | ||||
|     this._error(new Error('Arrays are not supported.')); | ||||
|     return; | ||||
|   } | ||||
| 
 | ||||
|   var header = this._multiPartHeader(field, value, options); | ||||
|   var footer = this._multiPartFooter(); | ||||
| 
 | ||||
|   append(header); | ||||
|   append(value); | ||||
|   append(footer); | ||||
| 
 | ||||
|   // pass along options.knownLength
 | ||||
|   this._trackLength(header, value, options); | ||||
| }; | ||||
| 
 | ||||
| FormData.prototype._trackLength = function(header, value, options) { | ||||
|   var valueLength = 0; | ||||
| 
 | ||||
|   // used w/ getLengthSync(), when length is known.
 | ||||
|   // e.g. for streaming directly from a remote server,
 | ||||
|   // w/ a known file a size, and not wanting to wait for
 | ||||
|   // incoming file to finish to get its size.
 | ||||
|   if (options.knownLength != null) { | ||||
|     valueLength += +options.knownLength; | ||||
|   } else if (Buffer.isBuffer(value)) { | ||||
|     valueLength = value.length; | ||||
|   } else if (typeof value === 'string') { | ||||
|     valueLength = Buffer.byteLength(value); | ||||
|   } | ||||
| 
 | ||||
|   this._valueLength += valueLength; | ||||
| 
 | ||||
|   // @check why add CRLF? does this account for custom/multiple CRLFs?
 | ||||
|   this._overheadLength += | ||||
|     Buffer.byteLength(header) + | ||||
|     FormData.LINE_BREAK.length; | ||||
| 
 | ||||
|   // empty or either doesn't have path or not an http response
 | ||||
|   if (!value || ( !value.path && !(value.readable && value.hasOwnProperty('httpVersion')) )) { | ||||
|     return; | ||||
|   } | ||||
| 
 | ||||
|   // no need to bother with the length
 | ||||
|   if (!options.knownLength) { | ||||
|     this._valuesToMeasure.push(value); | ||||
|   } | ||||
| }; | ||||
| 
 | ||||
| FormData.prototype._lengthRetriever = function(value, callback) { | ||||
| 
 | ||||
|   if (value.hasOwnProperty('fd')) { | ||||
| 
 | ||||
|     // take read range into a account
 | ||||
|     // `end` = Infinity –> read file till the end
 | ||||
|     //
 | ||||
|     // TODO: Looks like there is bug in Node fs.createReadStream
 | ||||
|     // it doesn't respect `end` options without `start` options
 | ||||
|     // Fix it when node fixes it.
 | ||||
|     // https://github.com/joyent/node/issues/7819
 | ||||
|     if (value.end != undefined && value.end != Infinity && value.start != undefined) { | ||||
| 
 | ||||
|       // when end specified
 | ||||
|       // no need to calculate range
 | ||||
|       // inclusive, starts with 0
 | ||||
|       callback(null, value.end + 1 - (value.start ? value.start : 0)); | ||||
| 
 | ||||
|     // not that fast snoopy
 | ||||
|     } else { | ||||
|       // still need to fetch file size from fs
 | ||||
|       fs.stat(value.path, function(err, stat) { | ||||
| 
 | ||||
|         var fileSize; | ||||
| 
 | ||||
|         if (err) { | ||||
|           callback(err); | ||||
|           return; | ||||
|         } | ||||
| 
 | ||||
|         // update final size based on the range options
 | ||||
|         fileSize = stat.size - (value.start ? value.start : 0); | ||||
|         callback(null, fileSize); | ||||
|       }); | ||||
|     } | ||||
| 
 | ||||
|   // or http response
 | ||||
|   } else if (value.hasOwnProperty('httpVersion')) { | ||||
|     callback(null, +value.headers['content-length']); | ||||
| 
 | ||||
|   // or request stream http://github.com/mikeal/request
 | ||||
|   } else if (value.hasOwnProperty('httpModule')) { | ||||
|     // wait till response come back
 | ||||
|     value.on('response', function(response) { | ||||
|       value.pause(); | ||||
|       callback(null, +response.headers['content-length']); | ||||
|     }); | ||||
|     value.resume(); | ||||
| 
 | ||||
|   // something else
 | ||||
|   } else { | ||||
|     callback('Unknown stream'); | ||||
|   } | ||||
| }; | ||||
| 
 | ||||
| FormData.prototype._multiPartHeader = function(field, value, options) { | ||||
|   // custom header specified (as string)?
 | ||||
|   // it becomes responsible for boundary
 | ||||
|   // (e.g. to handle extra CRLFs on .NET servers)
 | ||||
|   if (typeof options.header == 'string') { | ||||
|     return options.header; | ||||
|   } | ||||
| 
 | ||||
|   var contentDisposition = this._getContentDisposition(value, options); | ||||
|   var contentType = this._getContentType(value, options); | ||||
| 
 | ||||
|   var contents = ''; | ||||
|   var headers  = { | ||||
|     // add custom disposition as third element or keep it two elements if not
 | ||||
|     'Content-Disposition': ['form-data', 'name="' + field + '"'].concat(contentDisposition || []), | ||||
|     // if no content type. allow it to be empty array
 | ||||
|     'Content-Type': [].concat(contentType || []) | ||||
|   }; | ||||
| 
 | ||||
|   // allow custom headers.
 | ||||
|   if (typeof options.header == 'object') { | ||||
|     populate(headers, options.header); | ||||
|   } | ||||
| 
 | ||||
|   var header; | ||||
|   for (var prop in headers) { | ||||
|     if (!headers.hasOwnProperty(prop)) continue; | ||||
|     header = headers[prop]; | ||||
| 
 | ||||
|     // skip nullish headers.
 | ||||
|     if (header == null) { | ||||
|       continue; | ||||
|     } | ||||
| 
 | ||||
|     // convert all headers to arrays.
 | ||||
|     if (!Array.isArray(header)) { | ||||
|       header = [header]; | ||||
|     } | ||||
| 
 | ||||
|     // add non-empty headers.
 | ||||
|     if (header.length) { | ||||
|       contents += prop + ': ' + header.join('; ') + FormData.LINE_BREAK; | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   return '--' + this.getBoundary() + FormData.LINE_BREAK + contents + FormData.LINE_BREAK; | ||||
| }; | ||||
| 
 | ||||
| FormData.prototype._getContentDisposition = function(value, options) { | ||||
| 
 | ||||
|   var filename | ||||
|     , contentDisposition | ||||
|     ; | ||||
| 
 | ||||
|   if (typeof options.filepath === 'string') { | ||||
|     // custom filepath for relative paths
 | ||||
|     filename = path.normalize(options.filepath).replace(/\\/g, '/'); | ||||
|   } else if (options.filename || value.name || value.path) { | ||||
|     // custom filename take precedence
 | ||||
|     // formidable and the browser add a name property
 | ||||
|     // fs- and request- streams have path property
 | ||||
|     filename = path.basename(options.filename || value.name || value.path); | ||||
|   } else if (value.readable && value.hasOwnProperty('httpVersion')) { | ||||
|     // or try http response
 | ||||
|     filename = path.basename(value.client._httpMessage.path); | ||||
|   } | ||||
| 
 | ||||
|   if (filename) { | ||||
|     contentDisposition = 'filename="' + filename + '"'; | ||||
|   } | ||||
| 
 | ||||
|   return contentDisposition; | ||||
| }; | ||||
| 
 | ||||
| FormData.prototype._getContentType = function(value, options) { | ||||
| 
 | ||||
|   // use custom content-type above all
 | ||||
|   var contentType = options.contentType; | ||||
| 
 | ||||
|   // or try `name` from formidable, browser
 | ||||
|   if (!contentType && value.name) { | ||||
|     contentType = mime.lookup(value.name); | ||||
|   } | ||||
| 
 | ||||
|   // or try `path` from fs-, request- streams
 | ||||
|   if (!contentType && value.path) { | ||||
|     contentType = mime.lookup(value.path); | ||||
|   } | ||||
| 
 | ||||
|   // or if it's http-reponse
 | ||||
|   if (!contentType && value.readable && value.hasOwnProperty('httpVersion')) { | ||||
|     contentType = value.headers['content-type']; | ||||
|   } | ||||
| 
 | ||||
|   // or guess it from the filepath or filename
 | ||||
|   if (!contentType && (options.filepath || options.filename)) { | ||||
|     contentType = mime.lookup(options.filepath || options.filename); | ||||
|   } | ||||
| 
 | ||||
|   // fallback to the default content type if `value` is not simple value
 | ||||
|   if (!contentType && typeof value == 'object') { | ||||
|     contentType = FormData.DEFAULT_CONTENT_TYPE; | ||||
|   } | ||||
| 
 | ||||
|   return contentType; | ||||
| }; | ||||
| 
 | ||||
| FormData.prototype._multiPartFooter = function() { | ||||
|   return function(next) { | ||||
|     var footer = FormData.LINE_BREAK; | ||||
| 
 | ||||
|     var lastPart = (this._streams.length === 0); | ||||
|     if (lastPart) { | ||||
|       footer += this._lastBoundary(); | ||||
|     } | ||||
| 
 | ||||
|     next(footer); | ||||
|   }.bind(this); | ||||
| }; | ||||
| 
 | ||||
| FormData.prototype._lastBoundary = function() { | ||||
|   return '--' + this.getBoundary() + '--' + FormData.LINE_BREAK; | ||||
| }; | ||||
| 
 | ||||
| FormData.prototype.getHeaders = function(userHeaders) { | ||||
|   var header; | ||||
|   var formHeaders = { | ||||
|     'content-type': 'multipart/form-data; boundary=' + this.getBoundary() | ||||
|   }; | ||||
| 
 | ||||
|   for (header in userHeaders) { | ||||
|     if (userHeaders.hasOwnProperty(header)) { | ||||
|       formHeaders[header.toLowerCase()] = userHeaders[header]; | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   return formHeaders; | ||||
| }; | ||||
| 
 | ||||
| FormData.prototype.getBoundary = function() { | ||||
|   if (!this._boundary) { | ||||
|     this._generateBoundary(); | ||||
|   } | ||||
| 
 | ||||
|   return this._boundary; | ||||
| }; | ||||
| 
 | ||||
| FormData.prototype._generateBoundary = function() { | ||||
|   // This generates a 50 character boundary similar to those used by Firefox.
 | ||||
|   // They are optimized for boyer-moore parsing.
 | ||||
|   var boundary = '--------------------------'; | ||||
|   for (var i = 0; i < 24; i++) { | ||||
|     boundary += Math.floor(Math.random() * 10).toString(16); | ||||
|   } | ||||
| 
 | ||||
|   this._boundary = boundary; | ||||
| }; | ||||
| 
 | ||||
| // Note: getLengthSync DOESN'T calculate streams length
 | ||||
| // As workaround one can calculate file size manually
 | ||||
| // and add it as knownLength option
 | ||||
| FormData.prototype.getLengthSync = function() { | ||||
|   var knownLength = this._overheadLength + this._valueLength; | ||||
| 
 | ||||
|   // Don't get confused, there are 3 "internal" streams for each keyval pair
 | ||||
|   // so it basically checks if there is any value added to the form
 | ||||
|   if (this._streams.length) { | ||||
|     knownLength += this._lastBoundary().length; | ||||
|   } | ||||
| 
 | ||||
|   // https://github.com/form-data/form-data/issues/40
 | ||||
|   if (!this.hasKnownLength()) { | ||||
|     // Some async length retrievers are present
 | ||||
|     // therefore synchronous length calculation is false.
 | ||||
|     // Please use getLength(callback) to get proper length
 | ||||
|     this._error(new Error('Cannot calculate proper length in synchronous way.')); | ||||
|   } | ||||
| 
 | ||||
|   return knownLength; | ||||
| }; | ||||
| 
 | ||||
| // Public API to check if length of added values is known
 | ||||
| // https://github.com/form-data/form-data/issues/196
 | ||||
| // https://github.com/form-data/form-data/issues/262
 | ||||
| FormData.prototype.hasKnownLength = function() { | ||||
|   var hasKnownLength = true; | ||||
| 
 | ||||
|   if (this._valuesToMeasure.length) { | ||||
|     hasKnownLength = false; | ||||
|   } | ||||
| 
 | ||||
|   return hasKnownLength; | ||||
| }; | ||||
| 
 | ||||
| FormData.prototype.getLength = function(cb) { | ||||
|   var knownLength = this._overheadLength + this._valueLength; | ||||
| 
 | ||||
|   if (this._streams.length) { | ||||
|     knownLength += this._lastBoundary().length; | ||||
|   } | ||||
| 
 | ||||
|   if (!this._valuesToMeasure.length) { | ||||
|     process.nextTick(cb.bind(this, null, knownLength)); | ||||
|     return; | ||||
|   } | ||||
| 
 | ||||
|   asynckit.parallel(this._valuesToMeasure, this._lengthRetriever, function(err, values) { | ||||
|     if (err) { | ||||
|       cb(err); | ||||
|       return; | ||||
|     } | ||||
| 
 | ||||
|     values.forEach(function(length) { | ||||
|       knownLength += length; | ||||
|     }); | ||||
| 
 | ||||
|     cb(null, knownLength); | ||||
|   }); | ||||
| }; | ||||
| 
 | ||||
| FormData.prototype.submit = function(params, cb) { | ||||
|   var request | ||||
|     , options | ||||
|     , defaults = {method: 'post'} | ||||
|     ; | ||||
| 
 | ||||
|   // parse provided url if it's string
 | ||||
|   // or treat it as options object
 | ||||
|   if (typeof params == 'string') { | ||||
| 
 | ||||
|     params = parseUrl(params); | ||||
|     options = populate({ | ||||
|       port: params.port, | ||||
|       path: params.pathname, | ||||
|       host: params.hostname, | ||||
|       protocol: params.protocol | ||||
|     }, defaults); | ||||
| 
 | ||||
|   // use custom params
 | ||||
|   } else { | ||||
| 
 | ||||
|     options = populate(params, defaults); | ||||
|     // if no port provided use default one
 | ||||
|     if (!options.port) { | ||||
|       options.port = options.protocol == 'https:' ? 443 : 80; | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   // put that good code in getHeaders to some use
 | ||||
|   options.headers = this.getHeaders(params.headers); | ||||
| 
 | ||||
|   // https if specified, fallback to http in any other case
 | ||||
|   if (options.protocol == 'https:') { | ||||
|     request = https.request(options); | ||||
|   } else { | ||||
|     request = http.request(options); | ||||
|   } | ||||
| 
 | ||||
|   // get content length and fire away
 | ||||
|   this.getLength(function(err, length) { | ||||
|     if (err) { | ||||
|       this._error(err); | ||||
|       return; | ||||
|     } | ||||
| 
 | ||||
|     // add content length
 | ||||
|     request.setHeader('Content-Length', length); | ||||
| 
 | ||||
|     this.pipe(request); | ||||
|     if (cb) { | ||||
|       request.on('error', cb); | ||||
|       request.on('response', cb.bind(this, null)); | ||||
|     } | ||||
|   }.bind(this)); | ||||
| 
 | ||||
|   return request; | ||||
| }; | ||||
| 
 | ||||
| FormData.prototype._error = function(err) { | ||||
|   if (!this.error) { | ||||
|     this.error = err; | ||||
|     this.pause(); | ||||
|     this.emit('error', err); | ||||
|   } | ||||
| }; | ||||
| 
 | ||||
| FormData.prototype.toString = function () { | ||||
|   return '[object FormData]'; | ||||
| }; | ||||
							
								
								
									
										10
									
								
								node_modules/form-data/lib/populate.js
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								node_modules/form-data/lib/populate.js
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,10 @@ | |||
| // populates missing values
 | ||||
| module.exports = function(dst, src) { | ||||
| 
 | ||||
|   Object.keys(src).forEach(function(prop) | ||||
|   { | ||||
|     dst[prop] = dst[prop] || src[prop]; | ||||
|   }); | ||||
| 
 | ||||
|   return dst; | ||||
| }; | ||||
							
								
								
									
										65
									
								
								node_modules/form-data/package.json
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										65
									
								
								node_modules/form-data/package.json
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,65 @@ | |||
| { | ||||
|   "author": "Felix Geisendörfer <felix@debuggable.com> (http://debuggable.com/)", | ||||
|   "name": "form-data", | ||||
|   "description": "A library to create readable \"multipart/form-data\" streams. Can be used to submit forms and file uploads to other web applications.", | ||||
|   "version": "2.3.3", | ||||
|   "repository": { | ||||
|     "type": "git", | ||||
|     "url": "git://github.com/form-data/form-data.git" | ||||
|   }, | ||||
|   "main": "./lib/form_data", | ||||
|   "browser": "./lib/browser", | ||||
|   "scripts": { | ||||
|     "pretest": "rimraf coverage test/tmp", | ||||
|     "test": "istanbul cover test/run.js", | ||||
|     "posttest": "istanbul report lcov text", | ||||
|     "lint": "eslint lib/*.js test/*.js test/integration/*.js", | ||||
|     "report": "istanbul report lcov text", | ||||
|     "ci-lint": "is-node-modern 6 && npm run lint || is-node-not-modern 6", | ||||
|     "ci-test": "npm run test && npm run browser && npm run report", | ||||
|     "predebug": "rimraf coverage test/tmp", | ||||
|     "debug": "verbose=1 ./test/run.js", | ||||
|     "browser": "browserify -t browserify-istanbul test/run-browser.js | obake --coverage", | ||||
|     "check": "istanbul check-coverage coverage/coverage*.json", | ||||
|     "files": "pkgfiles --sort=name", | ||||
|     "get-version": "node -e \"console.log(require('./package.json').version)\"", | ||||
|     "update-readme": "sed -i.bak 's/\\/master\\.svg/\\/v'$(npm --silent run get-version)'.svg/g' README.md", | ||||
|     "restore-readme": "mv README.md.bak README.md", | ||||
|     "prepublish": "in-publish && npm run update-readme || not-in-publish", | ||||
|     "postpublish": "npm run restore-readme" | ||||
|   }, | ||||
|   "pre-commit": [ | ||||
|     "lint", | ||||
|     "ci-test", | ||||
|     "check" | ||||
|   ], | ||||
|   "engines": { | ||||
|     "node": ">= 0.12" | ||||
|   }, | ||||
|   "dependencies": { | ||||
|     "asynckit": "^0.4.0", | ||||
|     "combined-stream": "^1.0.6", | ||||
|     "mime-types": "^2.1.12" | ||||
|   }, | ||||
|   "devDependencies": { | ||||
|     "browserify": "^13.1.1", | ||||
|     "browserify-istanbul": "^2.0.0", | ||||
|     "coveralls": "^2.11.14", | ||||
|     "cross-spawn": "^4.0.2", | ||||
|     "eslint": "^3.9.1", | ||||
|     "fake": "^0.2.2", | ||||
|     "far": "^0.0.7", | ||||
|     "formidable": "^1.0.17", | ||||
|     "in-publish": "^2.0.0", | ||||
|     "is-node-modern": "^1.0.0", | ||||
|     "istanbul": "^0.4.5", | ||||
|     "obake": "^0.1.2", | ||||
|     "phantomjs-prebuilt": "^2.1.13", | ||||
|     "pkgfiles": "^2.3.0", | ||||
|     "pre-commit": "^1.1.3", | ||||
|     "request": "2.76.0", | ||||
|     "rimraf": "^2.5.4", | ||||
|     "tape": "^4.6.2" | ||||
|   }, | ||||
|   "license": "MIT" | ||||
| } | ||||
							
								
								
									
										2662
									
								
								node_modules/form-data/yarn.lock
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2662
									
								
								node_modules/form-data/yarn.lock
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue