vulcan 0.6.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/vulcan/cli.rb +20 -10
- data/lib/vulcan/version.rb +1 -1
- data/server/Procfile +1 -1
- data/server/bin/web +10 -0
- data/server/lib/cloudant.coffee +20 -0
- data/server/lib/logger.coffee +17 -0
- data/server/lib/on.coffee +10 -0
- data/server/lib/spawner.coffee +65 -0
- data/server/node_modules/coffee-script/CNAME +1 -0
- data/server/node_modules/coffee-script/LICENSE +22 -0
- data/server/node_modules/coffee-script/README +51 -0
- data/server/node_modules/coffee-script/Rakefile +78 -0
- data/server/node_modules/coffee-script/bin/cake +7 -0
- data/server/node_modules/coffee-script/bin/coffee +7 -0
- data/server/node_modules/coffee-script/extras/jsl.conf +44 -0
- data/server/node_modules/coffee-script/lib/coffee-script/browser.js +92 -0
- data/server/node_modules/coffee-script/lib/coffee-script/cake.js +111 -0
- data/server/node_modules/coffee-script/lib/coffee-script/coffee-script.js +167 -0
- data/server/node_modules/coffee-script/lib/coffee-script/command.js +500 -0
- data/server/node_modules/coffee-script/lib/coffee-script/grammar.js +606 -0
- data/server/node_modules/coffee-script/lib/coffee-script/helpers.js +77 -0
- data/server/node_modules/coffee-script/lib/coffee-script/index.js +11 -0
- data/server/node_modules/coffee-script/lib/coffee-script/lexer.js +788 -0
- data/server/node_modules/coffee-script/lib/coffee-script/nodes.js +2986 -0
- data/server/node_modules/coffee-script/lib/coffee-script/optparse.js +138 -0
- data/server/node_modules/coffee-script/lib/coffee-script/parser.js +683 -0
- data/server/node_modules/coffee-script/lib/coffee-script/repl.js +261 -0
- data/server/node_modules/coffee-script/lib/coffee-script/rewriter.js +349 -0
- data/server/node_modules/coffee-script/lib/coffee-script/scope.js +146 -0
- data/server/node_modules/coffee-script/package.json +55 -0
- data/server/node_modules/connect-form/History.md +0 -6
- data/server/node_modules/connect-form/lib/connect-form.js +2 -4
- data/server/node_modules/connect-form/node_modules/formidable/Readme.md +64 -36
- data/server/node_modules/connect-form/node_modules/formidable/lib/incoming_form.js +5 -1
- data/server/node_modules/connect-form/node_modules/formidable/package.json +20 -6
- data/server/node_modules/connect-form/node_modules/formidable/test/common.js +5 -6
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/file/funkyfilename.txt +1 -0
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/js/special-chars-in-filename.js +1 -1
- data/server/node_modules/connect-form/node_modules/formidable/test/{slow → integration}/test-fixtures.js +38 -33
- data/server/node_modules/connect-form/node_modules/formidable/test/legacy/simple/test-incoming-form.js +11 -0
- data/server/node_modules/connect-form/node_modules/formidable/test/run.js +1 -6
- data/server/node_modules/connect-form/node_modules/formidable/test/unit/test-incoming-form.js +63 -0
- data/server/node_modules/connect-form/package.json +27 -5
- data/server/node_modules/cradle/README.md +10 -10
- data/server/node_modules/cradle/lib/cradle.js +117 -523
- data/server/node_modules/cradle/lib/cradle/database/attachments.js +120 -0
- data/server/node_modules/cradle/lib/cradle/database/changes.js +56 -0
- data/server/node_modules/cradle/lib/cradle/database/documents.js +215 -0
- data/server/node_modules/cradle/lib/cradle/database/index.js +65 -0
- data/server/node_modules/cradle/lib/cradle/database/views.js +125 -0
- data/server/node_modules/cradle/node_modules/follow/LICENSE +202 -0
- data/server/node_modules/cradle/node_modules/follow/README.md +164 -0
- data/server/node_modules/cradle/node_modules/follow/Rakefile +54 -0
- data/server/node_modules/cradle/node_modules/follow/api.js +35 -0
- data/server/node_modules/cradle/node_modules/follow/browser/eventemitter2.js +453 -0
- data/server/node_modules/cradle/node_modules/follow/browser/export.js +78 -0
- data/server/node_modules/cradle/node_modules/follow/browser/index.html +14 -0
- data/server/node_modules/cradle/node_modules/follow/browser/jquery-1.6.1.min.js +18 -0
- data/server/node_modules/cradle/node_modules/follow/browser/log4js.js +46 -0
- data/server/node_modules/cradle/node_modules/follow/browser/main.js +92 -0
- data/server/node_modules/cradle/node_modules/follow/browser/querystring.js +28 -0
- data/server/node_modules/cradle/node_modules/follow/browser/request.jquery.js +237 -0
- data/server/node_modules/cradle/node_modules/follow/browser/require.js +33 -0
- data/server/node_modules/cradle/node_modules/follow/browser/util.js +28 -0
- data/server/node_modules/cradle/node_modules/follow/cli.js +101 -0
- data/server/node_modules/cradle/node_modules/follow/lib/feed.js +556 -0
- data/server/node_modules/cradle/node_modules/follow/lib/index.js +66 -0
- data/server/node_modules/cradle/node_modules/follow/lib/stream.js +305 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/LICENSE +55 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/README.md +285 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/main.js +618 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/mimetypes.js +146 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/oauth.js +34 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/package.json +42 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/googledoodle.png +0 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/run.sh +6 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/server.js +57 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/test-body.js +90 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/test-cookie.js +29 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/test-cookiejar.js +90 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/test-errors.js +30 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/test-oauth.js +109 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/test-pipes.js +167 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/test-proxy.js +39 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/test-timeout.js +87 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/uuid.js +19 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/vendor/cookie/index.js +55 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/vendor/cookie/jar.js +72 -0
- data/server/node_modules/cradle/node_modules/follow/package.json +45 -0
- data/server/node_modules/cradle/node_modules/follow/test/couch.js +153 -0
- data/server/node_modules/cradle/node_modules/follow/test/follow.js +136 -0
- data/server/node_modules/cradle/node_modules/follow/test/issues.js +178 -0
- data/server/node_modules/cradle/node_modules/follow/test/issues/10.js +24 -0
- data/server/node_modules/cradle/node_modules/follow/test/stream.js +493 -0
- data/server/node_modules/cradle/node_modules/request/LICENSE +55 -0
- data/server/node_modules/cradle/node_modules/request/README.md +287 -0
- data/server/node_modules/cradle/node_modules/request/forever.js +103 -0
- data/server/node_modules/cradle/node_modules/request/main.js +913 -0
- data/server/node_modules/cradle/node_modules/request/mimetypes.js +152 -0
- data/server/node_modules/cradle/node_modules/request/oauth.js +34 -0
- data/server/node_modules/cradle/node_modules/request/package.json +42 -0
- data/server/node_modules/cradle/node_modules/request/tests/googledoodle.png +0 -0
- data/server/node_modules/cradle/node_modules/request/tests/run.js +38 -0
- data/server/node_modules/cradle/node_modules/request/tests/server.js +82 -0
- data/server/node_modules/cradle/node_modules/request/tests/squid.conf +77 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/ca.cnf +20 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/ca.crl +0 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/ca.crt +17 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/ca.csr +13 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/ca.key +18 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/ca.srl +1 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/server.cnf +19 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/server.crt +16 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/server.csr +11 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/server.js +28 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/server.key +9 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/npm-ca.crt +16 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/test.crt +15 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/test.key +15 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-body.js +95 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-cookie.js +29 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-cookiejar.js +90 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-defaults.js +68 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-errors.js +37 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-headers.js +52 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-httpModule.js +94 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-https-strict.js +97 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-https.js +86 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-oauth.js +117 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-params.js +92 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-pipes.js +202 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-proxy.js +39 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-qs.js +28 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-redirect.js +154 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-timeout.js +87 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-toJSON.js +14 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-tunnel.js +61 -0
- data/server/node_modules/cradle/node_modules/request/tunnel.js +229 -0
- data/server/node_modules/cradle/node_modules/request/uuid.js +19 -0
- data/server/node_modules/cradle/node_modules/request/vendor/cookie/index.js +65 -0
- data/server/node_modules/cradle/node_modules/request/vendor/cookie/jar.js +72 -0
- data/server/node_modules/cradle/node_modules/vargs/package.json +33 -10
- data/server/node_modules/cradle/package.json +50 -12
- data/server/node_modules/cradle/test/cache-test.js +1 -4
- data/server/node_modules/cradle/test/connection-test.js +179 -0
- data/server/node_modules/cradle/test/database-attachment-test.js +344 -0
- data/server/node_modules/cradle/test/database-cache-test.js +132 -0
- data/server/node_modules/cradle/test/database-test.js +219 -0
- data/server/node_modules/cradle/test/database-view-test.js +141 -0
- data/server/node_modules/cradle/test/fixtures/databases.json +28 -1
- data/server/node_modules/cradle/test/helpers/seed.js +14 -5
- data/server/node_modules/cradle/test/response-test.js +1 -1
- data/server/node_modules/express/History.md +16 -0
- data/server/node_modules/express/bin/express +7 -6
- data/server/node_modules/express/lib-cov/application.js +510 -0
- data/server/node_modules/express/lib-cov/express.js +65 -0
- data/server/node_modules/express/lib-cov/middleware.js +54 -0
- data/server/node_modules/express/lib-cov/request.js +225 -0
- data/server/node_modules/express/lib-cov/response.js +611 -0
- data/server/node_modules/express/lib-cov/router/collection.js +40 -0
- data/server/node_modules/express/lib-cov/router/index.js +515 -0
- data/server/node_modules/express/lib-cov/router/methods.js +9 -0
- data/server/node_modules/express/lib-cov/router/route.js +68 -0
- data/server/node_modules/express/lib-cov/utils.js +151 -0
- data/server/node_modules/express/lib-cov/view.js +81 -0
- data/server/node_modules/express/lib/express.js +1 -1
- data/server/node_modules/express/lib/http.js +1 -2
- data/server/node_modules/express/lib/request.js +2 -2
- data/server/node_modules/express/lib/router/methods.js +10 -1
- data/server/node_modules/express/node_modules/connect/lib/connect.js +1 -1
- data/server/node_modules/express/node_modules/connect/lib/http.js +3 -2
- data/server/node_modules/express/node_modules/connect/lib/middleware/limit.js +0 -2
- data/server/node_modules/express/node_modules/connect/lib/middleware/session.js +1 -2
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/Readme.md +42 -25
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/lib/incoming_form.js +1 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/package.json +14 -3
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/legacy/simple/test-incoming-form.js +11 -0
- data/server/node_modules/express/node_modules/connect/package.json +35 -7
- data/server/node_modules/express/node_modules/mime/package.json +30 -8
- data/server/node_modules/express/node_modules/mkdirp/README.markdown +35 -2
- data/server/node_modules/express/node_modules/mkdirp/examples/pow.js +1 -1
- data/server/node_modules/express/node_modules/mkdirp/index.js +72 -13
- data/server/node_modules/express/node_modules/mkdirp/package.json +39 -21
- data/server/node_modules/express/node_modules/mkdirp/test/chmod.js +38 -0
- data/server/node_modules/express/node_modules/mkdirp/test/clobber.js +37 -0
- data/server/node_modules/express/node_modules/mkdirp/test/perm.js +32 -0
- data/server/node_modules/express/node_modules/mkdirp/test/perm_sync.js +39 -0
- data/server/node_modules/express/node_modules/mkdirp/test/sync.js +27 -0
- data/server/node_modules/express/node_modules/mkdirp/test/umask.js +28 -0
- data/server/node_modules/express/node_modules/mkdirp/test/umask_sync.js +27 -0
- data/server/node_modules/express/node_modules/qs/History.md +10 -0
- data/server/node_modules/express/node_modules/qs/Readme.md +9 -2
- data/server/node_modules/express/node_modules/qs/examples.js +3 -0
- data/server/node_modules/express/node_modules/qs/lib/querystring.js +8 -6
- data/server/node_modules/express/node_modules/qs/package.json +26 -8
- data/server/node_modules/express/node_modules/qs/test/parse.js +13 -1
- data/server/node_modules/express/node_modules/qs/test/stringify.js +45 -37
- data/server/node_modules/express/package.json +55 -16
- data/server/node_modules/express/test.js +41 -0
- data/server/node_modules/knox/package.json +26 -4
- data/server/node_modules/node-uuid/package.json +40 -11
- data/server/node_modules/node-uuid/test/test.js +1 -1
- data/server/node_modules/nodemon/README.md +120 -0
- data/server/node_modules/nodemon/nodemon.js +518 -0
- data/server/node_modules/nodemon/nodemonignore.example +11 -0
- data/server/node_modules/nodemon/package.json +49 -0
- data/server/node_modules/restler/README.md +144 -94
- data/server/node_modules/restler/lib/multipartform.js +2 -0
- data/server/node_modules/restler/lib/restler.js +218 -61
- data/server/node_modules/restler/package.json +35 -8
- data/server/node_modules/restler/test/all.js +6 -1
- data/server/node_modules/restler/test/restler.js +624 -118
- data/server/package.json +14 -10
- data/server/web.coffee +64 -0
- data/server/web.js +15 -3
- metadata +170 -57
- data/server/index.js +0 -14
- data/server/node_modules/connect-form/LICENSE +0 -22
- data/server/node_modules/connect-form/index.js +0 -100
- data/server/node_modules/connect-form/node_modules/formidable/test/fast/test-incoming-form.js +0 -45
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/no-filename/generic.http +0 -13
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/special-chars-in-filename/osx-chrome-13.http +0 -26
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/special-chars-in-filename/osx-firefox-3.6.http +0 -24
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/special-chars-in-filename/osx-safari-5.http +0 -23
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-chrome-12.http +0 -24
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-ie-7.http +0 -22
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-ie-8.http +0 -22
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-safari-5.http +0 -22
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/multi_video.upload +0 -0
- data/server/node_modules/cradle/Makefile +0 -10
- data/server/node_modules/cradle/test/cradle-test.js +0 -650
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/no-filename/generic.http +0 -13
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/osx-chrome-13.http +0 -26
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/osx-firefox-3.6.http +0 -24
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/osx-safari-5.http +0 -23
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-chrome-12.http +0 -24
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-ie-7.http +0 -22
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-ie-8.http +0 -22
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-safari-5.http +0 -22
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/multi_video.upload +0 -0
- data/server/node_modules/express/node_modules/connect/test.js +0 -52
- data/server/node_modules/express/testing/foo/app.js +0 -35
- data/server/node_modules/express/testing/foo/package.json +0 -9
- data/server/node_modules/express/testing/foo/public/stylesheets/style.css +0 -8
- data/server/node_modules/express/testing/foo/routes/index.js +0 -10
- data/server/node_modules/express/testing/foo/views/index.jade +0 -2
- data/server/node_modules/express/testing/foo/views/layout.jade +0 -6
- data/server/node_modules/express/testing/index.js +0 -43
- data/server/node_modules/express/testing/public/test.txt +0 -2971
- data/server/node_modules/express/testing/views/page.html +0 -1
- data/server/node_modules/express/testing/views/page.jade +0 -3
- data/server/node_modules/express/testing/views/test.md +0 -1
- data/server/node_modules/express/testing/views/user/index.jade +0 -1
- data/server/node_modules/express/testing/views/user/list.jade +0 -1
- data/server/node_modules/knox/lib/knox/mime/index.js +0 -308
- data/server/node_modules/knox/lib/knox/mime/test.js +0 -59
- data/server/node_modules/node-uuid/test/benchmark-native +0 -0
- data/server/node_modules/on/index.js +0 -13
- data/server/node_modules/restler/test/test_helper.js +0 -163
- data/server/node_modules/spawner/index.js +0 -106
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Copyright 2011 Iris Couch
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
exports.scrub_creds = function scrub_creds(url) {
|
|
16
|
+
return url.replace(/^(https?:\/\/)[^:]+:[^@]+@(.*)$/, '$1$2'); // Scrub username and password
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
exports.JP = JSON.parse;
|
|
20
|
+
exports.JS = JSON.stringify;
|
|
21
|
+
exports.JDUP = function(obj) { return JSON.parse(JSON.stringify(obj)) };
|
|
22
|
+
|
|
23
|
+
var timeouts = { 'setTimeout': setTimeout
|
|
24
|
+
, 'clearTimeout': clearTimeout
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
exports.setTimeout = function() { return timeouts.setTimeout.apply(this, arguments) }
|
|
28
|
+
exports.clearTimeout = function() { return timeouts.clearTimeout.apply(this, arguments) }
|
|
29
|
+
exports.timeouts = function(set, clear) {
|
|
30
|
+
timeouts.setTimeout = set
|
|
31
|
+
timeouts.clearTimeout = clear
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Wrap log4js so it will not be a dependency.
|
|
35
|
+
var VERBOSE;
|
|
36
|
+
if(require.isBrowser)
|
|
37
|
+
VERBOSE = true;
|
|
38
|
+
else
|
|
39
|
+
VERBOSE = (process.env.verbose === 'true');
|
|
40
|
+
|
|
41
|
+
var noop = function() {}
|
|
42
|
+
if(process.env.TAP_DIAG)
|
|
43
|
+
noop = console.error
|
|
44
|
+
|
|
45
|
+
function noops() {
|
|
46
|
+
return { "trace": noop
|
|
47
|
+
, "debug": VERBOSE ? console.log : noop
|
|
48
|
+
, "info" : VERBOSE ? console.info : noop
|
|
49
|
+
, "warn" : VERBOSE ? console.warn : noop
|
|
50
|
+
, "error": VERBOSE ? console.error : noop
|
|
51
|
+
, "fatal": VERBOSE ? console.error : noop
|
|
52
|
+
|
|
53
|
+
, "level": {'level':0, 'levelStr':'noop'}
|
|
54
|
+
, "setLevel": noop
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
if(! process.env.log_plain)
|
|
61
|
+
exports.log4js = require('log4js');
|
|
62
|
+
} catch(e) {
|
|
63
|
+
exports.log4js = null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
exports.log4js = exports.log4js || { 'getLogger': function() { return noops() } }
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
// Changes stream
|
|
2
|
+
//
|
|
3
|
+
// Copyright 2011 Iris Couch
|
|
4
|
+
//
|
|
5
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
// you may not use this file except in compliance with the License.
|
|
7
|
+
// You may obtain a copy of the License at
|
|
8
|
+
//
|
|
9
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
//
|
|
11
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
// See the License for the specific language governing permissions and
|
|
15
|
+
// limitations under the License.
|
|
16
|
+
|
|
17
|
+
var lib = require('../lib')
|
|
18
|
+
, util = require('util')
|
|
19
|
+
, stream = require('stream')
|
|
20
|
+
, request = require('request')
|
|
21
|
+
|
|
22
|
+
// Use the library timeout functions, primarily so the test suite can catch errors.
|
|
23
|
+
var setTimeout = lib.setTimeout
|
|
24
|
+
, clearTimeout = lib.clearTimeout
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
var DEFS =
|
|
28
|
+
{ 'longpoll_header': '{"results":['
|
|
29
|
+
, 'log_level' : process.env.follow_log_level || 'info'
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = { 'Changes': Changes
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
util.inherits(Changes, stream)
|
|
37
|
+
function Changes (opts) {
|
|
38
|
+
var self = this
|
|
39
|
+
stream.call(self)
|
|
40
|
+
|
|
41
|
+
self.readable = true
|
|
42
|
+
self.writable = true
|
|
43
|
+
|
|
44
|
+
self.headers = {}
|
|
45
|
+
self.statusCode = null
|
|
46
|
+
|
|
47
|
+
opts = opts || {}
|
|
48
|
+
self.feed = opts.feed || null // "continuous" or "longpoll"
|
|
49
|
+
self.encoding = opts.encoding || 'utf8'
|
|
50
|
+
|
|
51
|
+
self.log = opts.log
|
|
52
|
+
if(!self.log) {
|
|
53
|
+
self.log = lib.log4js.getLogger('change_stream')
|
|
54
|
+
self.log.setLevel(DEFS.log_level)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
self.is_sending = true
|
|
58
|
+
self.is_ending = false
|
|
59
|
+
self.is_dead = false
|
|
60
|
+
|
|
61
|
+
self.source = null
|
|
62
|
+
self.expect = null
|
|
63
|
+
self.buf = null
|
|
64
|
+
self.changes = []
|
|
65
|
+
|
|
66
|
+
self.on('pipe', function(src) {
|
|
67
|
+
if(!self.source)
|
|
68
|
+
self.source = src
|
|
69
|
+
else {
|
|
70
|
+
var er = new Error('Already have a pipe source')
|
|
71
|
+
er.source = self.source
|
|
72
|
+
self.error(er)
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
Changes.prototype.setHeader = function(key, val) {
|
|
79
|
+
var self = this
|
|
80
|
+
self.headers[key] = val
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
//
|
|
84
|
+
// Readable stream API
|
|
85
|
+
//
|
|
86
|
+
|
|
87
|
+
Changes.prototype.setEncoding = function(encoding) {
|
|
88
|
+
var self = this
|
|
89
|
+
self.encoding = encoding // TODO
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
Changes.prototype.pause = function() {
|
|
94
|
+
var self = this
|
|
95
|
+
self.is_sending = false
|
|
96
|
+
|
|
97
|
+
if(self.source && self.source.pause)
|
|
98
|
+
self.source.pause()
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
Changes.prototype.resume = function() {
|
|
103
|
+
var self = this
|
|
104
|
+
self.is_sending = true
|
|
105
|
+
if(self.source && self.source.resume)
|
|
106
|
+
self.source.resume()
|
|
107
|
+
self.emit_changes()
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
//
|
|
111
|
+
// Writable stream API
|
|
112
|
+
//
|
|
113
|
+
|
|
114
|
+
Changes.prototype.write = function(data, encoding) {
|
|
115
|
+
var self = this
|
|
116
|
+
|
|
117
|
+
data = self.normalize_data(data, encoding)
|
|
118
|
+
if(typeof data != 'string')
|
|
119
|
+
return // Looks like normalize_data emitted an error.
|
|
120
|
+
|
|
121
|
+
if(self.feed === 'longpoll')
|
|
122
|
+
return self.write_longpoll(data)
|
|
123
|
+
else if(self.feed === 'continuous')
|
|
124
|
+
return self.write_continuous(data)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
Changes.prototype.write_longpoll = function(data) {
|
|
129
|
+
var self = this
|
|
130
|
+
|
|
131
|
+
if(self.buf === null)
|
|
132
|
+
self.buf = []
|
|
133
|
+
|
|
134
|
+
self.buf.push(data)
|
|
135
|
+
return true
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
Changes.prototype.write_continuous = function(data) {
|
|
140
|
+
var self = this
|
|
141
|
+
|
|
142
|
+
var offset, json, change
|
|
143
|
+
, buf = (self.buf || "") + data
|
|
144
|
+
|
|
145
|
+
self.log.debug('write: ' + util.inspect({'data':data, 'buf':buf}))
|
|
146
|
+
|
|
147
|
+
// Buf could have 0, 1, or many JSON objects in it.
|
|
148
|
+
while((offset = buf.indexOf("\n")) >= 0) {
|
|
149
|
+
json = buf.substr(0, offset);
|
|
150
|
+
buf = buf.substr(offset + 1);
|
|
151
|
+
self.log.debug('JSON: ' + util.inspect(json))
|
|
152
|
+
|
|
153
|
+
// Heartbeats (empty strings) are fine, but otherwise confirm valid JSON.
|
|
154
|
+
if(json === "")
|
|
155
|
+
;
|
|
156
|
+
|
|
157
|
+
else if(json[0] !== '{')
|
|
158
|
+
return self.error(new Error('Non-object JSON data: ' + json))
|
|
159
|
+
|
|
160
|
+
else {
|
|
161
|
+
try { change = JSON.parse(json) }
|
|
162
|
+
catch (er) { return self.error(er) }
|
|
163
|
+
|
|
164
|
+
self.log.debug('Object: ' + util.inspect(change))
|
|
165
|
+
json = JSON.stringify(change)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Change (or heartbeat) looks good.
|
|
169
|
+
self.changes.push(json)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Remember the unused data and send all known good changes (or heartbeats).
|
|
173
|
+
self.buf = buf
|
|
174
|
+
self.emit_changes()
|
|
175
|
+
|
|
176
|
+
return self.is_sending
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
Changes.prototype.end = function(data, encoding) {
|
|
181
|
+
var self = this
|
|
182
|
+
|
|
183
|
+
self.is_ending = true
|
|
184
|
+
self.writable = false
|
|
185
|
+
|
|
186
|
+
// Always call write, even with no data, so it can fire the "end" event.
|
|
187
|
+
self.write(data, encoding)
|
|
188
|
+
|
|
189
|
+
if(self.feed === 'longpoll') {
|
|
190
|
+
var changes = [ DEFS.longpoll_header ].concat(self.buf).join('')
|
|
191
|
+
try { changes = JSON.parse(changes) || {} }
|
|
192
|
+
catch (er) { return self.error(er) }
|
|
193
|
+
|
|
194
|
+
if(!Array.isArray(changes.results))
|
|
195
|
+
return self.error(new Error('No "results" field in feed'))
|
|
196
|
+
if(self.changes.length !== 0)
|
|
197
|
+
return self.error(new Error('Changes are already queued: ' + JSON.stringify(self.changes)))
|
|
198
|
+
|
|
199
|
+
self.changes = changes.results.map(function(change) { return JSON.stringify(change) })
|
|
200
|
+
return self.emit_changes()
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
else if(self.feed === 'continuous') {
|
|
204
|
+
if(self.buf !== "")
|
|
205
|
+
self.log.debug('Unprocessed data after "end" called: ' + util.inspect(self.buf))
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
Changes.prototype.emit_changes = function() {
|
|
211
|
+
var self = this
|
|
212
|
+
|
|
213
|
+
while(self.is_sending && self.changes.length > 0) {
|
|
214
|
+
var change = self.changes.shift()
|
|
215
|
+
if(change === "") {
|
|
216
|
+
self.log.debug('emit: heartbeat')
|
|
217
|
+
self.emit('heartbeat')
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
else {
|
|
221
|
+
self.log.debug('emit: data')
|
|
222
|
+
self.emit('data', change)
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if(self.is_sending && self.is_ending && self.changes.length === 0) {
|
|
227
|
+
self.is_ending = false
|
|
228
|
+
self.readable = false
|
|
229
|
+
self.log.debug('emit: end')
|
|
230
|
+
self.emit('end')
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
//
|
|
235
|
+
// Readable/writable stream API
|
|
236
|
+
//
|
|
237
|
+
|
|
238
|
+
Changes.prototype.destroy = function() {
|
|
239
|
+
var self = this
|
|
240
|
+
self.log.debug('destroy')
|
|
241
|
+
|
|
242
|
+
self.is_dead = true
|
|
243
|
+
self.is_ending = false
|
|
244
|
+
self.is_sending = false
|
|
245
|
+
|
|
246
|
+
if(self.source && typeof self.source.destroy === 'function')
|
|
247
|
+
self.source.destroy()
|
|
248
|
+
|
|
249
|
+
// Often the source is from the request package, so destroy its response object.
|
|
250
|
+
if(self.source && self.source.__isRequestRequest && self.source.response
|
|
251
|
+
&& typeof self.source.response.destroy === 'function')
|
|
252
|
+
self.source.response.destroy()
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
Changes.prototype.destroySoon = function() {
|
|
257
|
+
var self = this
|
|
258
|
+
throw new Error('not implemented')
|
|
259
|
+
//return self.request.destroySoon()
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
//
|
|
263
|
+
// Internal implementation
|
|
264
|
+
//
|
|
265
|
+
|
|
266
|
+
Changes.prototype.normalize_data = function(data, encoding) {
|
|
267
|
+
var self = this
|
|
268
|
+
|
|
269
|
+
if(data instanceof Buffer)
|
|
270
|
+
data = data.toString(encoding)
|
|
271
|
+
else if(typeof data === 'undefined' && typeof encoding === 'undefined')
|
|
272
|
+
data = ""
|
|
273
|
+
|
|
274
|
+
if(typeof data != 'string')
|
|
275
|
+
return self.error(new Error('Not a string or Buffer: ' + util.inspect(data)))
|
|
276
|
+
|
|
277
|
+
if(self.feed !== 'continuous' && self.feed !== 'longpoll')
|
|
278
|
+
return self.error(new Error('Must set .feed to "continuous" or "longpoll" before writing data'))
|
|
279
|
+
|
|
280
|
+
if(self.expect === null)
|
|
281
|
+
self.expect = (self.feed == 'longpoll')
|
|
282
|
+
? DEFS.longpoll_header
|
|
283
|
+
: ""
|
|
284
|
+
|
|
285
|
+
var prefix = data.substr(0, self.expect.length)
|
|
286
|
+
data = data.substr(prefix.length)
|
|
287
|
+
|
|
288
|
+
var expected_part = self.expect.substr(0, prefix.length)
|
|
289
|
+
, expected_remainder = self.expect.substr(expected_part.length)
|
|
290
|
+
|
|
291
|
+
if(prefix !== expected_part)
|
|
292
|
+
return self.error(new Error('Prefix not expected '+util.inspect(expected_part)+': ' + util.inspect(prefix)))
|
|
293
|
+
|
|
294
|
+
self.expect = expected_remainder
|
|
295
|
+
return data
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
Changes.prototype.error = function(er) {
|
|
300
|
+
var self = this
|
|
301
|
+
|
|
302
|
+
self.readable = false
|
|
303
|
+
self.writable = false
|
|
304
|
+
self.emit('error', er)
|
|
305
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
|
|
5
|
+
http://www.apache.org/licenses/
|
|
6
|
+
|
|
7
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
8
|
+
|
|
9
|
+
1. Definitions.
|
|
10
|
+
|
|
11
|
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
16
|
+
|
|
17
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
|
18
|
+
|
|
19
|
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
|
20
|
+
|
|
21
|
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
|
22
|
+
|
|
23
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
|
24
|
+
|
|
25
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
|
26
|
+
|
|
27
|
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
|
28
|
+
|
|
29
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
|
30
|
+
|
|
31
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
|
32
|
+
|
|
33
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
|
34
|
+
|
|
35
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
|
36
|
+
|
|
37
|
+
You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
|
38
|
+
|
|
39
|
+
You must cause any modified files to carry prominent notices stating that You changed the files; and
|
|
40
|
+
|
|
41
|
+
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
|
42
|
+
|
|
43
|
+
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
|
44
|
+
|
|
45
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
|
46
|
+
|
|
47
|
+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
|
48
|
+
|
|
49
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
|
50
|
+
|
|
51
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
|
52
|
+
|
|
53
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
|
54
|
+
|
|
55
|
+
END OF TERMS AND CONDITIONS
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
# Request -- Simplified HTTP request method
|
|
2
|
+
|
|
3
|
+
## Install
|
|
4
|
+
|
|
5
|
+
<pre>
|
|
6
|
+
npm install request
|
|
7
|
+
</pre>
|
|
8
|
+
|
|
9
|
+
Or from source:
|
|
10
|
+
|
|
11
|
+
<pre>
|
|
12
|
+
git clone git://github.com/mikeal/request.git
|
|
13
|
+
cd request
|
|
14
|
+
npm link
|
|
15
|
+
</pre>
|
|
16
|
+
|
|
17
|
+
## Super simple to use
|
|
18
|
+
|
|
19
|
+
Request is designed to be the simplest way possible to make http calls. It support HTTPS and follows redirects by default.
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
var request = require('request');
|
|
23
|
+
request('http://www.google.com', function (error, response, body) {
|
|
24
|
+
if (!error && response.statusCode == 200) {
|
|
25
|
+
console.log(body) // Print the google web page.
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Streaming
|
|
31
|
+
|
|
32
|
+
You can stream any response to a file stream.
|
|
33
|
+
|
|
34
|
+
```javascript
|
|
35
|
+
request('http://google.com/doodle.png').pipe(fs.createWriteStream('doodle.png'))
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
You can also stream a file to a PUT or POST request. This method will also check the file extension against a mapping of file extensions to content-types, in this case `application/json`, and use the proper content-type in the PUT request if one is not already provided in the headers.
|
|
39
|
+
|
|
40
|
+
```javascript
|
|
41
|
+
fs.readStream('file.json').pipe(request.put('http://mysite.com/obj.json'))
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Request can also pipe to itself. When doing so the content-type and content-length will be preserved in the PUT headers.
|
|
45
|
+
|
|
46
|
+
```javascript
|
|
47
|
+
request.get('http://google.com/img.png').pipe(request.put('http://mysite.com/img.png'))
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Now let's get fancy.
|
|
51
|
+
|
|
52
|
+
```javascript
|
|
53
|
+
http.createServer(function (req, resp) {
|
|
54
|
+
if (req.url === '/doodle.png') {
|
|
55
|
+
if (req.method === 'PUT') {
|
|
56
|
+
req.pipe(request.put('http://mysite.com/doodle.png'))
|
|
57
|
+
} else if (req.method === 'GET' || req.method === 'HEAD') {
|
|
58
|
+
request.get('http://mysite.com/doodle.png').pipe(resp)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
You can also pipe() from a http.ServerRequest instance and to a http.ServerResponse instance. The HTTP method and headers will be sent as well as the entity-body data. Which means that, if you don't really care about security, you can do:
|
|
65
|
+
|
|
66
|
+
```javascript
|
|
67
|
+
http.createServer(function (req, resp) {
|
|
68
|
+
if (req.url === '/doodle.png') {
|
|
69
|
+
var x = request('http://mysite.com/doodle.png')
|
|
70
|
+
req.pipe(x)
|
|
71
|
+
x.pipe(resp)
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
And since pipe() returns the destination stream in node 0.5.x you can do one line proxying :)
|
|
77
|
+
|
|
78
|
+
```javascript
|
|
79
|
+
req.pipe(request('http://mysite.com/doodle.png')).pipe(resp)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Also, none of this new functionality conflicts with requests previous features, it just expands them.
|
|
83
|
+
|
|
84
|
+
```javascript
|
|
85
|
+
var r = request.defaults({'proxy':'http://localproxy.com'})
|
|
86
|
+
|
|
87
|
+
http.createServer(function (req, resp) {
|
|
88
|
+
if (req.url === '/doodle.png') {
|
|
89
|
+
r.get('http://google.com/doodle.png').pipe(resp)
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
You can still use intermediate proxies, the requests will still follow HTTP forwards, etc.
|
|
95
|
+
|
|
96
|
+
## OAuth Signing
|
|
97
|
+
|
|
98
|
+
```javascript
|
|
99
|
+
// Twitter OAuth
|
|
100
|
+
var qs = require('querystring')
|
|
101
|
+
, oauth =
|
|
102
|
+
{ callback: 'http://mysite.com/callback/'
|
|
103
|
+
, consumer_key: CONSUMER_KEY
|
|
104
|
+
, consumer_secret: CONSUMER_SECRET
|
|
105
|
+
}
|
|
106
|
+
, url = 'https://api.twitter.com/oauth/request_token'
|
|
107
|
+
;
|
|
108
|
+
request.post({url:url, oauth:oauth}, function (e, r, body) {
|
|
109
|
+
// Assume by some stretch of magic you aquired the verifier
|
|
110
|
+
var access_token = qs.parse(body)
|
|
111
|
+
, oauth =
|
|
112
|
+
{ consumer_key: CONSUMER_KEY
|
|
113
|
+
, consumer_secret: CONSUMER_SECRET
|
|
114
|
+
, token: access_token.oauth_token
|
|
115
|
+
, verifier: VERIFIER
|
|
116
|
+
, token_secret: access_token.oauth_token_secret
|
|
117
|
+
}
|
|
118
|
+
, url = 'https://api.twitter.com/oauth/access_token'
|
|
119
|
+
;
|
|
120
|
+
request.post({url:url, oauth:oauth}, function (e, r, body) {
|
|
121
|
+
var perm_token = qs.parse(body)
|
|
122
|
+
, oauth =
|
|
123
|
+
{ consumer_key: CONSUMER_KEY
|
|
124
|
+
, consumer_secret: CONSUMER_SECRET
|
|
125
|
+
, token: perm_token.oauth_token
|
|
126
|
+
, token_secret: perm_token.oauth_token_secret
|
|
127
|
+
}
|
|
128
|
+
, url = 'https://api.twitter.com/1/users/show.json?'
|
|
129
|
+
, params =
|
|
130
|
+
{ screen_name: perm_token.screen_name
|
|
131
|
+
, user_id: perm_token.user_id
|
|
132
|
+
}
|
|
133
|
+
;
|
|
134
|
+
url += qs.stringify(params)
|
|
135
|
+
request.get({url:url, oauth:oauth, json:true}, function (e, r, user) {
|
|
136
|
+
console.log(user)
|
|
137
|
+
})
|
|
138
|
+
})
|
|
139
|
+
})
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
### request(options, callback)
|
|
145
|
+
|
|
146
|
+
The first argument can be either a url or an options object. The only required option is uri, all others are optional.
|
|
147
|
+
|
|
148
|
+
* `uri` || `url` - fully qualified uri or a parsed url object from url.parse()
|
|
149
|
+
* `method` - http method, defaults to GET
|
|
150
|
+
* `headers` - http headers, defaults to {}
|
|
151
|
+
* `body` - entity body for POST and PUT requests. Must be buffer or string.
|
|
152
|
+
* `json` - sets `body` but to JSON representation of value and adds `Content-type: application/json` header.
|
|
153
|
+
* `multipart` - (experimental) array of objects which contains their own headers and `body` attribute. Sends `multipart/related` request. See example below.
|
|
154
|
+
* `followRedirect` - follow HTTP 3xx responses as redirects. defaults to true.
|
|
155
|
+
* `maxRedirects` - the maximum number of redirects to follow, defaults to 10.
|
|
156
|
+
* `onResponse` - If true the callback will be fired on the "response" event instead of "end". If a function it will be called on "response" and not effect the regular semantics of the main callback on "end".
|
|
157
|
+
* `encoding` - Encoding to be used on response.setEncoding when buffering the response data.
|
|
158
|
+
* `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.
|
|
159
|
+
* `pool.maxSockets` - Integer containing the maximum amount of sockets in the pool.
|
|
160
|
+
* `timeout` - Integer containing the number of milliseconds to wait for a request to respond before aborting the request
|
|
161
|
+
* `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.
|
|
162
|
+
* `oauth` - Options for OAuth HMAC-SHA1 signing, see documentation above.
|
|
163
|
+
* `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.
|
|
164
|
+
* `jar` - Set to `false` if you don't want cookies to be remembered for future use or define your custom cookie jar (see examples section)
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
The callback argument gets 3 arguments. The first is an error when applicable (usually from the http.Client option not the http.ClientRequest object). The second in an http.ClientResponse object. The third is the response body buffer.
|
|
168
|
+
|
|
169
|
+
## Convenience methods
|
|
170
|
+
|
|
171
|
+
There are also shorthand methods for different HTTP METHODs and some other conveniences.
|
|
172
|
+
|
|
173
|
+
### request.defaults(options)
|
|
174
|
+
|
|
175
|
+
This method returns a wrapper around the normal request API that defaults to whatever options you pass in to it.
|
|
176
|
+
|
|
177
|
+
### request.put
|
|
178
|
+
|
|
179
|
+
Same as request() but defaults to `method: "PUT"`.
|
|
180
|
+
|
|
181
|
+
```javascript
|
|
182
|
+
request.put(url)
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### request.post
|
|
186
|
+
|
|
187
|
+
Same as request() but defaults to `method: "POST"`.
|
|
188
|
+
|
|
189
|
+
```javascript
|
|
190
|
+
request.post(url)
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### request.head
|
|
194
|
+
|
|
195
|
+
Same as request() but defaults to `method: "HEAD"`.
|
|
196
|
+
|
|
197
|
+
```javascript
|
|
198
|
+
request.head(url)
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### request.del
|
|
202
|
+
|
|
203
|
+
Same as request() but defaults to `method: "DELETE"`.
|
|
204
|
+
|
|
205
|
+
```javascript
|
|
206
|
+
request.del(url)
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### request.get
|
|
210
|
+
|
|
211
|
+
Alias to normal request method for uniformity.
|
|
212
|
+
|
|
213
|
+
```javascript
|
|
214
|
+
request.get(url)
|
|
215
|
+
```
|
|
216
|
+
### request.cookie
|
|
217
|
+
|
|
218
|
+
Function that creates a new cookie.
|
|
219
|
+
|
|
220
|
+
```javascript
|
|
221
|
+
request.cookie('cookie_string_here')
|
|
222
|
+
```
|
|
223
|
+
### request.jar
|
|
224
|
+
|
|
225
|
+
Function that creates a new cookie jar.
|
|
226
|
+
|
|
227
|
+
```javascript
|
|
228
|
+
request.jar()
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
## Examples:
|
|
233
|
+
|
|
234
|
+
```javascript
|
|
235
|
+
var request = require('request')
|
|
236
|
+
, rand = Math.floor(Math.random()*100000000).toString()
|
|
237
|
+
;
|
|
238
|
+
request(
|
|
239
|
+
{ method: 'PUT'
|
|
240
|
+
, uri: 'http://mikeal.iriscouch.com/testjs/' + rand
|
|
241
|
+
, multipart:
|
|
242
|
+
[ { 'content-type': 'application/json'
|
|
243
|
+
, body: JSON.stringify({foo: 'bar', _attachments: {'message.txt': {follows: true, length: 18, 'content_type': 'text/plain' }}})
|
|
244
|
+
}
|
|
245
|
+
, { body: 'I am an attachment' }
|
|
246
|
+
]
|
|
247
|
+
}
|
|
248
|
+
, function (error, response, body) {
|
|
249
|
+
if(response.statusCode == 201){
|
|
250
|
+
console.log('document saved as: http://mikeal.iriscouch.com/testjs/'+ rand)
|
|
251
|
+
} else {
|
|
252
|
+
console.log('error: '+ response.statusCode)
|
|
253
|
+
console.log(body)
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
)
|
|
257
|
+
```
|
|
258
|
+
Cookies are enabled by default (so they can be used in subsequent requests). To disable cookies set jar to false (either in defaults or in the options sent).
|
|
259
|
+
|
|
260
|
+
```javascript
|
|
261
|
+
var request = request.defaults({jar: false})
|
|
262
|
+
request('http://www.google.com', function () {
|
|
263
|
+
request('http://images.google.com')
|
|
264
|
+
})
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
If you to use a custom cookie jar (instead of letting request use its own global cookie jar) you do so by setting the jar default or by specifying it as an option:
|
|
268
|
+
|
|
269
|
+
```javascript
|
|
270
|
+
var j = request.jar()
|
|
271
|
+
var request = request.defaults({jar:j})
|
|
272
|
+
request('http://www.google.com', function () {
|
|
273
|
+
request('http://images.google.com')
|
|
274
|
+
})
|
|
275
|
+
```
|
|
276
|
+
OR
|
|
277
|
+
|
|
278
|
+
```javascript
|
|
279
|
+
var j = request.jar()
|
|
280
|
+
var cookie = request.cookie('your_cookie_here')
|
|
281
|
+
j.add(cookie)
|
|
282
|
+
request({url: 'http://www.google.com', jar: j}, function () {
|
|
283
|
+
request('http://images.google.com')
|
|
284
|
+
})
|
|
285
|
+
```
|