From aa9fbd93254cdc199521b7fd4d670fa3e77bf676 Mon Sep 17 00:00:00 2001 From: John Wright Date: Fri, 4 Dec 2015 10:59:07 +0000 Subject: [PATCH] Updated packages. --- Gruntfile.js | 8 +- README.md | 72 +++++++++++--- package.json | 20 ++-- test/fixtures/basic.html | 193 +++++++++++++++++++++++++++++++++++- test/fixtures/callback.body | 2 +- test/http_test.js | 13 ++- 6 files changed, 268 insertions(+), 40 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 9175320..fabc32d 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -37,19 +37,19 @@ module.exports = function(grunt) { http: { basic: { options: { - url: 'http://www.j-g-w.info' + url: 'http://blog.j-g-w.info' }, dest: 'tmp/basic.html' }, justLog: { options: { - url: 'http://www.j-g-w.info', + url: 'http://blog.j-g-w.info', logBody: true } }, noSaveOrLog: { options: { - url: 'http://www.j-g-w.info' + url: 'http://blog.j-g-w.info' } }, closure: { @@ -104,7 +104,7 @@ module.exports = function(grunt) { }, callback: { options: { - url: 'http://www.j-g-w.info', + url: 'http://blog.j-g-w.info', callback: function (error, response, body) { grunt.file.write('tmp/callback.error', util.inspect(error)); grunt.file.write('tmp/callback.response', util.inspect(response)); diff --git a/README.md b/README.md index f8e3365..537099f 100644 --- a/README.md +++ b/README.md @@ -50,32 +50,75 @@ grunt-http uses the [request](https://github.com/mikeal/request) module under th - `qs` - object containing querystring values to be appended to the URI - `method` - http method, defaults to GET - `headers` - http headers, defaults to {} -- `body` - entity body for PATCH, POST and PUT requests. Must be buffer or string or a function returning a string or buffer. + +--- +- `qs` - object containing querystring values to be appended to the uri +- `qsParseOptions` - object containing options to pass to the [qs.parse](https://github.com/hapijs/qs#parsing-objects) method. Alternatively pass options to the [querystring.parse](https://nodejs.org/docs/v0.12.0/api/querystring.html#querystring_querystring_parse_str_sep_eq_options) method using this format {sep:';', eq:':', options:{}} +- `qsStringifyOptions` - object containing options to pass to the [qs.stringify](https://github.com/hapijs/qs#stringifying) method. Alternatively pass options to the [querystring.stringify](https://nodejs.org/docs/v0.12.0/api/querystring.html#querystring_querystring_stringify_obj_sep_eq_options) method using this format {sep:';', eq:':', options:{}}. For example, to change the way arrays are converted to query strings using the qs module pass the arrayFormat option with one of indices|brackets|repeat +- `useQuerystring` - If true, use querystring to stringify and parse querystrings, otherwise use qs (default: false). Set this option to true if you need arrays to be serialized as foo=bar&foo=baz instead of the default foo[0]=bar&foo[1]=baz. + +--- + +- `body` - entity body for PATCH, POST and PUT requests. Must be a Buffer or String, unless json is true. If json is true, then body must be a JSON-serializable object. - `sourceField` - A field in the body or form to add the source files' contents to. Can contain full stops to separate object path. IE "form.js\_code". - `form` - When passed an object, this sets body to a querystring representation of value, and adds Content-type: application/x-www-form-urlencoded; charset=utf-8 header. When passed no options, a FormData instance is returned (and is piped to request). For `multipart/form-data` install the optional dependency `npm i form-data`. -- `auth` - A hash containing values user || username, password || pass, and sendImmediately (optional). [See more info here](https://github.com/mikeal/request#http-authentication). +- `formData` - Data to pass for a multipart/form-data +- `multipart` - array of objects which contain their own headers and body attributes. Sends a multipart/related request. + - Alternatively you can pass in an object `{chunked: false, data: []}` where chunked is used to specify whether the request is sent in [chunked transfer encoding](https://en.wikipedia.org/wiki/Chunked_transfer_encoding) In non-chunked requests, data items with body streams are not allowed. +- `reambleCRLF` - append a newline/CRLF before the boundary of your multipart/form-data request. +- `postambleCRLF` - append a newline/CRLF at the end of the boundary of your multipart/form-data request. - `json` - sets body but to JSON representation of value and adds Content-type: application/json header. Additionally, parses the response body as json. Must be buffer or string or a function returning a string or buffer. -- `multipart` - (experimental) array of objects which contains their own headers and body attribute. Sends multipart/related request. See example below. +- `jsonReviver` - a [reviver function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse) that will be passed to JSON.parse() when parsing a JSON response body. + +--- + +- `auth` - A hash containing values user || username, password || pass, and sendImmediately (optional). [See more info here](https://github.com/mikeal/request#http-authentication). +- `oauth` - Options for OAuth HMAC-SHA1 signing. [See more info here](https://github.com/mikeal/request#oauth-signing). The `oauth-sign` module must be installed to use this functionality. +- `hawk` - Options for [Hawk signing](https://github.com/hueniverse/hawk). The credentials key must contain the necessary signing info, [see hawk docs for details](https://github.com/hueniverse/hawk#usage-example). You will need to install the `hawk` module to use this functionality. +- `aws` - object containing AWS signing information. Should have the properties key, secret. Also requires the property bucket, unless you’re specifying your bucket as part of the path, or the request doesn’t use a bucket (i.e. GET Services) +- `httpSignature` - Options for the [HTTP Signature Scheme](https://github.com/joyent/node-http-signature/blob/master/http_signing.md) using [Joyent's library](https://github.com/joyent/node-http-signature). The `http-signature` module must be installed and the keyId and key properties must be specified. + +--- + - `followRedirect` - follow HTTP 3xx responses as redirects. defaults to true. - `followAllRedirects` - follow non-GET HTTP 3xx responses as redirects. defaults to false. - `maxRedirects` - the maximum number of redirects to follow, defaults to 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. + +--- + - `encoding` - Encoding to be used on setEncoding of response data. If set to null, the body is returned as a Buffer. -- `pool` - A hash object containing the agents for these requests. If omitted this request will use the global pool which is set to node's default maxSockets. -- `pool.maxSockets` - Integer containing the maximum amount of sockets in the pool. +- `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. +- `jar` - If true, remember cookies for future use (or define your custom cookie jar; [see mikeal/request's examples](https://github.com/mikeal/request#examples)). To get either of these functions working you'll need to install an optional dependecy `npm i tough-cookie`. + +--- + +- `agent` - http(s).Agent instance to use +- `agentClass` - alternatively specify your agent's class name +- `agentOptions` - and pass its options. Note: for HTTPS see [tls API doc for TLS/SSL options](http://nodejs.org/api/tls.html#tls_tls_connect_options_callback) and the [request.js docs](https://github.com/request/request#using-optionsagentoptions) +- `pool` - An object describing which agents to use for the request. If this option is omitted the request will use the global agent (as long as your options allow for it). Otherwise, request will search the pool for your custom agent. If no custom agent is found, a new agent will be created and added to the pool. Note: pool is used only when the agent option is not specified. + - A maxSockets property can also be provided on the pool object to set the max number of sockets for all agents created (ex: pool: {maxSockets: Infinity}). + - Note that if you are sending multiple requests in a loop and creating multiple new pool objects, maxSockets will not work as intended. To work around this, either use request.defaults with your pool options or create the pool object with the maxSockets property outside of the loop. - `timeout` - Integer containing the number of milliseconds to wait for a request to respond before aborting the request + +--- + +- `localAddress` - Local interface to bind for network connections. - `proxy` - An HTTP proxy to be used. Support proxy Auth with Basic Auth the same way it's supported with the url parameter by embedding the auth info in the uri. -- `oauth` - Options for OAuth HMAC-SHA1 signing. [See more info here](https://github.com/mikeal/request#oauth-signing). The `oauth-sign` module must be installed to use this functionality. -- `hawk` - Options for [Hawk signing](https://github.com/hueniverse/hawk). The credentials key must contain the necessary signing info, [see hawk docs for details](https://github.com/hueniverse/hawk#usage-example). You will need to install the `hawk` module to use this functionality. - `strictSSL` - Set to true to require that SSL certificates be valid. Note: to use your own certificate authority, you need to specify an agent that was created with that ca as an option. -- `jar` - If true, remember cookies for future use (or define your custom cookie jar; [see mikeal/request's examples](https://github.com/mikeal/request#examples)). To get either of these functions working you'll need to install an optional dependecy `npm i tough-cookie`. -- `aws` - object containing aws signing information, should have the properties key and secret as well as bucket unless you're specifying your bucket as part of the path, or you are making a request that doesn't use a bucket (i.e. GET Services). You will need to install the `aws-sign2` module to use this functionality. -- `httpSignature` - Options for the [HTTP Signature Scheme](https://github.com/joyent/node-http-signature/blob/master/http_signing.md) using [Joyent's library](https://github.com/joyent/node-http-signature). The `http-signature` module must be installed and the keyId and key properties must be specified. -- `localAddress` - Local interface to bind for network connections. -- `ignoreErrors` - Ignore the status code returned (if any). -- `logBody` - Outputs the response body in the logs. This can also be set at runtime by using --logBody=true on the command. - +- `tunnel` - controls the behavior of [HTTP CONNECT tunneling](https://en.wikipedia.org/wiki/HTTP_tunnel#HTTP_CONNECT_tunneling) as follows: + - `undefined` (default) - true if the destination is https, false otherwise + - `true` - always tunnel to the destination by making a CONNECT request to the proxy + - `false` - request the destination as a GET request. +- `proxyHeaderWhiteList` - A whitelist of headers to send to a tunneling proxy. +- `proxyHeaderExclusiveList` - A whitelist of headers to send exclusively to a tunneling proxy and not to destination. There are a few optional dependencies you'll need to install to get certain functionality from this module. +--- + +- `time` - If true, the request-response cycle (including all redirects) is timed at millisecond resolution, and the result provided on the response's elapsedTime property. +- `har` - A [HAR 1.2 Request Object](http://www.softwareishard.com/blog/har-12-spec/#request), will be processed from HAR format into options overwriting matching values (see the [HAR 1.2 section](https://github.com/request/request#support-for-har-1.2) for details) + - if you wish to use cookies (`jar`) install `tough-cookie` - if you want to pass `multipart/form-data` you'll need to install `form-data` - if you wish to tunnel your requests install `tunnel-agent` @@ -164,4 +207,3 @@ With the above configuration you can call all 3 services with one command `grunt In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/). ## [Release History](/johngeorgewright/grunt-http/releases) - diff --git a/package.json b/package.json index c80db0d..6084d12 100644 --- a/package.json +++ b/package.json @@ -30,10 +30,10 @@ "devDependencies": { "form-data": "^0.1.2", "grunt": "~0.4.1", - "grunt-contrib-clean": "~0.6.0", - "grunt-contrib-jshint": "~0.10.0", + "grunt-contrib-clean": "~0.7.0", + "grunt-contrib-jshint": "~0.11.3", "grunt-contrib-nodeunit": "~0.4.1", - "sinon": "~1.10.3" + "sinon": "~1.17.2" }, "peerDependencies": { "grunt": "~0.4.1" @@ -44,16 +44,16 @@ "http" ], "dependencies": { - "async": "^0.9.0", - "request": "~2.47.0" + "async": "^1.5.0", + "request": "~2.67.0" }, "optionalDependencies": { "tough-cookie": ">=0.12.0", - "form-data": "~0.1.0", + "form-data": "~1.0.0-rc3", "tunnel-agent": "~0.4.0", - "http-signature": "~0.10.0", - "oauth-sign": "~0.4.0", - "hawk": "~2.3.0", - "aws-sign2": "~0.5.0" + "http-signature": "~1.1.0", + "oauth-sign": "~0.8.0", + "hawk": "~4.0.0", + "aws-sign2": "~0.6.0" } } diff --git a/test/fixtures/basic.html b/test/fixtures/basic.html index 73f643b..d5aa9d5 100644 --- a/test/fixtures/basic.html +++ b/test/fixtures/basic.html @@ -1,3 +1,190 @@ -John Wright | Web Developer | SEO Webmaster | UX Designer
Wee Mee

Web Developer

Specialising in profitable, commercial and communication solutions for you unique business requirements.

Hi there,

My name is John Wright and I'm a freelance Web Developer. I've had over 5 years experience with web sites large and small. I'm senior in both backend and frontend development and I'm highly skilled in search engine optimisation helping you get the customers to your site.

If you'd like to hire me, have any enquiries or just fancy a chat, please don't hesitate to contact me

\ No newline at end of file + + + + + + + JGW + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ +
+
+

JGW

+

Developer Blurb

+
+
+ +
+ +
+ +
+ +
+ + +
+
+

GPG for the simple

+
+
+

I found myself trying to explain how GPG (GnuPG) works and saw the enquisitive almost instantly glaze over at the mention of encryption and private/public »

+
+ +
+ + + + + + +
+ + +
+ +
Proudly published with Ghost
+
+ +
+ + + + + + + + + + + + + + + diff --git a/test/fixtures/callback.body b/test/fixtures/callback.body index 7ba88bc..f1ad6f3 100644 --- a/test/fixtures/callback.body +++ b/test/fixtures/callback.body @@ -1 +1 @@ -'John Wright | Web Developer | SEO Webmaster | UX Designer
Wee Mee

Web Developer

Specialising in profitable, commercial and communication solutions for you unique business requirements.

Hi there,

My name is John Wright and I\'m a freelance Web Developer. I\'ve had over 5 years experience with web sites large and small. I\'m senior in both backend and frontend development and I\'m highly skilled in search engine optimisation helping you get the customers to your site.

If you\'d like to hire me, have any enquiries or just fancy a chat, please don\'t hesitate to contact me

' \ No newline at end of file +'\n\n\n \n \n\n JGW\n \n\n \n \n\n \n\n \n \n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n \n \n \n\n\n\n \n\n\n\n
\n\n \n
\n \n
\n
\n

JGW

\n

Developer Blurb

\n
\n
\n \n
\n\n
\n\n
\n \n
\n\n\n
\n
\n

GPG for the simple

\n
\n
\n

I found myself trying to explain how GPG (GnuPG) works and saw the enquisitive almost instantly glaze over at the mention of encryption and private/public »

\n
\n \n
\n\n
\n
\n

CoffeeScript OO Templating

\n
\n
\n

Templating in CoffeeScript is fun. There is already CoffeeKup which is fantastic. But unlike Jade, there\'s still no sign of template inheritance. I was first inspired »

\n
\n \n
\n\n\n\n\n
\n\n\n
\n \n
Proudly published with Ghost
\n
\n\n
\n\n \n\n\n\n\n\n\n\n\n \n \n\n\n\n' diff --git a/test/http_test.js b/test/http_test.js index 8dd30be..9791269 100644 --- a/test/http_test.js +++ b/test/http_test.js @@ -7,8 +7,8 @@ exports.http = { 'it can fetch something just using a destination': function (test) { test.expect(1); test.equal( - grunt.file.read('tmp/basic.html'), - grunt.file.read('test/fixtures/basic.html'), + grunt.file.read('tmp/basic.html').replace(/\s+/g, ''), + grunt.file.read('test/fixtures/basic.html').replace(/\s+/g, ''), 'different content to what\'s been downloaded' ); test.done(); @@ -17,8 +17,8 @@ exports.http = { 'it should have downloaded compiled code from the closure service': function (test) { test.expect(1); test.equal( - grunt.file.read('tmp/compiled.js'), - grunt.file.read('test/fixtures/compiled.js'), + grunt.file.read('tmp/compiled.js').trim(), + grunt.file.read('test/fixtures/compiled.js').trim(), 'different content to what\'s been downloaded' ); test.done(); @@ -36,8 +36,8 @@ exports.http = { test.expect(2); ['error', 'body'].forEach(function (part) { test.equal( - grunt.file.read('tmp/callback.' + part), - grunt.file.read('test/fixtures/callback.' + part) + grunt.file.read('tmp/callback.' + part).trim(), + grunt.file.read('test/fixtures/callback.' + part).trim() ); }); test.done(); @@ -60,4 +60,3 @@ exports.http = { } }; -