mirror of
				https://github.com/therootcompany/request.js.git
				synced 2024-11-16 17:28:58 +00:00 
			
		
		
		
	Compare commits
	
		
			39 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| bb30d5acf6 | |||
| 5b539deb7b | |||
| 0a2e7afa76 | |||
| ba60df7eab | |||
| bc4f6e59c0 | |||
| 3842ee1d61 | |||
| 9518cb970b | |||
| 2e9a643c0f | |||
| dcd41a33d0 | |||
| 5f5e0b6066 | |||
| ed2bab931f | |||
| a95d003ed5 | |||
| 5149bc9dcb | |||
| 95a12a8285 | |||
| 9395ec96e3 | |||
| 3574e35635 | |||
| 508f1ce591 | |||
| c2c4b5b2de | |||
| f6557b7610 | |||
| 4b9a1f07ee | |||
| e22baa8eae | |||
| 812f4e6062 | |||
| 5b5cd36aa5 | |||
| 4f3fe38ee4 | |||
| ef3183e984 | |||
| e384aead9b | |||
| 87bf5a5fc5 | |||
| 1692b9e7df | |||
| 8f5133385b | |||
| 1507b38503 | |||
| 9ab91d9721 | |||
| b6900b937b | |||
| be91c1b78f | |||
| 335dd98631 | |||
| 28f3f783ae | |||
| 1d4c3c1997 | |||
| 999797270f | |||
|  | aec78877cf | ||
| 4eaf68966c | 
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,2 @@ | |||||||
|  | node_modules | ||||||
|  | .*.sw* | ||||||
							
								
								
									
										22
									
								
								.jshintrc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								.jshintrc
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,22 @@ | |||||||
|  | { | ||||||
|  |   "browser": true, | ||||||
|  |   "node": true, | ||||||
|  |   "esversion": 11, | ||||||
|  |   "curly": true, | ||||||
|  |   "sub": true, | ||||||
|  |   "bitwise": true, | ||||||
|  |   "eqeqeq": true, | ||||||
|  |   "forin": true, | ||||||
|  |   "freeze": true, | ||||||
|  |   "immed": true, | ||||||
|  |   "latedef": "nofunc", | ||||||
|  |   "nonbsp": true, | ||||||
|  |   "nonew": true, | ||||||
|  |   "plusplus": true, | ||||||
|  |   "undef": true, | ||||||
|  |   "unused": "vars", | ||||||
|  |   "strict": true, | ||||||
|  |   "maxdepth": 3, | ||||||
|  |   "maxstatements": 100, | ||||||
|  |   "maxcomplexity": 40 | ||||||
|  | } | ||||||
							
								
								
									
										8
									
								
								.prettierrc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								.prettierrc
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,8 @@ | |||||||
|  | { | ||||||
|  |   "bracketSpacing": true, | ||||||
|  |   "printWidth": 80, | ||||||
|  |   "singleQuote": true, | ||||||
|  |   "tabWidth": 4, | ||||||
|  |   "trailingComma": "none", | ||||||
|  |   "useTabs": false | ||||||
|  | } | ||||||
							
								
								
									
										6
									
								
								CHANGELOG.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								CHANGELOG.md
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,6 @@ | |||||||
|  | # CHANGELOG | ||||||
|  | 
 | ||||||
|  | ## v1.8.0 | ||||||
|  | 
 | ||||||
|  | -   add `resp.ok` - same as WHATWG fetch `resp.ok = (resp.statusCode >= 200 && resp.statusCode < 300)` | ||||||
|  | -   add `resp.stream.body()` to populate `resp.body` rather than (or perhaps in addition to) continuing to stream (useful for error handling) | ||||||
							
								
								
									
										65
									
								
								EXTRA.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										65
									
								
								EXTRA.md
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,65 @@ | |||||||
|  | # Extra | ||||||
|  | 
 | ||||||
|  | There are some niche features of @root/request which are beyond the request.js | ||||||
|  | compatibility. | ||||||
|  | 
 | ||||||
|  | ## async/await & Promises | ||||||
|  | 
 | ||||||
|  | The differences in async support are explained in [README.md](/README.md), up near the top. | ||||||
|  | 
 | ||||||
|  | If you're familiar with Promises (and async/await), then it's pretty self-explanatory. | ||||||
|  | 
 | ||||||
|  | ## ok | ||||||
|  | 
 | ||||||
|  | Just like WHATWG `fetch`, we have `resp.ok`: | ||||||
|  | 
 | ||||||
|  | ```js | ||||||
|  | let resp = await request({ | ||||||
|  |     url: 'https://example.com' | ||||||
|  | }).then(mustOk); | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | ```js | ||||||
|  | function mustOk(resp) { | ||||||
|  |     if (!resp.ok) { | ||||||
|  |         // handle error | ||||||
|  |         throw new Error('BAD RESPONSE'); | ||||||
|  |     } | ||||||
|  |     return resp; | ||||||
|  | } | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | ## streams | ||||||
|  | 
 | ||||||
|  | The differences in stream support are explained in [README.md](/README.md), up near the top. | ||||||
|  | 
 | ||||||
|  | ## userAgent | ||||||
|  | 
 | ||||||
|  | There's a default User-Agent string describing the version of @root/request, node.js, and the OS. | ||||||
|  | 
 | ||||||
|  | Add to the default User-Agent | ||||||
|  | 
 | ||||||
|  | ```js | ||||||
|  | request({ | ||||||
|  |     // ... | ||||||
|  |     userAgent: 'my-package/1.0' // add to agent | ||||||
|  | }); | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | Replace the default User-Agent | ||||||
|  | 
 | ||||||
|  | ```js | ||||||
|  | request({ | ||||||
|  |     // ... | ||||||
|  |     headers: { 'User-Agent': 'replace/0.0' } | ||||||
|  | }); | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | Disable the default User-Agent: | ||||||
|  | 
 | ||||||
|  | ```js | ||||||
|  | request({ | ||||||
|  |     // ... | ||||||
|  |     headers: { 'User-Agent': false } | ||||||
|  | }); | ||||||
|  | ``` | ||||||
							
								
								
									
										316
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										316
									
								
								README.md
									
									
									
									
									
								
							| @ -1,37 +1,147 @@ | |||||||
| # µRequest - Minimalist HTTP client | # [@root/request](https://git.rootprojects.org/root/request.js) | a [Root](https://rootprojects.org) project | ||||||
| 
 | 
 | ||||||
| A lightweight alternative to (and drop-in replacement for) request. | > Minimalist HTTP client | ||||||
| 
 | 
 | ||||||
| Written from scratch. | A lightweight alternative to (and 80/20 drop-in replacement for) request. | ||||||
|  | 
 | ||||||
|  | Has the 20% of features that 80%+ of people need, in about 500 LoC. | ||||||
|  | 
 | ||||||
|  | Written from scratch, with zero-dependencies. | ||||||
| 
 | 
 | ||||||
| ## Super simple to use | ## Super simple to use | ||||||
| 
 | 
 | ||||||
| µRequest is designed to be a drop-in replacement for request.  It supports HTTPS and follows redirects by default. | @root/request is designed to be a drop-in replacement for request. It also supports Promises and async/await by default, enhanced stream support, and a few other things as mentioned below. | ||||||
| 
 | 
 | ||||||
| ```bash | ```bash | ||||||
| npm install --save @coolaj86/urequest | npm install --save @root/request | ||||||
|  | 
 | ||||||
|  | # or npm install git+ssh://git@git.therootcompany.com/request.js | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| ```js | ```js | ||||||
| var request = require('@coolaj86/urequest'); | var request = require('@root/request'); | ||||||
| request('http://www.google.com', function (error, response, body) { | request('http://www.google.com', function (error, response, body) { | ||||||
|   console.log('error:', error); // Print the error if one occurred |     console.log('error:', error); // Print the error if one occurred | ||||||
|   console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received |     console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received | ||||||
|   console.log('body:', body); // Print the HTML for the Google homepage. |     console.log('body:', body); // Print the HTML for the Google homepage. | ||||||
| }); | }); | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
|  | **Using Promises** | ||||||
|  | 
 | ||||||
|  | ```js | ||||||
|  | var request = require('@root/request'); | ||||||
|  | 
 | ||||||
|  | request('http://www.google.com') | ||||||
|  |     .then(function (response) { | ||||||
|  |         console.log('statusCode:', response.statusCode); // Print the response status code if a response was received | ||||||
|  |         console.log('body:', response.body); // Print the HTML for the Google homepage. | ||||||
|  |     }) | ||||||
|  |     .catch(function (error) { | ||||||
|  |         console.log('error:', error); // Print the error if one occurred | ||||||
|  |     }); | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | **Streaming** | ||||||
|  | 
 | ||||||
|  | In order to keep this library lightweight, performant, and keep the code easy to | ||||||
|  | read, the streaming behavior is **_slightly different_** from that of | ||||||
|  | `request.js`. | ||||||
|  | 
 | ||||||
|  | ```diff | ||||||
|  | -var request = require('request'); | ||||||
|  | +var request = require('@root/request'); | ||||||
|  | 
 | ||||||
|  | -var stream = request({ url, headers }); | ||||||
|  | +var stream = await request({ url, headers }); | ||||||
|  | 
 | ||||||
|  |  let attachment = await new MailgunAPI.Attachment({ | ||||||
|  |    data: stream | ||||||
|  |  }) | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | Example: | ||||||
|  | 
 | ||||||
|  | ```js | ||||||
|  | var request = require('@root/request'); | ||||||
|  | 
 | ||||||
|  | var resp = await request({ | ||||||
|  |     url: 'http://www.google.com', | ||||||
|  |     stream: true // true | 'filename.ext' | stream.Writable | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | // 'resp' itself is a ReadableStream | ||||||
|  | resp.on('data', function () { | ||||||
|  |     // got some data | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | resp.on('end', function () { | ||||||
|  |     // the data has ended | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | // 'resp.stream' is a Promise that is resolved when the read stream is destroyed | ||||||
|  | await resp.stream; // returns `undefined` | ||||||
|  | console.log('Done'); | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | The difference is that we don't add an extra layer of stream abstraction. | ||||||
|  | You must use the response from await, a Promise, or the callback. | ||||||
|  | 
 | ||||||
|  | You can also give a file path: | ||||||
|  | 
 | ||||||
|  | ```js | ||||||
|  | request({ | ||||||
|  |     url: 'http://www.google.com', | ||||||
|  |     stream: '/tmp/google-index.html' | ||||||
|  | }); | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | Which is equivalent to passing a write stream for the file: | ||||||
|  | 
 | ||||||
|  | ```js | ||||||
|  | request({ | ||||||
|  |     url: 'http://www.google.com', | ||||||
|  |     stream: fs.createWriteStream('/tmp/google-index.html') | ||||||
|  | }); | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | Also, `await resp.stream.body()` can be used to get back the full body (the same as if you didn't use the `stream` option: | ||||||
|  | 
 | ||||||
|  | ```js | ||||||
|  | let resp = await request({ | ||||||
|  |     url: 'http://www.google.com', | ||||||
|  |     stream: true | ||||||
|  | }); | ||||||
|  | if (!resp.ok) { | ||||||
|  |     await resp.stream.body(); | ||||||
|  |     console.error(resp.body); | ||||||
|  | } | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
| ## Table of contents | ## Table of contents | ||||||
| 
 | 
 | ||||||
| - [Forms](#forms) | -   [Extra Features](/EXTRA.md) | ||||||
| - [HTTP Authentication](#http-authentication) | -   [Forms](#forms) | ||||||
| - [Custom HTTP Headers](#custom-http-headers) | -   [HTTP Authentication](#http-authentication) | ||||||
| - [Unix Domain Sockets](#unix-domain-sockets) | -   [Custom HTTP Headers](#custom-http-headers) | ||||||
| - [**All Available Options**](#requestoptions-callback) | -   [Unix Domain Sockets](#unix-domain-sockets) | ||||||
|  | -   [**All Available Options**](#requestoptions-callback) | ||||||
|  | 
 | ||||||
|  | ## Extra Features | ||||||
|  | 
 | ||||||
|  | The following are features that the original `request` did not have, but have been added for convenience in `@root/request`. | ||||||
|  | 
 | ||||||
|  | -   Support for `async`/`await` & `Promise`s (as explained above) | ||||||
|  | -   `request({ userAgent: 'my-api/1.1' })` (for building API clients) | ||||||
|  | -   `resp.ok` (just like `fetch`) | ||||||
|  | -   `resp.stream` (see above) | ||||||
|  | 
 | ||||||
|  | See [EXTRA.md](/EXTRA.md) | ||||||
| 
 | 
 | ||||||
| ## Forms | ## Forms | ||||||
| 
 | 
 | ||||||
| `urequest` supports `application/x-www-form-urlencoded` and `multipart/form-data` form uploads. | `@root/request` supports `application/x-www-form-urlencoded` and `multipart/form-data` form uploads. | ||||||
|  | 
 | ||||||
| <!-- For `multipart/related` refer to the `multipart` API. --> | <!-- For `multipart/related` refer to the `multipart` API. --> | ||||||
| 
 | 
 | ||||||
| #### application/x-www-form-urlencoded (URL-Encoded Forms) | #### application/x-www-form-urlencoded (URL-Encoded Forms) | ||||||
| @ -39,52 +149,66 @@ request('http://www.google.com', function (error, response, body) { | |||||||
| URL-encoded forms are simple. | URL-encoded forms are simple. | ||||||
| 
 | 
 | ||||||
| ```js | ```js | ||||||
| request.post('http://service.com/upload', {form:{key:'value'}}) | request.post('http://service.com/upload', { form: { key: 'value' } }); | ||||||
| // or | // or | ||||||
| request.post({url:'http://service.com/upload', form: {key:'value'}}, function(err,httpResponse,body){ /* ... */ }) | request.post( | ||||||
|  |     { url: 'http://service.com/upload', form: { key: 'value' } }, | ||||||
|  |     function (err, httpResponse, body) { | ||||||
|  |         /* ... */ | ||||||
|  |     } | ||||||
|  | ); | ||||||
| ``` | ``` | ||||||
|  | 
 | ||||||
| <!-- | <!-- | ||||||
| // or | // or | ||||||
| request.post('http://service.com/upload').form({key:'value'}) | request.post('http://service.com/upload').form({key:'value'}) | ||||||
| --> | --> | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| #### multipart/form-data (Multipart Form Uploads) | #### multipart/form-data (Multipart Form Uploads) | ||||||
| 
 | 
 | ||||||
| For `multipart/form-data` we use the [form-data](https://github.com/form-data/form-data) library by [@felixge](https://github.com/felixge). For the most cases, you can pass your upload form data via the `formData` option. | For `multipart/form-data` we use the [form-data](https://github.com/form-data/form-data/tree/v2.5.1) library by [@felixge](https://github.com/felixge). For the most cases, you can pass your upload form data via the `formData` option. | ||||||
| 
 | 
 | ||||||
|  | To use `form-data`, you must install it separately: | ||||||
|  | 
 | ||||||
|  | ```bash | ||||||
|  | npm install --save form-data@2.x | ||||||
|  | ``` | ||||||
| 
 | 
 | ||||||
| ```js | ```js | ||||||
| var formData = { | var formData = { | ||||||
|   // Pass a simple key-value pair |     // Pass a simple key-value pair | ||||||
|   my_field: 'my_value', |     my_field: 'my_value', | ||||||
|   // Pass data via Buffers |     // Pass data via Buffers | ||||||
|   my_buffer: Buffer.from([1, 2, 3]), |     my_buffer: Buffer.from([1, 2, 3]), | ||||||
|   // Pass data via Streams |     // Pass data via Streams | ||||||
|   my_file: fs.createReadStream(__dirname + '/unicycle.jpg'), |     my_file: fs.createReadStream(__dirname + '/unicycle.jpg'), | ||||||
|   // Pass multiple values /w an Array |     // Pass multiple values /w an Array | ||||||
|   attachments: [ |     attachments: [ | ||||||
|     fs.createReadStream(__dirname + '/attachment1.jpg'), |         fs.createReadStream(__dirname + '/attachment1.jpg'), | ||||||
|     fs.createReadStream(__dirname + '/attachment2.jpg') |         fs.createReadStream(__dirname + '/attachment2.jpg') | ||||||
|   ], |     ], | ||||||
|   // Pass optional meta-data with an 'options' object with style: {value: DATA, options: OPTIONS} |     // Pass optional meta-data with an 'options' object with style: {value: DATA, options: OPTIONS} | ||||||
|   // Use case: for some types of streams, you'll need to provide "file"-related information manually. |     // Use case: for some types of streams, you'll need to provide "file"-related information manually. | ||||||
|   // See the `form-data` README for more information about options: https://github.com/form-data/form-data |     // See the `form-data` README for more information about options: https://github.com/form-data/form-data | ||||||
|   custom_file: { |     custom_file: { | ||||||
|     value:  fs.createReadStream('/dev/urandom'), |         value: fs.createReadStream('/dev/urandom'), | ||||||
|     options: { |         options: { | ||||||
|       filename: 'topsecret.jpg', |             filename: 'topsecret.jpg', | ||||||
|       contentType: 'image/jpeg' |             contentType: 'image/jpeg' | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|   } |  | ||||||
| }; | }; | ||||||
| request.post({url:'http://service.com/upload', formData: formData}, function optionalCallback(err, httpResponse, body) { | request.post( | ||||||
|   if (err) { |     { url: 'http://service.com/upload', formData: formData }, | ||||||
|     return console.error('upload failed:', err); |     function optionalCallback(err, httpResponse, body) { | ||||||
|   } |         if (err) { | ||||||
|   console.log('Upload successful!  Server responded with:', body); |             return console.error('upload failed:', err); | ||||||
| }); |         } | ||||||
|  |         console.log('Upload successful!  Server responded with:', body); | ||||||
|  |     } | ||||||
|  | ); | ||||||
| ``` | ``` | ||||||
|  | 
 | ||||||
| <!-- | <!-- | ||||||
| 
 | 
 | ||||||
| For advanced cases, you can access the form-data object itself via `r.form()`. This can be modified until the request is fired on the next cycle of the event-loop. (Note that this calling `form()` will clear the currently set form data for that request.) | For advanced cases, you can access the form-data object itself via `r.form()`. This can be modified until the request is fired on the next cycle of the event-loop. (Note that this calling `form()` will clear the currently set form data for that request.) | ||||||
| @ -111,27 +235,28 @@ request.get('http://some.server.com/').auth('username', 'password', false); | |||||||
| request.get('http://some.server.com/').auth(null, null, true, 'bearerToken'); | request.get('http://some.server.com/').auth(null, null, true, 'bearerToken'); | ||||||
| // or | // or | ||||||
| --> | --> | ||||||
|  | 
 | ||||||
| ```js | ```js | ||||||
| request.get('http://some.server.com/', { | request.get('http://some.server.com/', { | ||||||
|   'auth': { |     auth: { | ||||||
|     'user': 'username', |         user: 'username', | ||||||
|     'pass': 'password', |         pass: 'password', | ||||||
|     'sendImmediately': false |         sendImmediately: false | ||||||
|   } |     } | ||||||
| }); | }); | ||||||
| // or | // or | ||||||
| request.get('http://some.server.com/', { | request.get('http://some.server.com/', { | ||||||
|   'auth': { |     auth: { | ||||||
|     'bearer': 'bearerToken' |         bearer: 'bearerToken' | ||||||
|   } |     } | ||||||
| }); | }); | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| If passed as an option, `auth` should be a hash containing values: | If passed as an option, `auth` should be a hash containing values: | ||||||
| 
 | 
 | ||||||
| - `user` || `username` | -   `user` || `username` | ||||||
| - `pass` || `password` | -   `pass` || `password` | ||||||
| - `bearer` (optional) | -   `bearer` (optional) | ||||||
| 
 | 
 | ||||||
| <!-- | <!-- | ||||||
| - `sendImmediately` (optional) | - `sendImmediately` (optional) | ||||||
| @ -155,8 +280,8 @@ var username = 'username', | |||||||
|     password = 'password', |     password = 'password', | ||||||
|     url = 'http://' + username + ':' + password + '@some.server.com'; |     url = 'http://' + username + ':' + password + '@some.server.com'; | ||||||
| 
 | 
 | ||||||
| request({url: url}, function (error, response, body) { | request({ url: url }, function (error, response, body) { | ||||||
|    // Do more stuff with 'body' here |     // Do more stuff with 'body' here | ||||||
| }); | }); | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| @ -187,18 +312,18 @@ custom `User-Agent` header as well as https. | |||||||
| var request = require('request'); | var request = require('request'); | ||||||
| 
 | 
 | ||||||
| var options = { | var options = { | ||||||
|   url: 'https://api.github.com/repos/request/request', |     url: 'https://api.github.com/repos/request/request', | ||||||
|   headers: { |     headers: { | ||||||
|     'User-Agent': 'request' |         'User-Agent': 'request' | ||||||
|   } |     } | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| function callback(error, response, body) { | function callback(error, response, body) { | ||||||
|   if (!error && response.statusCode == 200) { |     if (!error && response.statusCode == 200) { | ||||||
|     var info = JSON.parse(body); |         var info = JSON.parse(body); | ||||||
|     console.log(info.stargazers_count + " Stars"); |         console.log(info.stargazers_count + ' Stars'); | ||||||
|     console.log(info.forks_count + " Forks"); |         console.log(info.forks_count + ' Forks'); | ||||||
|   } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| request(options, callback); | request(options, callback); | ||||||
| @ -210,11 +335,13 @@ request(options, callback); | |||||||
| 
 | 
 | ||||||
| ## UNIX Domain Sockets | ## UNIX Domain Sockets | ||||||
| 
 | 
 | ||||||
| `urequest` supports making requests to [UNIX Domain Sockets](https://en.wikipedia.org/wiki/Unix_domain_socket). To make one, use the following URL scheme: | `@root/request` supports making requests to [UNIX Domain Sockets](https://en.wikipedia.org/wiki/Unix_domain_socket). To make one, use the following URL scheme: | ||||||
| 
 | 
 | ||||||
| ```js | ```js | ||||||
| /* Pattern */ 'http://unix:SOCKET:PATH' | /* Pattern */ 'http://unix:SOCKET:PATH'; | ||||||
| /* Example */ request.get('http://unix:/absolute/path/to/unix.socket:/request/path') | /* Example */ request.get( | ||||||
|  |     'http://unix:/absolute/path/to/unix.socket:/request/path' | ||||||
|  | ); | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| Note: The `SOCKET` path is assumed to be absolute to the root of the host file system. | Note: The `SOCKET` path is assumed to be absolute to the root of the host file system. | ||||||
| @ -227,9 +354,9 @@ Note: The `SOCKET` path is assumed to be absolute to the root of the host file s | |||||||
| 
 | 
 | ||||||
| The first argument can be either a `url` or an `options` object. The only required option is `uri`; all others are optional. | The first argument can be either a `url` or an `options` object. The only required option is `uri`; all others are optional. | ||||||
| 
 | 
 | ||||||
| - `uri` || `url` - fully qualified uri or a parsed url object from `url.parse()` | -   `uri` || `url` - fully qualified uri or a parsed url object from `url.parse()` | ||||||
| - `method` - http method (default: `"GET"`) | -   `method` - http method (default: `"GET"`) | ||||||
| - `headers` - http headers (default: `{}`) | -   `headers` - http headers (default: `{}`) | ||||||
| 
 | 
 | ||||||
| <!-- TODO | <!-- TODO | ||||||
| - `baseUrl` - fully qualified uri string used as the base url. Most useful with `request.defaults`, for example when you want to do many requests to the same domain. If `baseUrl` is `https://example.com/api/`, then requesting `/end/point?test=true` will fetch `https://example.com/api/end/point?test=true`. When `baseUrl` is given, `uri` must also be a string. | - `baseUrl` - fully qualified uri string used as the base url. Most useful with `request.defaults`, for example when you want to do many requests to the same domain. If `baseUrl` is `https://example.com/api/`, then requesting `/end/point?test=true` will fetch `https://example.com/api/end/point?test=true`. When `baseUrl` is given, `uri` must also be a string. | ||||||
| @ -237,8 +364,8 @@ The first argument can be either a `url` or an `options` object. The only requir | |||||||
| 
 | 
 | ||||||
| --- | --- | ||||||
| 
 | 
 | ||||||
| - `body` - entity body for PATCH, POST and PUT requests. Must be a `Buffer`, `String` or `ReadStream`. If `json` is `true`, then `body` must be a JSON-serializable object. | -   `body` - entity body for PATCH, POST and PUT requests. Must be a `Buffer`, `String` or `ReadStream`. If `json` is `true`, then `body` must be a JSON-serializable object. | ||||||
| - `json` - sets `body` to JSON representation of value and adds `Content-type: application/json` header. Additionally, parses the response body as JSON. | -   `json` - sets `body` to JSON representation of value and adds `Content-type: application/json` header. Additionally, parses the response body as JSON. | ||||||
| 
 | 
 | ||||||
| <!-- TODO | <!-- TODO | ||||||
| - `form` - when passed an object or a querystring, this sets `body` to a querystring representation of value, and adds `Content-type: application/x-www-form-urlencoded` header. When passed no options, a `FormData` instance is returned (and is piped to request). See "Forms" section above. | - `form` - when passed an object or a querystring, this sets `body` to a querystring representation of value, and adds `Content-type: application/x-www-form-urlencoded` header. When passed no options, a `FormData` instance is returned (and is piped to request). See "Forms" section above. | ||||||
| @ -259,15 +386,15 @@ The first argument can be either a `url` or an `options` object. The only requir | |||||||
| 
 | 
 | ||||||
| --- | --- | ||||||
| 
 | 
 | ||||||
| - `followRedirect` - follow HTTP 3xx responses as redirects (default: `true`). This property can also be implemented as function which gets `response` object as a single argument and should return `true` if redirects should continue or `false` otherwise. | -   `followRedirect` - follow HTTP 3xx responses as redirects (default: `true`). This property can also be implemented as function which gets `response` object as a single argument and should return `true` if redirects should continue or `false` otherwise. | ||||||
| - `followAllRedirects` - follow non-GET HTTP 3xx responses as redirects (default: `false`) | -   `followAllRedirects` - follow non-GET HTTP 3xx responses as redirects (default: `false`) | ||||||
| - `followOriginalHttpMethod` - by default we redirect to HTTP method GET. you can enable this property to redirect to the original HTTP method (default: `false`) | -   `followOriginalHttpMethod` - by default we redirect to HTTP method GET. you can enable this property to redirect to the original HTTP method (default: `false`) | ||||||
| - `maxRedirects` - the maximum number of redirects to follow (default: `10`) | -   `maxRedirects` - the maximum number of redirects to follow (default: `10`) | ||||||
| - `removeRefererHeader` - removes the referer header when a redirect happens (default: `false`). **Note:** if true, referer header set in the initial request is preserved during redirect chain. | -   `removeRefererHeader` - removes the referer header when a redirect happens (default: `false`). **Note:** if true, referer header set in the initial request is preserved during redirect chain. | ||||||
| 
 | 
 | ||||||
| --- | --- | ||||||
| 
 | 
 | ||||||
| - `encoding` - encoding to be used on `setEncoding` of response data. If `null`, the `body` is returned as a `Buffer`. Anything else **(including the default value of `undefined`)** will be passed as the [encoding](http://nodejs.org/api/buffer.html#buffer_buffer) parameter to `toString()` (meaning this is effectively `utf8` by default). (**Note:** if you expect binary data, you should set `encoding: null`.) | -   `encoding` - encoding to be used on `setEncoding` of response data. If `null`, the `body` is returned as a `Buffer`. Anything else **(including the default value of `undefined`)** will be passed as the [encoding](http://nodejs.org/api/buffer.html#buffer_buffer) parameter to `toString()` (meaning this is effectively `utf8` by default). (**Note:** if you expect binary data, you should set `encoding: null`.) | ||||||
| 
 | 
 | ||||||
| <!-- TODO | <!-- TODO | ||||||
| - `gzip` - if `true`, add an `Accept-Encoding` header to request compressed content encodings from the server (if not already present) and decode supported content encodings in the response. **Note:** Automatic decoding of the response content is performed on the body data returned through `request` (both through the `request` stream and passed to the callback function) but is not performed on the `response` stream (available from the `response` event) which is the unmodified `http.IncomingMessage` object which may contain compressed data. See example below. | - `gzip` - if `true`, add an `Accept-Encoding` header to request compressed content encodings from the server (if not already present) and decode supported content encodings in the response. **Note:** Automatic decoding of the response content is performed on the body data returned through `request` (both through the `request` stream and passed to the callback function) but is not performed on the `response` stream (available from the `response` event) which is the unmodified `http.IncomingMessage` object which may contain compressed data. See example below. | ||||||
| @ -292,30 +419,31 @@ instead, it **returns a wrapper** that has your default settings applied to it. | |||||||
| `request.defaults` to add/override defaults that were previously defaulted. | `request.defaults` to add/override defaults that were previously defaulted. | ||||||
| 
 | 
 | ||||||
| For example: | For example: | ||||||
|  | 
 | ||||||
| ```js | ```js | ||||||
| //requests using baseRequest() will set the 'x-token' header | //requests using baseRequest() will set the 'x-token' header | ||||||
| var baseRequest = request.defaults({ | var baseRequest = request.defaults({ | ||||||
|   headers: {'x-token': 'my-token'} |     headers: { 'x-token': 'my-token' } | ||||||
| }) | }); | ||||||
| 
 | 
 | ||||||
| //requests using specialRequest() will include the 'x-token' header set in | //requests using specialRequest() will include the 'x-token' header set in | ||||||
| //baseRequest and will also include the 'special' header | //baseRequest and will also include the 'special' header | ||||||
| var specialRequest = baseRequest.defaults({ | var specialRequest = baseRequest.defaults({ | ||||||
|   headers: {special: 'special value'} |     headers: { special: 'special value' } | ||||||
| }) | }); | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| ### request.METHOD() | ### request.METHOD() | ||||||
| 
 | 
 | ||||||
| These HTTP method convenience functions act just like `request()` but with a default method already set for you: | These HTTP method convenience functions act just like `request()` but with a default method already set for you: | ||||||
| 
 | 
 | ||||||
| - *request.get()*: Defaults to `method: "GET"`. | -   _request.get()_: Defaults to `method: "GET"`. | ||||||
| - *request.post()*: Defaults to `method: "POST"`. | -   _request.post()_: Defaults to `method: "POST"`. | ||||||
| - *request.put()*: Defaults to `method: "PUT"`. | -   _request.put()_: Defaults to `method: "PUT"`. | ||||||
| - *request.patch()*: Defaults to `method: "PATCH"`. | -   _request.patch()_: Defaults to `method: "PATCH"`. | ||||||
| - *request.del() / request.delete()*: Defaults to `method: "DELETE"`. | -   _request.del() / request.delete()_: Defaults to `method: "DELETE"`. | ||||||
| - *request.head()*: Defaults to `method: "HEAD"`. | -   _request.head()_: Defaults to `method: "HEAD"`. | ||||||
| - *request.options()*: Defaults to `method: "OPTIONS"`. | -   _request.options()_: Defaults to `method: "OPTIONS"`. | ||||||
| 
 | 
 | ||||||
| --- | --- | ||||||
| 
 | 
 | ||||||
| @ -323,10 +451,10 @@ These HTTP method convenience functions act just like `request()` but with a def | |||||||
| 
 | 
 | ||||||
| There are at least <!--three--> two ways to debug the operation of `request`: | There are at least <!--three--> two ways to debug the operation of `request`: | ||||||
| 
 | 
 | ||||||
| 1. Launch the node process like `NODE_DEBUG=urequest node script.js` | 1. Launch the node process like `NODE_DEBUG=@root/request node script.js` | ||||||
|    (`lib,request,otherlib` works too). |    (`lib,request,otherlib` works too). | ||||||
| 
 | 
 | ||||||
| 2. Set `require('@coolaj86/urequest').debug = true` at any time (this does the same thing | 2. Set `require('@root/request').debug = true` at any time (this does the same thing | ||||||
|    as #1). |    as #1). | ||||||
| 
 | 
 | ||||||
| <!-- TODO | <!-- TODO | ||||||
|  | |||||||
| @ -5,12 +5,15 @@ var request = require('../'); | |||||||
| 
 | 
 | ||||||
| // will redirect to https://www.github.com and then https://github.com
 | // will redirect to https://www.github.com and then https://github.com
 | ||||||
| //request('http://www.github.com', function (error, response, body) {
 | //request('http://www.github.com', function (error, response, body) {
 | ||||||
| request({ uri: { protocol: 'http:', hostname: 'www.github.com' } }, function (error, response, body) { | request( | ||||||
|   if (error) { |     { uri: { protocol: 'http:', hostname: 'www.github.com' } }, | ||||||
|     console.log('error:', error); // Print the error if one occurred
 |     function (error, response, body) { | ||||||
|     return; |         if (error) { | ||||||
|   } |             console.log('error:', error); // Print the error if one occurred
 | ||||||
|   console.log('statusCode:', response.statusCode); // The final statusCode
 |             return; | ||||||
|   console.log('Final href:', response.request.uri.href); // The final URI
 |         } | ||||||
|   console.log('Body Length:', body.length); // body length
 |         console.log('statusCode:', response.statusCode); // The final statusCode
 | ||||||
| }); |         console.log('Final href:', response.request.uri.href); // The final URI
 | ||||||
|  |         console.log('Body Length:', body.length); // body length
 | ||||||
|  |     } | ||||||
|  | ); | ||||||
|  | |||||||
| @ -8,21 +8,24 @@ var request = require('../'); | |||||||
| // will redirect to https://www.github.com and then https://github.com
 | // will redirect to https://www.github.com and then https://github.com
 | ||||||
| //request('http://www.github.com', function (error, response, body) {
 | //request('http://www.github.com', function (error, response, body) {
 | ||||||
| request( | request( | ||||||
|   //{ url: 'http://postb.in/syfxxnko'
 |     //{ url: 'http://postb.in/syfxxnko'
 | ||||||
|   { url: 'http://localhost:3007/form-data/' |     { | ||||||
|   , method: 'POST' |         url: 'http://localhost:3007/form-data/', | ||||||
|   , headers: { 'X-Foo': 'Bar' } |         method: 'POST', | ||||||
|   , formData: { |         headers: { 'X-Foo': 'Bar' }, | ||||||
|       foo: 'bar' |         formData: { | ||||||
|     , baz: require('fs').createReadStream(require('path').join(__dirname, 'get-to-json.js')) |             foo: 'bar', | ||||||
|  |             baz: require('fs').createReadStream( | ||||||
|  |                 require('path').join(__dirname, 'get-to-json.js') | ||||||
|  |             ) | ||||||
|  |         } | ||||||
|  |     }, | ||||||
|  |     function (error, response, body) { | ||||||
|  |         if (error) { | ||||||
|  |             console.log('error:', error); // Print the error if one occurred
 | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |         console.log('statusCode:', response.statusCode); // The final statusCode
 | ||||||
|  |         console.log('Body Length:', body.length); // body length
 | ||||||
|     } |     } | ||||||
|   } |  | ||||||
| , function (error, response, body) { |  | ||||||
|     if (error) { |  | ||||||
|       console.log('error:', error); // Print the error if one occurred
 |  | ||||||
|       return; |  | ||||||
|     } |  | ||||||
|     console.log('statusCode:', response.statusCode); // The final statusCode
 |  | ||||||
|     console.log('Body Length:', body.length); // body length
 |  | ||||||
|   } |  | ||||||
| ); | ); | ||||||
|  | |||||||
| @ -3,10 +3,10 @@ | |||||||
| //var request = require('urequest');
 | //var request = require('urequest');
 | ||||||
| var request = require('../'); | var request = require('../'); | ||||||
| request('https://www.google.com', function (error, response, body) { | request('https://www.google.com', function (error, response, body) { | ||||||
|   if (error) { |     if (error) { | ||||||
|     console.log('error:', error); // Print the error if one occurred
 |         console.log('error:', error); // Print the error if one occurred
 | ||||||
|     return; |         return; | ||||||
|   } |     } | ||||||
|   console.log('response.toJSON()'); |     console.log('response.toJSON()'); | ||||||
|   console.log(response.toJSON()); |     console.log(response.toJSON()); | ||||||
| }); | }); | ||||||
|  | |||||||
| @ -3,7 +3,7 @@ | |||||||
| //var request = require('urequest');
 | //var request = require('urequest');
 | ||||||
| var request = require('../'); | var request = require('../'); | ||||||
| request('http://www.google.com', function (error, response, body) { | request('http://www.google.com', function (error, response, body) { | ||||||
|   console.log('error:', error); // Print the error if one occurred
 |     console.log('error:', error); // Print the error if one occurred
 | ||||||
|   console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
 |     console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
 | ||||||
|   console.log('body:', body); // Print the HTML for the Google homepage.
 |     console.log('body:', body); // Print the HTML for the Google homepage.
 | ||||||
| }); | }); | ||||||
|  | |||||||
| @ -3,7 +3,7 @@ | |||||||
| //var request = require('urequest');
 | //var request = require('urequest');
 | ||||||
| var request = require('../'); | var request = require('../'); | ||||||
| request('https://www.google.com', function (error, response, body) { | request('https://www.google.com', function (error, response, body) { | ||||||
|   console.log('error:', error); // Print the error if one occurred
 |     console.log('error:', error); // Print the error if one occurred
 | ||||||
|   console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
 |     console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
 | ||||||
|   console.log('body:', body); // Print the HTML for the Google homepage.
 |     console.log('body:', body); // Print the HTML for the Google homepage.
 | ||||||
| }); | }); | ||||||
|  | |||||||
| @ -4,13 +4,16 @@ | |||||||
| var request = require('../'); | var request = require('../'); | ||||||
| 
 | 
 | ||||||
| // would normally redirect to https://www.github.com and then https://github.com
 | // would normally redirect to https://www.github.com and then https://github.com
 | ||||||
| request({ uri: 'https://www.github.com', followRedirect: false }, function (error, response, body) { | request( | ||||||
|   if (error) { |     { uri: 'https://www.github.com', followRedirect: false }, | ||||||
|     console.log('error:', error); // Print the error if one occurred
 |     function (error, response, body) { | ||||||
|     return; |         if (error) { | ||||||
|   } |             console.log('error:', error); // Print the error if one occurred
 | ||||||
|   console.log('href:', response.request.uri.href); // The final URI
 |             return; | ||||||
|   console.log('statusCode:', response.statusCode); // Should be 301 or 302
 |         } | ||||||
|   console.log('Location:', response.headers.location); // The redirect
 |         console.log('href:', response.request.uri.href); // The final URI
 | ||||||
|   console.log('Body:', body || JSON.stringify(body)); |         console.log('statusCode:', response.statusCode); // Should be 301 or 302
 | ||||||
| }); |         console.log('Location:', response.headers.location); // The redirect
 | ||||||
|  |         console.log('Body:', body || JSON.stringify(body)); | ||||||
|  |     } | ||||||
|  | ); | ||||||
|  | |||||||
							
								
								
									
										15
									
								
								examples/postbin.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								examples/postbin.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,15 @@ | |||||||
|  | 'use strict'; | ||||||
|  | 
 | ||||||
|  | var request = require('../'); | ||||||
|  | request({ | ||||||
|  |     url: 'https://postb.in/1588134650162-6019286897499?hello=world' | ||||||
|  |     //headers: { 'user-agent': false } // remove
 | ||||||
|  |     //headers: { 'user-agent': 'test/1.0' } // overwrite
 | ||||||
|  |     //userAgent: 'test/1.1' // add to the default
 | ||||||
|  | }) | ||||||
|  |     .then(function (resp) { | ||||||
|  |         console.log(resp.body); | ||||||
|  |     }) | ||||||
|  |     .catch(function (err) { | ||||||
|  |         console.error(err); | ||||||
|  |     }); | ||||||
							
								
								
									
										27
									
								
								examples/stream-to-file.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								examples/stream-to-file.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,27 @@ | |||||||
|  | 'use strict'; | ||||||
|  | 
 | ||||||
|  | var request = require('../'); | ||||||
|  | 
 | ||||||
|  | async function main() { | ||||||
|  |     var tpath = '/tmp/google-index.html'; | ||||||
|  |     var resp = await request({ | ||||||
|  |         url: 'https://google.com', | ||||||
|  |         encoding: null, | ||||||
|  |         stream: tpath | ||||||
|  |     }); | ||||||
|  |     console.log('[Response Headers]'); | ||||||
|  |     console.log(resp.toJSON().headers); | ||||||
|  | 
 | ||||||
|  |     //console.error(resp.headers, resp.body.byteLength);
 | ||||||
|  |     await resp.stream; | ||||||
|  |     console.log('[Response Body] written to', tpath); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | main() | ||||||
|  |     .then(function () { | ||||||
|  |         console.log('Pass'); | ||||||
|  |     }) | ||||||
|  |     .catch(function (e) { | ||||||
|  |         console.error('Fail'); | ||||||
|  |         console.error(e.stack); | ||||||
|  |     }); | ||||||
							
								
								
									
										34
									
								
								examples/stream.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								examples/stream.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,34 @@ | |||||||
|  | 'use strict'; | ||||||
|  | 
 | ||||||
|  | var request = require('../'); | ||||||
|  | 
 | ||||||
|  | async function main() { | ||||||
|  |     var tpath = '/tmp/google-index.html'; | ||||||
|  |     var resp = await request({ | ||||||
|  |         url: 'https://google.com', | ||||||
|  |         encoding: null, | ||||||
|  |         stream: true | ||||||
|  |     }); | ||||||
|  |     console.log('[Response Headers]'); | ||||||
|  |     console.log(resp.toJSON().headers); | ||||||
|  | 
 | ||||||
|  |     resp.on('data', function (chunk) { | ||||||
|  | 	    console.log('[Data]', chunk.byteLength); | ||||||
|  |     }); | ||||||
|  |     resp.on('end', function (chunk) { | ||||||
|  | 	    console.log('[End]'); | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     //console.error(resp.headers, resp.body.byteLength);
 | ||||||
|  |     await resp.stream; | ||||||
|  |     console.log('[Close]'); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | main() | ||||||
|  |     .then(function () { | ||||||
|  |         console.log('Pass'); | ||||||
|  |     }) | ||||||
|  |     .catch(function (e) { | ||||||
|  |         console.error('Fail'); | ||||||
|  |         console.error(e.stack); | ||||||
|  |     }); | ||||||
| @ -8,18 +8,19 @@ var request = require('../'); | |||||||
| // will redirect to https://www.github.com and then https://github.com
 | // will redirect to https://www.github.com and then https://github.com
 | ||||||
| //request('http://www.github.com', function (error, response, body) {
 | //request('http://www.github.com', function (error, response, body) {
 | ||||||
| request( | request( | ||||||
|   { url: 'http://postb.in/2meyt50C' |     { | ||||||
|   , method: 'POST' |         url: 'http://postb.in/2meyt50C', | ||||||
|   , headers: { 'X-Foo': 'Bar' } |         method: 'POST', | ||||||
|   , form: { foo: 'bar', baz: 'qux' } |         headers: { 'X-Foo': 'Bar' }, | ||||||
|   } |         form: { foo: 'bar', baz: 'qux' } | ||||||
| , function (error, response, body) { |     }, | ||||||
|     if (error) { |     function (error, response, body) { | ||||||
|       console.log('error:', error); // Print the error if one occurred
 |         if (error) { | ||||||
|       return; |             console.log('error:', error); // Print the error if one occurred
 | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |         console.log('statusCode:', response.statusCode); // The final statusCode
 | ||||||
|  |         console.log('Body Length:', body.length); // body length
 | ||||||
|  |         console.log('Response:', response.toJSON()); // body length
 | ||||||
|     } |     } | ||||||
|     console.log('statusCode:', response.statusCode); // The final statusCode
 |  | ||||||
|     console.log('Body Length:', body.length); // body length
 |  | ||||||
|     console.log('Response:', response.toJSON()); // body length
 |  | ||||||
|   } |  | ||||||
| ); | ); | ||||||
|  | |||||||
							
								
								
									
										5
									
								
								package-lock.json
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								package-lock.json
									
									
									
										generated
									
									
									
										Normal file
									
								
							| @ -0,0 +1,5 @@ | |||||||
|  | { | ||||||
|  |     "name": "@root/request", | ||||||
|  |     "version": "1.8.2", | ||||||
|  |     "lockfileVersion": 1 | ||||||
|  | } | ||||||
							
								
								
									
										54
									
								
								package.json
									
									
									
									
									
								
							
							
						
						
									
										54
									
								
								package.json
									
									
									
									
									
								
							| @ -1,29 +1,29 @@ | |||||||
| { | { | ||||||
|   "name": "@coolaj86/urequest", |     "name": "@root/request", | ||||||
|   "version": "1.3.6", |     "version": "1.8.2", | ||||||
|   "description": "A lightweight drop-in replacement for request", |     "description": "A lightweight, zero-dependency drop-in replacement for request", | ||||||
|   "main": "index.js", |     "main": "index.js", | ||||||
|   "files": [ |     "files": [ | ||||||
|     "lib" |         "lib" | ||||||
|   ], |     ], | ||||||
|   "directories": { |     "directories": { | ||||||
|     "example": "examples" |         "example": "examples" | ||||||
|   }, |     }, | ||||||
|   "scripts": { |     "scripts": { | ||||||
|     "test": "echo \"Error: no test specified\" && exit 1" |         "test": "echo \"Error: no test specified\" && exit 1" | ||||||
|   }, |     }, | ||||||
|   "repository": { |     "repository": { | ||||||
|     "type": "git", |         "type": "git", | ||||||
|     "url": "https://git.ppl.family/ppl/urequest.js.git" |         "url": "https://git.rootprojects.org/root/request.js.git" | ||||||
|   }, |     }, | ||||||
|   "keywords": [ |     "keywords": [ | ||||||
|     "request", |         "request", | ||||||
|     "lightweight", |         "lightweight", | ||||||
|     "alternative", |         "alternative", | ||||||
|     "http", |         "http", | ||||||
|     "https", |         "https", | ||||||
|     "call" |         "call" | ||||||
|   ], |     ], | ||||||
|   "author": "AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com/)", |     "author": "AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com/)", | ||||||
|   "license": "(MIT OR Apache-2.0)" |     "license": "(MIT OR Apache-2.0)" | ||||||
| } | } | ||||||
|  | |||||||
| @ -2,10 +2,10 @@ | |||||||
| 
 | 
 | ||||||
| var net = require('net'); | var net = require('net'); | ||||||
| var server = net.createServer(function (socket) { | var server = net.createServer(function (socket) { | ||||||
|   socket.on('data', function (chunk) { |     socket.on('data', function (chunk) { | ||||||
|     console.info(chunk.toString('utf8')); |         console.info(chunk.toString('utf8')); | ||||||
|   }); |     }); | ||||||
| }) | }); | ||||||
| server.listen(3007, function () { | server.listen(3007, function () { | ||||||
|   console.info("Listening on", this.address()); |     console.info('Listening on', this.address()); | ||||||
| }); | }); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user