freezerwatch 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (314) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/CODE_OF_CONDUCT.md +13 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +21 -0
  6. data/README.md +40 -0
  7. data/Rakefile +1 -0
  8. data/bin/console +14 -0
  9. data/bin/freezerwatch +9 -0
  10. data/bin/setup +7 -0
  11. data/freezerwatch.gemspec +23 -0
  12. data/lib/freezerwatch.rb +5 -0
  13. data/lib/freezerwatch/version.rb +3 -0
  14. data/node_modules/.bin/freezerwatch +139 -0
  15. data/node_modules/freezerwatch/.npmignore +3 -0
  16. data/node_modules/freezerwatch/.ruby-version +1 -0
  17. data/node_modules/freezerwatch/Gemfile +4 -0
  18. data/node_modules/freezerwatch/Gemfile.lock +79 -0
  19. data/node_modules/freezerwatch/LICENSE +23 -0
  20. data/node_modules/freezerwatch/README.md +41 -0
  21. data/node_modules/freezerwatch/Rakefile +13 -0
  22. data/node_modules/freezerwatch/freezerwatch.js +139 -0
  23. data/node_modules/freezerwatch/metrics/bigfiles_high_water_mark +1 -0
  24. data/node_modules/freezerwatch/metrics/cane_high_water_mark +1 -0
  25. data/node_modules/freezerwatch/metrics/flay_high_water_mark +1 -0
  26. data/node_modules/freezerwatch/metrics/flog_high_water_mark +1 -0
  27. data/node_modules/freezerwatch/metrics/punchlist_high_water_mark +2 -0
  28. data/node_modules/freezerwatch/metrics/reek_high_water_mark +1 -0
  29. data/node_modules/freezerwatch/metrics/rubocop_high_water_mark +1 -0
  30. data/node_modules/freezerwatch/node_modules/async/.jshintrc +25 -0
  31. data/node_modules/freezerwatch/node_modules/async/.travis.yml +6 -0
  32. data/node_modules/freezerwatch/node_modules/async/CHANGELOG.md +65 -0
  33. data/node_modules/freezerwatch/node_modules/async/LICENSE +19 -0
  34. data/node_modules/freezerwatch/node_modules/async/README.md +1803 -0
  35. data/node_modules/freezerwatch/node_modules/async/bower.json +43 -0
  36. data/node_modules/freezerwatch/node_modules/async/component.json +17 -0
  37. data/node_modules/freezerwatch/node_modules/async/coverage/base.css +182 -0
  38. data/node_modules/freezerwatch/node_modules/async/coverage/index.html +73 -0
  39. data/node_modules/freezerwatch/node_modules/async/coverage/lcov-report/base.css +182 -0
  40. data/node_modules/freezerwatch/node_modules/async/coverage/lcov-report/index.html +73 -0
  41. data/node_modules/freezerwatch/node_modules/async/coverage/lcov-report/lib/async.js.html +3900 -0
  42. data/node_modules/freezerwatch/node_modules/async/coverage/lcov-report/lib/index.html +73 -0
  43. data/node_modules/freezerwatch/node_modules/async/coverage/lcov-report/prettify.css +1 -0
  44. data/node_modules/freezerwatch/node_modules/async/coverage/lcov-report/prettify.js +1 -0
  45. data/node_modules/freezerwatch/node_modules/async/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  46. data/node_modules/freezerwatch/node_modules/async/coverage/lcov-report/sorter.js +156 -0
  47. data/node_modules/freezerwatch/node_modules/async/coverage/lcov.info +1452 -0
  48. data/node_modules/freezerwatch/node_modules/async/coverage/lib/async.js.html +3597 -0
  49. data/node_modules/freezerwatch/node_modules/async/coverage/lib/index.html +73 -0
  50. data/node_modules/freezerwatch/node_modules/async/coverage/prettify.css +1 -0
  51. data/node_modules/freezerwatch/node_modules/async/coverage/prettify.js +1 -0
  52. data/node_modules/freezerwatch/node_modules/async/coverage/sort-arrow-sprite.png +0 -0
  53. data/node_modules/freezerwatch/node_modules/async/coverage/sorter.js +156 -0
  54. data/node_modules/freezerwatch/node_modules/async/lib/async.js +1191 -0
  55. data/node_modules/freezerwatch/node_modules/async/nyc_output/5074.json +1 -0
  56. data/node_modules/freezerwatch/node_modules/async/package.json +96 -0
  57. data/node_modules/freezerwatch/node_modules/async/support/sync-package-managers.js +53 -0
  58. data/node_modules/freezerwatch/node_modules/lacrosse/.npmignore +15 -0
  59. data/node_modules/freezerwatch/node_modules/lacrosse/Client.js +60 -0
  60. data/node_modules/freezerwatch/node_modules/lacrosse/Device.js +38 -0
  61. data/node_modules/freezerwatch/node_modules/lacrosse/DeviceRawReadStream.js +36 -0
  62. data/node_modules/freezerwatch/node_modules/lacrosse/DeviceSingleRawReadStream.js +29 -0
  63. data/node_modules/freezerwatch/node_modules/lacrosse/DeviceStream.js +35 -0
  64. data/node_modules/freezerwatch/node_modules/lacrosse/LICENSE +23 -0
  65. data/node_modules/freezerwatch/node_modules/lacrosse/README.md +25 -0
  66. data/node_modules/freezerwatch/node_modules/lacrosse/index.js +1 -0
  67. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/.npmignore +2 -0
  68. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/.travis.yml +12 -0
  69. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/LICENSE +55 -0
  70. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/README.md +364 -0
  71. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/index.js +156 -0
  72. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/lib/copy.js +8 -0
  73. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/lib/debug.js +7 -0
  74. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/lib/getSafe.js +34 -0
  75. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/lib/optional.js +5 -0
  76. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/.bin/uuid +26 -0
  77. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/aws-sign2/LICENSE +55 -0
  78. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/aws-sign2/README.md +4 -0
  79. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/aws-sign2/index.js +202 -0
  80. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/aws-sign2/package.json +46 -0
  81. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/forever-agent/LICENSE +55 -0
  82. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/forever-agent/README.md +4 -0
  83. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/forever-agent/index.js +119 -0
  84. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/forever-agent/package.json +45 -0
  85. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/form-data/License +19 -0
  86. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/form-data/Readme.md +175 -0
  87. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/form-data/lib/form_data.js +351 -0
  88. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/form-data/node_modules/async/.travis.yml +5 -0
  89. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/form-data/node_modules/async/LICENSE +19 -0
  90. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/form-data/node_modules/async/README.md +1647 -0
  91. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/form-data/node_modules/async/bower.json +38 -0
  92. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/form-data/node_modules/async/component.json +16 -0
  93. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/form-data/node_modules/async/lib/async.js +1123 -0
  94. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/form-data/node_modules/async/package.json +84 -0
  95. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/form-data/node_modules/async/support/sync-package-managers.js +53 -0
  96. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/form-data/node_modules/combined-stream/License +19 -0
  97. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/form-data/node_modules/combined-stream/Readme.md +132 -0
  98. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/form-data/node_modules/combined-stream/lib/combined_stream.js +188 -0
  99. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/.npmignore +2 -0
  100. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/License +19 -0
  101. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/Makefile +7 -0
  102. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/Readme.md +154 -0
  103. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/lib/delayed_stream.js +99 -0
  104. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/package.json +42 -0
  105. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/common.js +6 -0
  106. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-delayed-http-upload.js +38 -0
  107. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-delayed-stream-auto-pause.js +21 -0
  108. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-delayed-stream-pause.js +14 -0
  109. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-delayed-stream.js +48 -0
  110. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-handle-source-errors.js +15 -0
  111. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-max-data-size.js +18 -0
  112. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-pipe-resumes.js +13 -0
  113. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-proxy-readable.js +13 -0
  114. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/run.js +7 -0
  115. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/form-data/node_modules/combined-stream/package.json +60 -0
  116. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/form-data/package.json +80 -0
  117. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/.npmignore +18 -0
  118. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/.travis.yml +5 -0
  119. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/LICENSE +24 -0
  120. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/Makefile +10 -0
  121. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/README.md +627 -0
  122. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/example/usage.js +78 -0
  123. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/images/hawk.png +0 -0
  124. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/images/logo.png +0 -0
  125. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/index.js +1 -0
  126. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/lib/browser.js +485 -0
  127. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/lib/client.js +367 -0
  128. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/lib/crypto.js +111 -0
  129. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/lib/index.js +15 -0
  130. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/lib/server.js +524 -0
  131. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/lib/utils.js +183 -0
  132. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/boom/.npmignore +18 -0
  133. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/boom/.travis.yml +5 -0
  134. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/boom/LICENSE +24 -0
  135. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/boom/Makefile +11 -0
  136. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/boom/README.md +6 -0
  137. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/boom/images/boom.png +0 -0
  138. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/boom/index.js +1 -0
  139. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/boom/lib/index.js +207 -0
  140. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/boom/package.json +64 -0
  141. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/boom/test/index.js +245 -0
  142. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/cryptiles/.npmignore +18 -0
  143. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/cryptiles/.travis.yml +5 -0
  144. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/cryptiles/LICENSE +24 -0
  145. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/cryptiles/Makefile +11 -0
  146. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/cryptiles/README.md +6 -0
  147. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/cryptiles/index.js +1 -0
  148. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/cryptiles/lib/index.js +68 -0
  149. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/cryptiles/package.json +65 -0
  150. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/cryptiles/test/index.js +101 -0
  151. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/hoek/.npmignore +18 -0
  152. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/hoek/.travis.yml +5 -0
  153. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/hoek/LICENSE +33 -0
  154. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/hoek/Makefile +10 -0
  155. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/hoek/README.md +436 -0
  156. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/hoek/images/hoek.png +0 -0
  157. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/hoek/index.js +1 -0
  158. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/hoek/lib/escape.js +132 -0
  159. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/hoek/lib/index.js +585 -0
  160. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/hoek/package.json +70 -0
  161. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/hoek/test/escaper.js +86 -0
  162. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/hoek/test/index.js +1078 -0
  163. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/hoek/test/modules/test1.js +1 -0
  164. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/hoek/test/modules/test2.js +1 -0
  165. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/hoek/test/modules/test3.js +1 -0
  166. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/sntp/.npmignore +18 -0
  167. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/sntp/.travis.yml +5 -0
  168. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/sntp/LICENSE +24 -0
  169. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/sntp/Makefile +11 -0
  170. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/sntp/README.md +68 -0
  171. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/sntp/examples/offset.js +16 -0
  172. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/sntp/examples/time.js +25 -0
  173. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/sntp/index.js +1 -0
  174. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/sntp/lib/index.js +409 -0
  175. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/sntp/package.json +65 -0
  176. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/node_modules/sntp/test/index.js +359 -0
  177. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/package.json +70 -0
  178. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/test/browser.js +771 -0
  179. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/test/client.js +206 -0
  180. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/test/crypto.js +86 -0
  181. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/test/index.js +316 -0
  182. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/test/message.js +246 -0
  183. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/test/readme.js +98 -0
  184. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/test/server.js +686 -0
  185. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/test/uri.js +456 -0
  186. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/hawk/test/utils.js +120 -0
  187. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/.dir-locals.el +6 -0
  188. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/.npmignore +7 -0
  189. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/LICENSE +18 -0
  190. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/README.md +79 -0
  191. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/http_signing.md +296 -0
  192. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/lib/index.js +26 -0
  193. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/lib/parser.js +304 -0
  194. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/lib/signer.js +178 -0
  195. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/lib/util.js +304 -0
  196. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/lib/verify.js +42 -0
  197. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/node_modules/asn1/.npmignore +2 -0
  198. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/node_modules/asn1/LICENSE +19 -0
  199. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/node_modules/asn1/README.md +50 -0
  200. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/errors.js +13 -0
  201. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/index.js +27 -0
  202. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/reader.js +267 -0
  203. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/types.js +36 -0
  204. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/writer.js +317 -0
  205. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/index.js +20 -0
  206. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/node_modules/asn1/package.json +63 -0
  207. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/node_modules/asn1/tst/ber/reader.test.js +172 -0
  208. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/node_modules/asn1/tst/ber/writer.test.js +296 -0
  209. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/node_modules/assert-plus/README.md +126 -0
  210. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/node_modules/assert-plus/assert.js +245 -0
  211. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/node_modules/assert-plus/package.json +45 -0
  212. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/node_modules/ctype/.npmignore +1 -0
  213. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/node_modules/ctype/CHANGELOG +78 -0
  214. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/node_modules/ctype/LICENSE +24 -0
  215. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/node_modules/ctype/README +82 -0
  216. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/node_modules/ctype/README.old +298 -0
  217. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/node_modules/ctype/ctf.js +245 -0
  218. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/node_modules/ctype/ctio.js +1485 -0
  219. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/node_modules/ctype/ctype.js +944 -0
  220. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/node_modules/ctype/man/man3ctype/ctio.3ctype +241 -0
  221. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/node_modules/ctype/package.json +42 -0
  222. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/node_modules/ctype/tools/jsl.conf +129 -0
  223. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/node_modules/ctype/tools/jsstyle +839 -0
  224. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/http-signature/package.json +72 -0
  225. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/json-stringify-safe/.npmignore +1 -0
  226. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/json-stringify-safe/CHANGELOG.md +14 -0
  227. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/json-stringify-safe/LICENSE +15 -0
  228. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/json-stringify-safe/Makefile +35 -0
  229. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/json-stringify-safe/README.md +52 -0
  230. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/json-stringify-safe/package.json +68 -0
  231. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/json-stringify-safe/stringify.js +27 -0
  232. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/json-stringify-safe/test/mocha.opts +2 -0
  233. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/json-stringify-safe/test/stringify_test.js +246 -0
  234. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/mime/LICENSE +19 -0
  235. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/mime/README.md +66 -0
  236. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/mime/mime.js +114 -0
  237. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/mime/package.json +57 -0
  238. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/mime/test.js +84 -0
  239. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/mime/types/mime.types +1588 -0
  240. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/mime/types/node.types +77 -0
  241. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/node-uuid/.npmignore +2 -0
  242. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/node-uuid/LICENSE.md +21 -0
  243. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/node-uuid/README.md +243 -0
  244. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/node-uuid/benchmark/README.md +53 -0
  245. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/node-uuid/benchmark/bench.gnu +174 -0
  246. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/node-uuid/benchmark/bench.sh +34 -0
  247. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/node-uuid/benchmark/benchmark-native.c +34 -0
  248. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/node-uuid/benchmark/benchmark.js +84 -0
  249. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/node-uuid/bin/uuid +26 -0
  250. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/node-uuid/bower.json +23 -0
  251. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/node-uuid/component.json +18 -0
  252. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/node-uuid/package.json +65 -0
  253. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/node-uuid/test/compare_v1.js +63 -0
  254. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/node-uuid/test/test.html +17 -0
  255. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/node-uuid/test/test.js +228 -0
  256. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/node-uuid/uuid.js +247 -0
  257. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/oauth-sign/LICENSE +55 -0
  258. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/oauth-sign/README.md +4 -0
  259. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/oauth-sign/index.js +43 -0
  260. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/oauth-sign/package.json +48 -0
  261. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/oauth-sign/test.js +49 -0
  262. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/qs/.gitmodules +6 -0
  263. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/qs/.npmignore +7 -0
  264. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/qs/Readme.md +58 -0
  265. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/qs/index.js +366 -0
  266. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/qs/package.json +55 -0
  267. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/tough-cookie/.jshintrc +72 -0
  268. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/tough-cookie/.npmignore +3 -0
  269. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/tough-cookie/LICENSE +78 -0
  270. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/tough-cookie/README.md +380 -0
  271. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/tough-cookie/generate-pubsuffix.js +230 -0
  272. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/tough-cookie/lib/cookie.js +947 -0
  273. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/tough-cookie/lib/memstore.js +102 -0
  274. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/tough-cookie/lib/pubsuffix.js +69 -0
  275. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/tough-cookie/node_modules/punycode/LICENSE-MIT.txt +20 -0
  276. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/tough-cookie/node_modules/punycode/README.md +176 -0
  277. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/tough-cookie/node_modules/punycode/package.json +81 -0
  278. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/tough-cookie/node_modules/punycode/punycode.js +530 -0
  279. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/tough-cookie/package.json +63 -0
  280. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/tough-cookie/public-suffix.txt +5229 -0
  281. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/tough-cookie/test.js +1340 -0
  282. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/tunnel-agent/LICENSE +55 -0
  283. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/tunnel-agent/README.md +4 -0
  284. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/tunnel-agent/index.js +227 -0
  285. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/node_modules/tunnel-agent/package.json +45 -0
  286. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/package.json +74 -0
  287. data/node_modules/freezerwatch/node_modules/lacrosse/node_modules/request/request.js +1244 -0
  288. data/node_modules/freezerwatch/node_modules/lacrosse/package.json +34 -0
  289. data/node_modules/freezerwatch/node_modules/optparse/README.md +163 -0
  290. data/node_modules/freezerwatch/node_modules/optparse/TODO +1 -0
  291. data/node_modules/freezerwatch/node_modules/optparse/examples/browser-test.html +75 -0
  292. data/node_modules/freezerwatch/node_modules/optparse/examples/nodejs-test.js +86 -0
  293. data/node_modules/freezerwatch/node_modules/optparse/lib/optparse.js +309 -0
  294. data/node_modules/freezerwatch/node_modules/optparse/package.json +46 -0
  295. data/node_modules/freezerwatch/node_modules/optparse/seed.yml +5 -0
  296. data/node_modules/freezerwatch/node_modules/osenv/.npmignore +13 -0
  297. data/node_modules/freezerwatch/node_modules/osenv/.travis.yml +9 -0
  298. data/node_modules/freezerwatch/node_modules/osenv/LICENSE +15 -0
  299. data/node_modules/freezerwatch/node_modules/osenv/README.md +63 -0
  300. data/node_modules/freezerwatch/node_modules/osenv/node_modules/os-homedir/index.js +24 -0
  301. data/node_modules/freezerwatch/node_modules/osenv/node_modules/os-homedir/license +21 -0
  302. data/node_modules/freezerwatch/node_modules/osenv/node_modules/os-homedir/package.json +70 -0
  303. data/node_modules/freezerwatch/node_modules/osenv/node_modules/os-homedir/readme.md +33 -0
  304. data/node_modules/freezerwatch/node_modules/osenv/node_modules/os-tmpdir/index.js +25 -0
  305. data/node_modules/freezerwatch/node_modules/osenv/node_modules/os-tmpdir/license +21 -0
  306. data/node_modules/freezerwatch/node_modules/osenv/node_modules/os-tmpdir/package.json +70 -0
  307. data/node_modules/freezerwatch/node_modules/osenv/node_modules/os-tmpdir/readme.md +36 -0
  308. data/node_modules/freezerwatch/node_modules/osenv/osenv.js +72 -0
  309. data/node_modules/freezerwatch/node_modules/osenv/package.json +76 -0
  310. data/node_modules/freezerwatch/node_modules/osenv/test/unix.js +71 -0
  311. data/node_modules/freezerwatch/node_modules/osenv/test/windows.js +74 -0
  312. data/node_modules/freezerwatch/node_modules/osenv/x.tap +39 -0
  313. data/node_modules/freezerwatch/package.json +37 -0
  314. metadata +384 -0
@@ -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,4 @@
1
+ tunnel-agent
2
+ ============
3
+
4
+ HTTP proxy tunneling agent. Formerly part of mikeal/request, now a standalone module.
@@ -0,0 +1,227 @@
1
+ 'use strict'
2
+
3
+ var net = require('net')
4
+ , tls = require('tls')
5
+ , http = require('http')
6
+ , https = require('https')
7
+ , events = require('events')
8
+ , assert = require('assert')
9
+ , util = require('util')
10
+ ;
11
+
12
+ exports.httpOverHttp = httpOverHttp
13
+ exports.httpsOverHttp = httpsOverHttp
14
+ exports.httpOverHttps = httpOverHttps
15
+ exports.httpsOverHttps = httpsOverHttps
16
+
17
+
18
+ function httpOverHttp(options) {
19
+ var agent = new TunnelingAgent(options)
20
+ agent.request = http.request
21
+ return agent
22
+ }
23
+
24
+ function httpsOverHttp(options) {
25
+ var agent = new TunnelingAgent(options)
26
+ agent.request = http.request
27
+ agent.createSocket = createSecureSocket
28
+ return agent
29
+ }
30
+
31
+ function httpOverHttps(options) {
32
+ var agent = new TunnelingAgent(options)
33
+ agent.request = https.request
34
+ return agent
35
+ }
36
+
37
+ function httpsOverHttps(options) {
38
+ var agent = new TunnelingAgent(options)
39
+ agent.request = https.request
40
+ agent.createSocket = createSecureSocket
41
+ return agent
42
+ }
43
+
44
+
45
+ function TunnelingAgent(options) {
46
+ var self = this
47
+ self.options = options || {}
48
+ self.proxyOptions = self.options.proxy || {}
49
+ self.maxSockets = self.options.maxSockets || http.Agent.defaultMaxSockets
50
+ self.requests = []
51
+ self.sockets = []
52
+
53
+ self.on('free', function onFree(socket, host, port) {
54
+ for (var i = 0, len = self.requests.length; i < len; ++i) {
55
+ var pending = self.requests[i]
56
+ if (pending.host === host && pending.port === port) {
57
+ // Detect the request to connect same origin server,
58
+ // reuse the connection.
59
+ self.requests.splice(i, 1)
60
+ pending.request.onSocket(socket)
61
+ return
62
+ }
63
+ }
64
+ socket.destroy()
65
+ self.removeSocket(socket)
66
+ })
67
+ }
68
+ util.inherits(TunnelingAgent, events.EventEmitter)
69
+
70
+ TunnelingAgent.prototype.addRequest = function addRequest(req, host, port) {
71
+ var self = this
72
+
73
+ if (self.sockets.length >= this.maxSockets) {
74
+ // We are over limit so we'll add it to the queue.
75
+ self.requests.push({host: host, port: port, request: req})
76
+ return
77
+ }
78
+
79
+ // If we are under maxSockets create a new one.
80
+ self.createSocket({host: host, port: port, request: req}, function(socket) {
81
+ socket.on('free', onFree)
82
+ socket.on('close', onCloseOrRemove)
83
+ socket.on('agentRemove', onCloseOrRemove)
84
+ req.onSocket(socket)
85
+
86
+ function onFree() {
87
+ self.emit('free', socket, host, port)
88
+ }
89
+
90
+ function onCloseOrRemove(err) {
91
+ self.removeSocket()
92
+ socket.removeListener('free', onFree)
93
+ socket.removeListener('close', onCloseOrRemove)
94
+ socket.removeListener('agentRemove', onCloseOrRemove)
95
+ }
96
+ })
97
+ }
98
+
99
+ TunnelingAgent.prototype.createSocket = function createSocket(options, cb) {
100
+ var self = this
101
+ var placeholder = {}
102
+ self.sockets.push(placeholder)
103
+
104
+ var connectOptions = mergeOptions({}, self.proxyOptions,
105
+ { method: 'CONNECT'
106
+ , path: options.host + ':' + options.port
107
+ , agent: false
108
+ }
109
+ )
110
+ if (connectOptions.proxyAuth) {
111
+ connectOptions.headers = connectOptions.headers || {}
112
+ connectOptions.headers['Proxy-Authorization'] = 'Basic ' +
113
+ new Buffer(connectOptions.proxyAuth).toString('base64')
114
+ }
115
+
116
+ debug('making CONNECT request')
117
+ var connectReq = self.request(connectOptions)
118
+ connectReq.useChunkedEncodingByDefault = false // for v0.6
119
+ connectReq.once('response', onResponse) // for v0.6
120
+ connectReq.once('upgrade', onUpgrade) // for v0.6
121
+ connectReq.once('connect', onConnect) // for v0.7 or later
122
+ connectReq.once('error', onError)
123
+ connectReq.end()
124
+
125
+ function onResponse(res) {
126
+ // Very hacky. This is necessary to avoid http-parser leaks.
127
+ res.upgrade = true
128
+ }
129
+
130
+ function onUpgrade(res, socket, head) {
131
+ // Hacky.
132
+ process.nextTick(function() {
133
+ onConnect(res, socket, head)
134
+ })
135
+ }
136
+
137
+ function onConnect(res, socket, head) {
138
+ connectReq.removeAllListeners()
139
+ socket.removeAllListeners()
140
+
141
+ if (res.statusCode === 200) {
142
+ assert.equal(head.length, 0)
143
+ debug('tunneling connection has established')
144
+ self.sockets[self.sockets.indexOf(placeholder)] = socket
145
+ cb(socket)
146
+ } else {
147
+ debug('tunneling socket could not be established, statusCode=%d', res.statusCode)
148
+ var error = new Error('tunneling socket could not be established, ' + 'statusCode=' + res.statusCode)
149
+ error.code = 'ECONNRESET'
150
+ options.request.emit('error', error)
151
+ self.removeSocket(placeholder)
152
+ }
153
+ }
154
+
155
+ function onError(cause) {
156
+ connectReq.removeAllListeners()
157
+
158
+ debug('tunneling socket could not be established, cause=%s\n', cause.message, cause.stack)
159
+ var error = new Error('tunneling socket could not be established, ' + 'cause=' + cause.message)
160
+ error.code = 'ECONNRESET'
161
+ options.request.emit('error', error)
162
+ self.removeSocket(placeholder)
163
+ }
164
+ }
165
+
166
+ TunnelingAgent.prototype.removeSocket = function removeSocket(socket) {
167
+ var pos = this.sockets.indexOf(socket)
168
+ if (pos === -1) return
169
+
170
+ this.sockets.splice(pos, 1)
171
+
172
+ var pending = this.requests.shift()
173
+ if (pending) {
174
+ // If we have pending requests and a socket gets closed a new one
175
+ // needs to be created to take over in the pool for the one that closed.
176
+ this.createSocket(pending, function(socket) {
177
+ pending.request.onSocket(socket)
178
+ })
179
+ }
180
+ }
181
+
182
+ function createSecureSocket(options, cb) {
183
+ var self = this
184
+ TunnelingAgent.prototype.createSocket.call(self, options, function(socket) {
185
+ // 0 is dummy port for v0.6
186
+ var secureSocket = tls.connect(0, mergeOptions({}, self.options,
187
+ { servername: options.host
188
+ , socket: socket
189
+ }
190
+ ))
191
+ cb(secureSocket)
192
+ })
193
+ }
194
+
195
+
196
+ function mergeOptions(target) {
197
+ for (var i = 1, len = arguments.length; i < len; ++i) {
198
+ var overrides = arguments[i]
199
+ if (typeof overrides === 'object') {
200
+ var keys = Object.keys(overrides)
201
+ for (var j = 0, keyLen = keys.length; j < keyLen; ++j) {
202
+ var k = keys[j]
203
+ if (overrides[k] !== undefined) {
204
+ target[k] = overrides[k]
205
+ }
206
+ }
207
+ }
208
+ }
209
+ return target
210
+ }
211
+
212
+
213
+ var debug
214
+ if (process.env.NODE_DEBUG && /\btunnel\b/.test(process.env.NODE_DEBUG)) {
215
+ debug = function() {
216
+ var args = Array.prototype.slice.call(arguments)
217
+ if (typeof args[0] === 'string') {
218
+ args[0] = 'TUNNEL: ' + args[0]
219
+ } else {
220
+ args.unshift('TUNNEL:')
221
+ }
222
+ console.error.apply(console, args)
223
+ }
224
+ } else {
225
+ debug = function() {}
226
+ }
227
+ exports.debug = debug // for test
@@ -0,0 +1,45 @@
1
+ {
2
+ "author": {
3
+ "name": "Mikeal Rogers",
4
+ "email": "mikeal.rogers@gmail.com",
5
+ "url": "http://www.futurealoof.com"
6
+ },
7
+ "name": "tunnel-agent",
8
+ "description": "HTTP proxy tunneling agent. Formerly part of mikeal/request, now a standalone module.",
9
+ "version": "0.3.0",
10
+ "repository": {
11
+ "url": "git+https://github.com/mikeal/tunnel-agent.git"
12
+ },
13
+ "main": "index.js",
14
+ "dependencies": {},
15
+ "devDependencies": {},
16
+ "optionalDependencies": {},
17
+ "engines": {
18
+ "node": "*"
19
+ },
20
+ "_id": "tunnel-agent@0.3.0",
21
+ "dist": {
22
+ "shasum": "ad681b68f5321ad2827c4cfb1b7d5df2cfe942ee",
23
+ "tarball": "http://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.3.0.tgz"
24
+ },
25
+ "_from": "tunnel-agent@>=0.3.0 <0.4.0",
26
+ "_npmVersion": "1.2.14",
27
+ "_npmUser": {
28
+ "name": "mikeal",
29
+ "email": "mikeal.rogers@gmail.com"
30
+ },
31
+ "maintainers": [
32
+ {
33
+ "name": "mikeal",
34
+ "email": "mikeal.rogers@gmail.com"
35
+ }
36
+ ],
37
+ "directories": {},
38
+ "_shasum": "ad681b68f5321ad2827c4cfb1b7d5df2cfe942ee",
39
+ "_resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.3.0.tgz",
40
+ "bugs": {
41
+ "url": "https://github.com/mikeal/tunnel-agent/issues"
42
+ },
43
+ "readme": "ERROR: No README data found!",
44
+ "homepage": "https://github.com/mikeal/tunnel-agent#readme"
45
+ }
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "request",
3
+ "description": "Simplified HTTP request client.",
4
+ "tags": [
5
+ "http",
6
+ "simple",
7
+ "util",
8
+ "utility"
9
+ ],
10
+ "version": "2.29.0",
11
+ "author": {
12
+ "name": "Mikeal Rogers",
13
+ "email": "mikeal.rogers@gmail.com"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+ssh://git@github.com/mikeal/request.git"
18
+ },
19
+ "bugs": {
20
+ "url": "http://github.com/mikeal/request/issues"
21
+ },
22
+ "engines": [
23
+ "node >= 0.8.0"
24
+ ],
25
+ "main": "index.js",
26
+ "dependencies": {
27
+ "qs": "~0.6.0",
28
+ "json-stringify-safe": "~5.0.0",
29
+ "forever-agent": "~0.5.0",
30
+ "node-uuid": "~1.4.0",
31
+ "mime": "~1.2.9",
32
+ "tough-cookie": "~0.9.15",
33
+ "form-data": "~0.1.0",
34
+ "tunnel-agent": "~0.3.0",
35
+ "http-signature": "~0.10.0",
36
+ "oauth-sign": "~0.3.0",
37
+ "hawk": "~1.0.0",
38
+ "aws-sign2": "~0.5.0"
39
+ },
40
+ "optionalDependencies": {
41
+ "tough-cookie": "~0.9.15",
42
+ "form-data": "~0.1.0",
43
+ "tunnel-agent": "~0.3.0",
44
+ "http-signature": "~0.10.0",
45
+ "oauth-sign": "~0.3.0",
46
+ "hawk": "~1.0.0",
47
+ "aws-sign2": "~0.5.0"
48
+ },
49
+ "scripts": {
50
+ "test": "node tests/run.js"
51
+ },
52
+ "_id": "request@2.29.0",
53
+ "dist": {
54
+ "shasum": "0d4b8de70d26a9911a8344af9a0e8edab81ff1c3",
55
+ "tarball": "http://registry.npmjs.org/request/-/request-2.29.0.tgz"
56
+ },
57
+ "_from": "request@>=2.29.0 <2.30.0",
58
+ "_npmVersion": "1.3.2",
59
+ "_npmUser": {
60
+ "name": "mikeal",
61
+ "email": "mikeal.rogers@gmail.com"
62
+ },
63
+ "maintainers": [
64
+ {
65
+ "name": "mikeal",
66
+ "email": "mikeal.rogers@gmail.com"
67
+ }
68
+ ],
69
+ "directories": {},
70
+ "_shasum": "0d4b8de70d26a9911a8344af9a0e8edab81ff1c3",
71
+ "_resolved": "https://registry.npmjs.org/request/-/request-2.29.0.tgz",
72
+ "readme": "ERROR: No README data found!",
73
+ "homepage": "https://github.com/mikeal/request#readme"
74
+ }
@@ -0,0 +1,1244 @@
1
+ var optional = require('./lib/optional')
2
+ , http = require('http')
3
+ , https = optional('https')
4
+ , tls = optional('tls')
5
+ , url = require('url')
6
+ , util = require('util')
7
+ , stream = require('stream')
8
+ , qs = require('qs')
9
+ , querystring = require('querystring')
10
+ , crypto = require('crypto')
11
+
12
+ , oauth = optional('oauth-sign')
13
+ , hawk = optional('hawk')
14
+ , aws = optional('aws-sign')
15
+ , httpSignature = optional('http-signature')
16
+ , uuid = require('node-uuid')
17
+ , mime = require('mime')
18
+ , tunnel = optional('tunnel-agent')
19
+ , _safeStringify = require('json-stringify-safe')
20
+
21
+ , ForeverAgent = require('forever-agent')
22
+ , FormData = optional('form-data')
23
+
24
+ , Cookie = optional('tough-cookie')
25
+ , CookieJar = Cookie && Cookie.CookieJar
26
+ , cookieJar = CookieJar && new CookieJar
27
+
28
+ , copy = require('./lib/copy')
29
+ , debug = require('./lib/debug')
30
+ , getSafe = require('./lib/getSafe')
31
+ ;
32
+
33
+ function safeStringify (obj) {
34
+ var ret
35
+ try { ret = JSON.stringify(obj) }
36
+ catch (e) { ret = _safeStringify(obj) }
37
+ return ret
38
+ }
39
+
40
+ var globalPool = {}
41
+ var isUrl = /^https?:/i
42
+
43
+
44
+ // Hacky fix for pre-0.4.4 https
45
+ if (https && !https.Agent) {
46
+ https.Agent = function (options) {
47
+ http.Agent.call(this, options)
48
+ }
49
+ util.inherits(https.Agent, http.Agent)
50
+ https.Agent.prototype._getConnection = function (host, port, cb) {
51
+ var s = tls.connect(port, host, this.options, function () {
52
+ // do other checks here?
53
+ if (cb) cb()
54
+ })
55
+ return s
56
+ }
57
+ }
58
+
59
+ function isReadStream (rs) {
60
+ if (rs.readable && rs.path && rs.mode) {
61
+ return true
62
+ }
63
+ }
64
+
65
+ function toBase64 (str) {
66
+ return (new Buffer(str || "", "ascii")).toString("base64")
67
+ }
68
+
69
+ function md5 (str) {
70
+ return crypto.createHash('md5').update(str).digest('hex')
71
+ }
72
+
73
+ function Request (options) {
74
+ stream.Stream.call(this)
75
+ this.readable = true
76
+ this.writable = true
77
+
78
+ if (typeof options === 'string') {
79
+ options = {uri:options}
80
+ }
81
+
82
+ var reserved = Object.keys(Request.prototype)
83
+ for (var i in options) {
84
+ if (reserved.indexOf(i) === -1) {
85
+ this[i] = options[i]
86
+ } else {
87
+ if (typeof options[i] === 'function') {
88
+ delete options[i]
89
+ }
90
+ }
91
+ }
92
+
93
+ if (options.method) {
94
+ this.explicitMethod = true
95
+ }
96
+
97
+ this.canTunnel = options.tunnel !== false && tunnel;
98
+
99
+ this.init(options)
100
+ }
101
+ util.inherits(Request, stream.Stream)
102
+ Request.prototype.init = function (options) {
103
+ // init() contains all the code to setup the request object.
104
+ // the actual outgoing request is not started until start() is called
105
+ // this function is called from both the constructor and on redirect.
106
+ var self = this
107
+ if (!options) options = {}
108
+
109
+ if (!self.method) self.method = options.method || 'GET'
110
+ self.localAddress = options.localAddress
111
+
112
+ debug(options)
113
+ if (!self.pool && self.pool !== false) self.pool = globalPool
114
+ self.dests = self.dests || []
115
+ self.__isRequestRequest = true
116
+
117
+ // Protect against double callback
118
+ if (!self._callback && self.callback) {
119
+ self._callback = self.callback
120
+ self.callback = function () {
121
+ if (self._callbackCalled) return // Print a warning maybe?
122
+ self._callbackCalled = true
123
+ self._callback.apply(self, arguments)
124
+ }
125
+ self.on('error', self.callback.bind())
126
+ self.on('complete', self.callback.bind(self, null))
127
+ }
128
+
129
+ if (self.url && !self.uri) {
130
+ // People use this property instead all the time so why not just support it.
131
+ self.uri = self.url
132
+ delete self.url
133
+ }
134
+
135
+ if (!self.uri) {
136
+ // this will throw if unhandled but is handleable when in a redirect
137
+ return self.emit('error', new Error("options.uri is a required argument"))
138
+ } else {
139
+ if (typeof self.uri == "string") self.uri = url.parse(self.uri)
140
+ }
141
+
142
+ if (self.strictSSL === false) {
143
+ self.rejectUnauthorized = false
144
+ }
145
+
146
+ if (self.proxy) {
147
+ if (typeof self.proxy == 'string') self.proxy = url.parse(self.proxy)
148
+
149
+ // do the HTTP CONNECT dance using koichik/node-tunnel
150
+ if (http.globalAgent && self.uri.protocol === "https:" && self.canTunnel) {
151
+ var tunnelFn = self.proxy.protocol === "http:"
152
+ ? tunnel.httpsOverHttp : tunnel.httpsOverHttps
153
+
154
+ var tunnelOptions = { proxy: { host: self.proxy.hostname
155
+ , port: +self.proxy.port
156
+ , proxyAuth: self.proxy.auth
157
+ , headers: { Host: self.uri.hostname + ':' +
158
+ (self.uri.port || self.uri.protocol === 'https:' ? 443 : 80) }}
159
+ , rejectUnauthorized: self.rejectUnauthorized
160
+ , ca: this.ca }
161
+
162
+ self.agent = tunnelFn(tunnelOptions)
163
+ self.tunnel = true
164
+ }
165
+ }
166
+
167
+ if (!self.uri.pathname) {self.uri.pathname = '/'}
168
+
169
+ if (!self.uri.host) {
170
+ // Invalid URI: it may generate lot of bad errors, like "TypeError: Cannot call method 'indexOf' of undefined" in CookieJar
171
+ // Detect and reject it as soon as possible
172
+ var faultyUri = url.format(self.uri)
173
+ var message = 'Invalid URI "' + faultyUri + '"'
174
+ if (Object.keys(options).length === 0) {
175
+ // No option ? This can be the sign of a redirect
176
+ // As this is a case where the user cannot do anything (they didn't call request directly with this URL)
177
+ // they should be warned that it can be caused by a redirection (can save some hair)
178
+ message += '. This can be caused by a crappy redirection.'
179
+ }
180
+ self.emit('error', new Error(message))
181
+ return // This error was fatal
182
+ }
183
+
184
+ self._redirectsFollowed = self._redirectsFollowed || 0
185
+ self.maxRedirects = (self.maxRedirects !== undefined) ? self.maxRedirects : 10
186
+ self.followRedirect = (self.followRedirect !== undefined) ? self.followRedirect : true
187
+ self.followAllRedirects = (self.followAllRedirects !== undefined) ? self.followAllRedirects : false
188
+ if (self.followRedirect || self.followAllRedirects)
189
+ self.redirects = self.redirects || []
190
+
191
+ self.headers = self.headers ? copy(self.headers) : {}
192
+
193
+ self.setHost = false
194
+ if (!self.hasHeader('host')) {
195
+ self.setHeader('host', self.uri.hostname)
196
+ if (self.uri.port) {
197
+ if ( !(self.uri.port === 80 && self.uri.protocol === 'http:') &&
198
+ !(self.uri.port === 443 && self.uri.protocol === 'https:') )
199
+ self.setHeader('host', self.getHeader('host') + (':'+self.uri.port) )
200
+ }
201
+ self.setHost = true
202
+ }
203
+
204
+ self.jar(self._jar || options.jar)
205
+
206
+ if (!self.uri.port) {
207
+ if (self.uri.protocol == 'http:') {self.uri.port = 80}
208
+ else if (self.uri.protocol == 'https:') {self.uri.port = 443}
209
+ }
210
+
211
+ if (self.proxy && !self.tunnel) {
212
+ self.port = self.proxy.port
213
+ self.host = self.proxy.hostname
214
+ } else {
215
+ self.port = self.uri.port
216
+ self.host = self.uri.hostname
217
+ }
218
+
219
+ self.clientErrorHandler = function (error) {
220
+ if (self._aborted) return
221
+ if (self.req && self.req._reusedSocket && error.code === 'ECONNRESET'
222
+ && self.agent.addRequestNoreuse) {
223
+ self.agent = { addRequest: self.agent.addRequestNoreuse.bind(self.agent) }
224
+ self.start()
225
+ self.req.end()
226
+ return
227
+ }
228
+ if (self.timeout && self.timeoutTimer) {
229
+ clearTimeout(self.timeoutTimer)
230
+ self.timeoutTimer = null
231
+ }
232
+ self.emit('error', error)
233
+ }
234
+
235
+ self._parserErrorHandler = function (error) {
236
+ if (this.res) {
237
+ if (this.res.request) {
238
+ this.res.request.emit('error', error)
239
+ } else {
240
+ this.res.emit('error', error)
241
+ }
242
+ } else {
243
+ this._httpMessage.emit('error', error)
244
+ }
245
+ }
246
+
247
+ if (options.form) {
248
+ self.form(options.form)
249
+ }
250
+
251
+ if (options.qs) self.qs(options.qs)
252
+
253
+ if (self.uri.path) {
254
+ self.path = self.uri.path
255
+ } else {
256
+ self.path = self.uri.pathname + (self.uri.search || "")
257
+ }
258
+
259
+ if (self.path.length === 0) self.path = '/'
260
+
261
+
262
+ // Auth must happen last in case signing is dependent on other headers
263
+ if (options.oauth) {
264
+ self.oauth(options.oauth)
265
+ }
266
+
267
+ if (options.aws) {
268
+ self.aws(options.aws)
269
+ }
270
+
271
+ if (options.hawk) {
272
+ self.hawk(options.hawk)
273
+ }
274
+
275
+ if (options.httpSignature) {
276
+ self.httpSignature(options.httpSignature)
277
+ }
278
+
279
+ if (options.auth) {
280
+ if (Object.prototype.hasOwnProperty.call(options.auth, 'username')) options.auth.user = options.auth.username
281
+ if (Object.prototype.hasOwnProperty.call(options.auth, 'password')) options.auth.pass = options.auth.password
282
+
283
+ self.auth(
284
+ options.auth.user,
285
+ options.auth.pass,
286
+ options.auth.sendImmediately
287
+ )
288
+ }
289
+
290
+ if (self.uri.auth && !self.hasHeader('authorization')) {
291
+ var authPieces = self.uri.auth.split(':').map(function(item){ return querystring.unescape(item) })
292
+ self.auth(authPieces[0], authPieces.slice(1).join(':'), true)
293
+ }
294
+ if (self.proxy && self.proxy.auth && !self.hasHeader('proxy-authorization') && !self.tunnel) {
295
+ self.setHeader('proxy-authorization', "Basic " + toBase64(self.proxy.auth.split(':').map(function(item){ return querystring.unescape(item)}).join(':')))
296
+ }
297
+
298
+
299
+ if (self.proxy && !self.tunnel) self.path = (self.uri.protocol + '//' + self.uri.host + self.path)
300
+
301
+ if (options.json) {
302
+ self.json(options.json)
303
+ } else if (options.multipart) {
304
+ self.boundary = uuid()
305
+ self.multipart(options.multipart)
306
+ }
307
+
308
+ if (self.body) {
309
+ var length = 0
310
+ if (!Buffer.isBuffer(self.body)) {
311
+ if (Array.isArray(self.body)) {
312
+ for (var i = 0; i < self.body.length; i++) {
313
+ length += self.body[i].length
314
+ }
315
+ } else {
316
+ self.body = new Buffer(self.body)
317
+ length = self.body.length
318
+ }
319
+ } else {
320
+ length = self.body.length
321
+ }
322
+ if (length) {
323
+ if (!self.hasHeader('content-length')) self.setHeader('content-length', length)
324
+ } else {
325
+ throw new Error('Argument error, options.body.')
326
+ }
327
+ }
328
+
329
+ var protocol = self.proxy && !self.tunnel ? self.proxy.protocol : self.uri.protocol
330
+ , defaultModules = {'http:':http, 'https:':https}
331
+ , httpModules = self.httpModules || {}
332
+ ;
333
+ self.httpModule = httpModules[protocol] || defaultModules[protocol]
334
+
335
+ if (!self.httpModule) return this.emit('error', new Error("Invalid protocol"))
336
+
337
+ if (options.ca) self.ca = options.ca
338
+
339
+ if (!self.agent) {
340
+ if (options.agentOptions) self.agentOptions = options.agentOptions
341
+
342
+ if (options.agentClass) {
343
+ self.agentClass = options.agentClass
344
+ } else if (options.forever) {
345
+ self.agentClass = protocol === 'http:' ? ForeverAgent : ForeverAgent.SSL
346
+ } else {
347
+ self.agentClass = self.httpModule.Agent
348
+ }
349
+ }
350
+
351
+ if (self.pool === false) {
352
+ self.agent = false
353
+ } else {
354
+ self.agent = self.agent || self.getAgent()
355
+ if (self.maxSockets) {
356
+ // Don't use our pooling if node has the refactored client
357
+ self.agent.maxSockets = self.maxSockets
358
+ }
359
+ if (self.pool.maxSockets) {
360
+ // Don't use our pooling if node has the refactored client
361
+ self.agent.maxSockets = self.pool.maxSockets
362
+ }
363
+ }
364
+
365
+ self.on('pipe', function (src) {
366
+ if (self.ntick && self._started) throw new Error("You cannot pipe to this stream after the outbound request has started.")
367
+ self.src = src
368
+ if (isReadStream(src)) {
369
+ if (!self.hasHeader('content-type')) self.setHeader('content-type', mime.lookup(src.path))
370
+ } else {
371
+ if (src.headers) {
372
+ for (var i in src.headers) {
373
+ if (!self.hasHeader(i)) {
374
+ self.setHeader(i, src.headers[i])
375
+ }
376
+ }
377
+ }
378
+ if (self._json && !self.hasHeader('content-type'))
379
+ self.setHeader('content-type', 'application/json')
380
+ if (src.method && !self.explicitMethod) {
381
+ self.method = src.method
382
+ }
383
+ }
384
+
385
+ // self.on('pipe', function () {
386
+ // console.error("You have already piped to this stream. Pipeing twice is likely to break the request.")
387
+ // })
388
+ })
389
+
390
+ process.nextTick(function () {
391
+ if (self._aborted) return
392
+
393
+ if (self._form) {
394
+ self.setHeaders(self._form.getHeaders())
395
+ self._form.pipe(self)
396
+ }
397
+ if (self.body) {
398
+ if (Array.isArray(self.body)) {
399
+ self.body.forEach(function (part) {
400
+ self.write(part)
401
+ })
402
+ } else {
403
+ self.write(self.body)
404
+ }
405
+ self.end()
406
+ } else if (self.requestBodyStream) {
407
+ console.warn("options.requestBodyStream is deprecated, please pass the request object to stream.pipe.")
408
+ self.requestBodyStream.pipe(self)
409
+ } else if (!self.src) {
410
+ if (self.method !== 'GET' && typeof self.method !== 'undefined') {
411
+ self.setHeader('content-length', 0)
412
+ }
413
+ self.end()
414
+ }
415
+ self.ntick = true
416
+ })
417
+ }
418
+
419
+ // Must call this when following a redirect from https to http or vice versa
420
+ // Attempts to keep everything as identical as possible, but update the
421
+ // httpModule, Tunneling agent, and/or Forever Agent in use.
422
+ Request.prototype._updateProtocol = function () {
423
+ var self = this
424
+ var protocol = self.uri.protocol
425
+
426
+ if (protocol === 'https:') {
427
+ // previously was doing http, now doing https
428
+ // if it's https, then we might need to tunnel now.
429
+ if (self.proxy && self.canTunnel) {
430
+ self.tunnel = true
431
+ var tunnelFn = self.proxy.protocol === 'http:'
432
+ ? tunnel.httpsOverHttp : tunnel.httpsOverHttps
433
+ var tunnelOptions = { proxy: { host: self.proxy.hostname
434
+ , port: +self.proxy.port
435
+ , proxyAuth: self.proxy.auth }
436
+ , rejectUnauthorized: self.rejectUnauthorized
437
+ , ca: self.ca }
438
+ self.agent = tunnelFn(tunnelOptions)
439
+ return
440
+ }
441
+
442
+ self.httpModule = https
443
+ switch (self.agentClass) {
444
+ case ForeverAgent:
445
+ self.agentClass = ForeverAgent.SSL
446
+ break
447
+ case http.Agent:
448
+ self.agentClass = https.Agent
449
+ break
450
+ default:
451
+ // nothing we can do. Just hope for the best.
452
+ return
453
+ }
454
+
455
+ // if there's an agent, we need to get a new one.
456
+ if (self.agent) self.agent = self.getAgent()
457
+
458
+ } else {
459
+ // previously was doing https, now doing http
460
+ // stop any tunneling.
461
+ if (self.tunnel) self.tunnel = false
462
+ self.httpModule = http
463
+ switch (self.agentClass) {
464
+ case ForeverAgent.SSL:
465
+ self.agentClass = ForeverAgent
466
+ break
467
+ case https.Agent:
468
+ self.agentClass = http.Agent
469
+ break
470
+ default:
471
+ // nothing we can do. just hope for the best
472
+ return
473
+ }
474
+
475
+ // if there's an agent, then get a new one.
476
+ if (self.agent) {
477
+ self.agent = null
478
+ self.agent = self.getAgent()
479
+ }
480
+ }
481
+ }
482
+
483
+ Request.prototype.getAgent = function () {
484
+ var Agent = this.agentClass
485
+ var options = {}
486
+ if (this.agentOptions) {
487
+ for (var i in this.agentOptions) {
488
+ options[i] = this.agentOptions[i]
489
+ }
490
+ }
491
+ if (this.ca) options.ca = this.ca
492
+ if (this.ciphers) options.ciphers = this.ciphers
493
+ if (this.secureProtocol) options.secureProtocol = this.secureProtocol
494
+ if (typeof this.rejectUnauthorized !== 'undefined') options.rejectUnauthorized = this.rejectUnauthorized
495
+
496
+ if (this.cert && this.key) {
497
+ options.key = this.key
498
+ options.cert = this.cert
499
+ }
500
+
501
+ var poolKey = ''
502
+
503
+ // different types of agents are in different pools
504
+ if (Agent !== this.httpModule.Agent) {
505
+ poolKey += Agent.name
506
+ }
507
+
508
+ if (!this.httpModule.globalAgent) {
509
+ // node 0.4.x
510
+ options.host = this.host
511
+ options.port = this.port
512
+ if (poolKey) poolKey += ':'
513
+ poolKey += this.host + ':' + this.port
514
+ }
515
+
516
+ // ca option is only relevant if proxy or destination are https
517
+ var proxy = this.proxy
518
+ if (typeof proxy === 'string') proxy = url.parse(proxy)
519
+ var isHttps = (proxy && proxy.protocol === 'https:') || this.uri.protocol === 'https:'
520
+ if (isHttps) {
521
+ if (options.ca) {
522
+ if (poolKey) poolKey += ':'
523
+ poolKey += options.ca
524
+ }
525
+
526
+ if (typeof options.rejectUnauthorized !== 'undefined') {
527
+ if (poolKey) poolKey += ':'
528
+ poolKey += options.rejectUnauthorized
529
+ }
530
+
531
+ if (options.cert)
532
+ poolKey += options.cert.toString('ascii') + options.key.toString('ascii')
533
+
534
+ if (options.ciphers) {
535
+ if (poolKey) poolKey += ':'
536
+ poolKey += options.ciphers
537
+ }
538
+
539
+ if (options.secureProtocol) {
540
+ if (poolKey) poolKey += ':'
541
+ poolKey += options.secureProtocol
542
+ }
543
+ }
544
+
545
+ if (this.pool === globalPool && !poolKey && Object.keys(options).length === 0 && this.httpModule.globalAgent) {
546
+ // not doing anything special. Use the globalAgent
547
+ return this.httpModule.globalAgent
548
+ }
549
+
550
+ // we're using a stored agent. Make sure it's protocol-specific
551
+ poolKey = this.uri.protocol + poolKey
552
+
553
+ // already generated an agent for this setting
554
+ if (this.pool[poolKey]) return this.pool[poolKey]
555
+
556
+ return this.pool[poolKey] = new Agent(options)
557
+ }
558
+
559
+ Request.prototype.start = function () {
560
+ // start() is called once we are ready to send the outgoing HTTP request.
561
+ // this is usually called on the first write(), end() or on nextTick()
562
+ var self = this
563
+
564
+ if (self._aborted) return
565
+
566
+ self._started = true
567
+ self.method = self.method || 'GET'
568
+ self.href = self.uri.href
569
+
570
+ if (self.src && self.src.stat && self.src.stat.size && !self.hasHeader('content-length')) {
571
+ self.setHeader('content-length', self.src.stat.size)
572
+ }
573
+ if (self._aws) {
574
+ self.aws(self._aws, true)
575
+ }
576
+
577
+ // We have a method named auth, which is completely different from the http.request
578
+ // auth option. If we don't remove it, we're gonna have a bad time.
579
+ var reqOptions = copy(self)
580
+ delete reqOptions.auth
581
+
582
+ debug('make request', self.uri.href)
583
+ self.req = self.httpModule.request(reqOptions, self.onResponse.bind(self))
584
+
585
+ if (self.timeout && !self.timeoutTimer) {
586
+ self.timeoutTimer = setTimeout(function () {
587
+ self.req.abort()
588
+ var e = new Error("ETIMEDOUT")
589
+ e.code = "ETIMEDOUT"
590
+ self.emit("error", e)
591
+ }, self.timeout)
592
+
593
+ // Set additional timeout on socket - in case if remote
594
+ // server freeze after sending headers
595
+ if (self.req.setTimeout) { // only works on node 0.6+
596
+ self.req.setTimeout(self.timeout, function () {
597
+ if (self.req) {
598
+ self.req.abort()
599
+ var e = new Error("ESOCKETTIMEDOUT")
600
+ e.code = "ESOCKETTIMEDOUT"
601
+ self.emit("error", e)
602
+ }
603
+ })
604
+ }
605
+ }
606
+
607
+ self.req.on('error', self.clientErrorHandler)
608
+ self.req.on('drain', function() {
609
+ self.emit('drain')
610
+ })
611
+ self.on('end', function() {
612
+ if ( self.req.connection ) self.req.connection.removeListener('error', self._parserErrorHandler)
613
+ })
614
+ self.emit('request', self.req)
615
+ }
616
+ Request.prototype.onResponse = function (response) {
617
+ var self = this
618
+ debug('onResponse', self.uri.href, response.statusCode, response.headers)
619
+ response.on('end', function() {
620
+ debug('response end', self.uri.href, response.statusCode, response.headers)
621
+ });
622
+
623
+ if (response.connection.listeners('error').indexOf(self._parserErrorHandler) === -1) {
624
+ response.connection.once('error', self._parserErrorHandler)
625
+ }
626
+ if (self._aborted) {
627
+ debug('aborted', self.uri.href)
628
+ response.resume()
629
+ return
630
+ }
631
+ if (self._paused) response.pause()
632
+ else response.resume()
633
+
634
+ self.response = response
635
+ response.request = self
636
+ response.toJSON = toJSON
637
+
638
+ // XXX This is different on 0.10, because SSL is strict by default
639
+ if (self.httpModule === https &&
640
+ self.strictSSL &&
641
+ !response.client.authorized) {
642
+ debug('strict ssl error', self.uri.href)
643
+ var sslErr = response.client.authorizationError
644
+ self.emit('error', new Error('SSL Error: '+ sslErr))
645
+ return
646
+ }
647
+
648
+ if (self.setHost && self.hasHeader('host')) delete self.headers[self.hasHeader('host')]
649
+ if (self.timeout && self.timeoutTimer) {
650
+ clearTimeout(self.timeoutTimer)
651
+ self.timeoutTimer = null
652
+ }
653
+
654
+ var addCookie = function (cookie) {
655
+ if (self._jar){
656
+ var targetCookieJar = self._jar.setCookie?self._jar:cookieJar;
657
+
658
+ //set the cookie if it's domain in the href's domain.
659
+ targetCookieJar.setCookie(cookie, self.uri.href, function(err){
660
+ if (err){
661
+ console.warn('set cookie failed,'+ err)
662
+ }
663
+ })
664
+ }
665
+
666
+ }
667
+
668
+ if (hasHeader('set-cookie', response.headers) && (!self._disableCookies)) {
669
+ var headerName = hasHeader('set-cookie', response.headers)
670
+ if (Array.isArray(response.headers[headerName])) response.headers[headerName].forEach(addCookie)
671
+ else addCookie(response.headers[headerName])
672
+ }
673
+
674
+ var redirectTo = null
675
+ if (response.statusCode >= 300 && response.statusCode < 400 && hasHeader('location', response.headers)) {
676
+ var location = response.headers[hasHeader('location', response.headers)]
677
+ debug('redirect', location)
678
+
679
+ if (self.followAllRedirects) {
680
+ redirectTo = location
681
+ } else if (self.followRedirect) {
682
+ switch (self.method) {
683
+ case 'PATCH':
684
+ case 'PUT':
685
+ case 'POST':
686
+ case 'DELETE':
687
+ // Do not follow redirects
688
+ break
689
+ default:
690
+ redirectTo = location
691
+ break
692
+ }
693
+ }
694
+ } else if (response.statusCode == 401 && self._hasAuth && !self._sentAuth) {
695
+ var authHeader = response.headers[hasHeader('www-authenticate', response.headers)]
696
+ var authVerb = authHeader && authHeader.split(' ')[0]
697
+ debug('reauth', authVerb)
698
+
699
+ switch (authVerb) {
700
+ case 'Basic':
701
+ self.auth(self._user, self._pass, true)
702
+ redirectTo = self.uri
703
+ break
704
+
705
+ case 'Digest':
706
+ // TODO: More complete implementation of RFC 2617. For reference:
707
+ // http://tools.ietf.org/html/rfc2617#section-3
708
+ // https://github.com/bagder/curl/blob/master/lib/http_digest.c
709
+
710
+ var matches = authHeader.match(/([a-z0-9_-]+)="([^"]+)"/gi)
711
+ var challenge = {}
712
+
713
+ for (var i = 0; i < matches.length; i++) {
714
+ var eqPos = matches[i].indexOf('=')
715
+ var key = matches[i].substring(0, eqPos)
716
+ var quotedValue = matches[i].substring(eqPos + 1)
717
+ challenge[key] = quotedValue.substring(1, quotedValue.length - 1)
718
+ }
719
+
720
+ var ha1 = md5(self._user + ':' + challenge.realm + ':' + self._pass)
721
+ var ha2 = md5(self.method + ':' + self.uri.path)
722
+ var cnonce = uuid().replace(/-/g, '')
723
+ var digestResponse = md5(ha1 + ':' + challenge.nonce + ':1:' + cnonce + ':auth:' + ha2)
724
+ var authValues = {
725
+ username: self._user,
726
+ realm: challenge.realm,
727
+ nonce: challenge.nonce,
728
+ uri: self.uri.path,
729
+ qop: challenge.qop,
730
+ response: digestResponse,
731
+ nc: 1,
732
+ cnonce: cnonce
733
+ }
734
+
735
+ authHeader = []
736
+ for (var k in authValues) {
737
+ authHeader.push(k + '="' + authValues[k] + '"')
738
+ }
739
+ authHeader = 'Digest ' + authHeader.join(', ')
740
+ self.setHeader('authorization', authHeader)
741
+ self._sentAuth = true
742
+
743
+ redirectTo = self.uri
744
+ break
745
+ }
746
+ }
747
+
748
+ if (redirectTo) {
749
+ debug('redirect to', redirectTo)
750
+
751
+ // ignore any potential response body. it cannot possibly be useful
752
+ // to us at this point.
753
+ if (self._paused) response.resume()
754
+
755
+ if (self._redirectsFollowed >= self.maxRedirects) {
756
+ self.emit('error', new Error("Exceeded maxRedirects. Probably stuck in a redirect loop "+self.uri.href))
757
+ return
758
+ }
759
+ self._redirectsFollowed += 1
760
+
761
+ if (!isUrl.test(redirectTo)) {
762
+ redirectTo = url.resolve(self.uri.href, redirectTo)
763
+ }
764
+
765
+ var uriPrev = self.uri
766
+ self.uri = url.parse(redirectTo)
767
+
768
+ // handle the case where we change protocol from https to http or vice versa
769
+ if (self.uri.protocol !== uriPrev.protocol) {
770
+ self._updateProtocol()
771
+ }
772
+
773
+ self.redirects.push(
774
+ { statusCode : response.statusCode
775
+ , redirectUri: redirectTo
776
+ }
777
+ )
778
+ if (self.followAllRedirects && response.statusCode != 401) self.method = 'GET'
779
+ // self.method = 'GET' // Force all redirects to use GET || commented out fixes #215
780
+ delete self.src
781
+ delete self.req
782
+ delete self.agent
783
+ delete self._started
784
+ if (response.statusCode != 401) {
785
+ // Remove parameters from the previous response, unless this is the second request
786
+ // for a server that requires digest authentication.
787
+ delete self.body
788
+ delete self._form
789
+ if (self.headers) {
790
+ if (self.hasHeader('host')) delete self.headers[self.hasHeader('host')]
791
+ if (self.hasHeader('content-type')) delete self.headers[self.hasHeader('content-type')]
792
+ if (self.hasHeader('content-length')) delete self.headers[self.hasHeader('content-length')]
793
+ }
794
+ }
795
+
796
+ self.emit('redirect');
797
+
798
+ self.init()
799
+ return // Ignore the rest of the response
800
+ } else {
801
+ self._redirectsFollowed = self._redirectsFollowed || 0
802
+ // Be a good stream and emit end when the response is finished.
803
+ // Hack to emit end on close because of a core bug that never fires end
804
+ response.on('close', function () {
805
+ if (!self._ended) self.response.emit('end')
806
+ })
807
+
808
+ if (self.encoding) {
809
+ if (self.dests.length !== 0) {
810
+ console.error("Ignoring encoding parameter as this stream is being piped to another stream which makes the encoding option invalid.")
811
+ } else {
812
+ response.setEncoding(self.encoding)
813
+ }
814
+ }
815
+
816
+ self.emit('response', response)
817
+
818
+ self.dests.forEach(function (dest) {
819
+ self.pipeDest(dest)
820
+ })
821
+
822
+ response.on("data", function (chunk) {
823
+ self._destdata = true
824
+ self.emit("data", chunk)
825
+ })
826
+ response.on("end", function (chunk) {
827
+ self._ended = true
828
+ self.emit("end", chunk)
829
+ })
830
+ response.on("close", function () {self.emit("close")})
831
+
832
+ if (self.callback) {
833
+ var buffer = []
834
+ var bodyLen = 0
835
+ self.on("data", function (chunk) {
836
+ buffer.push(chunk)
837
+ bodyLen += chunk.length
838
+ })
839
+ self.on("end", function () {
840
+ debug('end event', self.uri.href)
841
+ if (self._aborted) {
842
+ debug('aborted', self.uri.href)
843
+ return
844
+ }
845
+
846
+ if (buffer.length && Buffer.isBuffer(buffer[0])) {
847
+ debug('has body', self.uri.href, bodyLen)
848
+ var body = new Buffer(bodyLen)
849
+ var i = 0
850
+ buffer.forEach(function (chunk) {
851
+ chunk.copy(body, i, 0, chunk.length)
852
+ i += chunk.length
853
+ })
854
+ if (self.encoding === null) {
855
+ response.body = body
856
+ } else {
857
+ response.body = body.toString(self.encoding)
858
+ }
859
+ } else if (buffer.length) {
860
+ // The UTF8 BOM [0xEF,0xBB,0xBF] is converted to [0xFE,0xFF] in the JS UTC16/UCS2 representation.
861
+ // Strip this value out when the encoding is set to 'utf8', as upstream consumers won't expect it and it breaks JSON.parse().
862
+ if (self.encoding === 'utf8' && buffer[0].length > 0 && buffer[0][0] === "\uFEFF") {
863
+ buffer[0] = buffer[0].substring(1)
864
+ }
865
+ response.body = buffer.join('')
866
+ }
867
+
868
+ if (self._json) {
869
+ try {
870
+ response.body = JSON.parse(response.body)
871
+ } catch (e) {}
872
+ }
873
+ debug('emitting complete', self.uri.href)
874
+ if(response.body == undefined && !self._json) {
875
+ response.body = "";
876
+ }
877
+ self.emit('complete', response, response.body)
878
+ })
879
+ }
880
+ //if no callback
881
+ else{
882
+ self.on("end", function () {
883
+ if (self._aborted) {
884
+ debug('aborted', self.uri.href)
885
+ return
886
+ }
887
+ self.emit('complete', response);
888
+ });
889
+ }
890
+ }
891
+ debug('finish init function', self.uri.href)
892
+ }
893
+
894
+ Request.prototype.abort = function () {
895
+ this._aborted = true
896
+
897
+ if (this.req) {
898
+ this.req.abort()
899
+ }
900
+ else if (this.response) {
901
+ this.response.abort()
902
+ }
903
+
904
+ this.emit("abort")
905
+ }
906
+
907
+ Request.prototype.pipeDest = function (dest) {
908
+ var response = this.response
909
+ // Called after the response is received
910
+ if (dest.headers && !dest.headersSent) {
911
+ if (hasHeader('content-type', response.headers)) {
912
+ var ctname = hasHeader('content-type', response.headers)
913
+ if (dest.setHeader) dest.setHeader(ctname, response.headers[ctname])
914
+ else dest.headers[ctname] = response.headers[ctname]
915
+ }
916
+
917
+ if (hasHeader('content-length', response.headers)) {
918
+ var clname = hasHeader('content-length', response.headers)
919
+ if (dest.setHeader) dest.setHeader(clname, response.headers[clname])
920
+ else dest.headers[clname] = response.headers[clname]
921
+ }
922
+ }
923
+ if (dest.setHeader && !dest.headersSent) {
924
+ for (var i in response.headers) {
925
+ dest.setHeader(i, response.headers[i])
926
+ }
927
+ dest.statusCode = response.statusCode
928
+ }
929
+ if (this.pipefilter) this.pipefilter(response, dest)
930
+ }
931
+
932
+ // Composable API
933
+ Request.prototype.setHeader = function (name, value, clobber) {
934
+ if (clobber === undefined) clobber = true
935
+ if (clobber || !this.hasHeader(name)) this.headers[name] = value
936
+ else this.headers[this.hasHeader(name)] += ',' + value
937
+ return this
938
+ }
939
+ Request.prototype.setHeaders = function (headers) {
940
+ for (var i in headers) {this.setHeader(i, headers[i])}
941
+ return this
942
+ }
943
+ Request.prototype.hasHeader = function (header, headers) {
944
+ var headers = Object.keys(headers || this.headers)
945
+ , lheaders = headers.map(function (h) {return h.toLowerCase()})
946
+ ;
947
+ header = header.toLowerCase()
948
+ for (var i=0;i<lheaders.length;i++) {
949
+ if (lheaders[i] === header) return headers[i]
950
+ }
951
+ return false
952
+ }
953
+
954
+ var hasHeader = Request.prototype.hasHeader
955
+
956
+ Request.prototype.qs = function (q, clobber) {
957
+ var base
958
+ if (!clobber && this.uri.query) base = qs.parse(this.uri.query)
959
+ else base = {}
960
+
961
+ for (var i in q) {
962
+ base[i] = q[i]
963
+ }
964
+
965
+ if (qs.stringify(base) === ''){
966
+ return this
967
+ }
968
+
969
+ this.uri = url.parse(this.uri.href.split('?')[0] + '?' + qs.stringify(base))
970
+ this.url = this.uri
971
+ this.path = this.uri.path
972
+
973
+ return this
974
+ }
975
+ Request.prototype.form = function (form) {
976
+ if (form) {
977
+ this.setHeader('content-type', 'application/x-www-form-urlencoded; charset=utf-8')
978
+ this.body = qs.stringify(form).toString('utf8')
979
+ return this
980
+ }
981
+ // create form-data object
982
+ this._form = new FormData()
983
+ return this._form
984
+ }
985
+ Request.prototype.multipart = function (multipart) {
986
+ var self = this
987
+ self.body = []
988
+
989
+ if (!self.hasHeader('content-type')) {
990
+ self.setHeader('content-type', 'multipart/related; boundary=' + self.boundary)
991
+ } else {
992
+ var headerName = self.hasHeader('content-type');
993
+ self.setHeader(headerName, self.headers[headerName].split(';')[0] + '; boundary=' + self.boundary)
994
+ }
995
+
996
+ if (!multipart.forEach) throw new Error('Argument error, options.multipart.')
997
+
998
+ if (self.preambleCRLF) {
999
+ self.body.push(new Buffer('\r\n'))
1000
+ }
1001
+
1002
+ multipart.forEach(function (part) {
1003
+ var body = part.body
1004
+ if(body == null) throw Error('Body attribute missing in multipart.')
1005
+ delete part.body
1006
+ var preamble = '--' + self.boundary + '\r\n'
1007
+ Object.keys(part).forEach(function (key) {
1008
+ preamble += key + ': ' + part[key] + '\r\n'
1009
+ })
1010
+ preamble += '\r\n'
1011
+ self.body.push(new Buffer(preamble))
1012
+ self.body.push(new Buffer(body))
1013
+ self.body.push(new Buffer('\r\n'))
1014
+ })
1015
+ self.body.push(new Buffer('--' + self.boundary + '--'))
1016
+ return self
1017
+ }
1018
+ Request.prototype.json = function (val) {
1019
+ var self = this
1020
+
1021
+ if (!self.hasHeader('accept')) self.setHeader('accept', 'application/json')
1022
+
1023
+ this._json = true
1024
+ if (typeof val === 'boolean') {
1025
+ if (typeof this.body === 'object') {
1026
+ this.body = safeStringify(this.body)
1027
+ self.setHeader('content-type', 'application/json')
1028
+ }
1029
+ } else {
1030
+ this.body = safeStringify(val)
1031
+ self.setHeader('content-type', 'application/json')
1032
+ }
1033
+ return this
1034
+ }
1035
+ Request.prototype.getHeader = function (name, headers) {
1036
+ var result, re, match
1037
+ if (!headers) headers = this.headers
1038
+ Object.keys(headers).forEach(function (key) {
1039
+ re = new RegExp(name, 'i')
1040
+ match = key.match(re)
1041
+ if (match) result = headers[key]
1042
+ })
1043
+ return result
1044
+ }
1045
+ var getHeader = Request.prototype.getHeader
1046
+
1047
+ Request.prototype.auth = function (user, pass, sendImmediately) {
1048
+ if (typeof user !== 'string' || (pass !== undefined && typeof pass !== 'string')) {
1049
+ throw new Error('auth() received invalid user or password')
1050
+ }
1051
+ this._user = user
1052
+ this._pass = pass
1053
+ this._hasAuth = true
1054
+ var header = typeof pass !== 'undefined' ? user + ':' + pass : user
1055
+ if (sendImmediately || typeof sendImmediately == 'undefined') {
1056
+ this.setHeader('authorization', 'Basic ' + toBase64(header))
1057
+ this._sentAuth = true
1058
+ }
1059
+ return this
1060
+ }
1061
+ Request.prototype.aws = function (opts, now) {
1062
+ if (!now) {
1063
+ this._aws = opts
1064
+ return this
1065
+ }
1066
+ var date = new Date()
1067
+ this.setHeader('date', date.toUTCString())
1068
+ var auth =
1069
+ { key: opts.key
1070
+ , secret: opts.secret
1071
+ , verb: this.method.toUpperCase()
1072
+ , date: date
1073
+ , contentType: this.getHeader('content-type') || ''
1074
+ , md5: this.getHeader('content-md5') || ''
1075
+ , amazonHeaders: aws.canonicalizeHeaders(this.headers)
1076
+ }
1077
+ if (opts.bucket && this.path) {
1078
+ auth.resource = '/' + opts.bucket + this.path
1079
+ } else if (opts.bucket && !this.path) {
1080
+ auth.resource = '/' + opts.bucket
1081
+ } else if (!opts.bucket && this.path) {
1082
+ auth.resource = this.path
1083
+ } else if (!opts.bucket && !this.path) {
1084
+ auth.resource = '/'
1085
+ }
1086
+ auth.resource = aws.canonicalizeResource(auth.resource)
1087
+ this.setHeader('authorization', aws.authorization(auth))
1088
+
1089
+ return this
1090
+ }
1091
+ Request.prototype.httpSignature = function (opts) {
1092
+ var req = this
1093
+ httpSignature.signRequest({
1094
+ getHeader: function(header) {
1095
+ return getHeader(header, req.headers)
1096
+ },
1097
+ setHeader: function(header, value) {
1098
+ req.setHeader(header, value)
1099
+ },
1100
+ method: this.method,
1101
+ path: this.path
1102
+ }, opts)
1103
+ debug('httpSignature authorization', this.getHeader('authorization'))
1104
+
1105
+ return this
1106
+ }
1107
+
1108
+ Request.prototype.hawk = function (opts) {
1109
+ this.setHeader('Authorization', hawk.client.header(this.uri, this.method, opts).field)
1110
+ }
1111
+
1112
+ Request.prototype.oauth = function (_oauth) {
1113
+ var form
1114
+ if (this.hasHeader('content-type') &&
1115
+ this.getHeader('content-type').slice(0, 'application/x-www-form-urlencoded'.length) ===
1116
+ 'application/x-www-form-urlencoded'
1117
+ ) {
1118
+ form = qs.parse(this.body)
1119
+ }
1120
+ if (this.uri.query) {
1121
+ form = qs.parse(this.uri.query)
1122
+ }
1123
+ if (!form) form = {}
1124
+ var oa = {}
1125
+ for (var i in form) oa[i] = form[i]
1126
+ for (var i in _oauth) oa['oauth_'+i] = _oauth[i]
1127
+ if (!oa.oauth_version) oa.oauth_version = '1.0'
1128
+ if (!oa.oauth_timestamp) oa.oauth_timestamp = Math.floor( Date.now() / 1000 ).toString()
1129
+ if (!oa.oauth_nonce) oa.oauth_nonce = uuid().replace(/-/g, '')
1130
+
1131
+ oa.oauth_signature_method = 'HMAC-SHA1'
1132
+
1133
+ var consumer_secret = oa.oauth_consumer_secret
1134
+ delete oa.oauth_consumer_secret
1135
+ var token_secret = oa.oauth_token_secret
1136
+ delete oa.oauth_token_secret
1137
+ var timestamp = oa.oauth_timestamp
1138
+
1139
+ var baseurl = this.uri.protocol + '//' + this.uri.host + this.uri.pathname
1140
+ var signature = oauth.hmacsign(this.method, baseurl, oa, consumer_secret, token_secret)
1141
+
1142
+ // oa.oauth_signature = signature
1143
+ for (var i in form) {
1144
+ if ( i.slice(0, 'oauth_') in _oauth) {
1145
+ // skip
1146
+ } else {
1147
+ delete oa['oauth_'+i]
1148
+ if (i !== 'x_auth_mode') delete oa[i]
1149
+ }
1150
+ }
1151
+ oa.oauth_timestamp = timestamp
1152
+ var authHeader = 'OAuth '+Object.keys(oa).sort().map(function (i) {return i+'="'+oauth.rfc3986(oa[i])+'"'}).join(',')
1153
+ authHeader += ',oauth_signature="' + oauth.rfc3986(signature) + '"'
1154
+ this.setHeader('Authorization', authHeader)
1155
+ return this
1156
+ }
1157
+ Request.prototype.jar = function (jar) {
1158
+ var cookies
1159
+
1160
+ if (this._redirectsFollowed === 0) {
1161
+ this.originalCookieHeader = this.getHeader('cookie')
1162
+ }
1163
+
1164
+ if (!jar) {
1165
+ // disable cookies
1166
+ cookies = false
1167
+ this._disableCookies = true
1168
+ } else {
1169
+ var targetCookieJar = (jar && jar.getCookieString)?jar:cookieJar;
1170
+ var urihref = this.uri.href
1171
+
1172
+ //fetch cookie in the Specified host
1173
+ targetCookieJar.getCookieString(urihref, function(err, hrefCookie){
1174
+ if (err){
1175
+ console.warn('get cookieString failed,' +err)
1176
+ } else {
1177
+ cookies = hrefCookie
1178
+ }
1179
+ })
1180
+
1181
+ }
1182
+
1183
+ //if need cookie and cookie is not empty
1184
+ if (cookies && cookies.length) {
1185
+ if (this.originalCookieHeader) {
1186
+ // Don't overwrite existing Cookie header
1187
+ this.setHeader('cookie', this.originalCookieHeader + '; ' + cookies)
1188
+ } else {
1189
+ this.setHeader('cookie', cookies)
1190
+ }
1191
+ }
1192
+ this._jar = jar
1193
+ return this
1194
+ }
1195
+
1196
+
1197
+ // Stream API
1198
+ Request.prototype.pipe = function (dest, opts) {
1199
+ if (this.response) {
1200
+ if (this._destdata) {
1201
+ throw new Error("You cannot pipe after data has been emitted from the response.")
1202
+ } else if (this._ended) {
1203
+ throw new Error("You cannot pipe after the response has been ended.")
1204
+ } else {
1205
+ stream.Stream.prototype.pipe.call(this, dest, opts)
1206
+ this.pipeDest(dest)
1207
+ return dest
1208
+ }
1209
+ } else {
1210
+ this.dests.push(dest)
1211
+ stream.Stream.prototype.pipe.call(this, dest, opts)
1212
+ return dest
1213
+ }
1214
+ }
1215
+ Request.prototype.write = function () {
1216
+ if (!this._started) this.start()
1217
+ return this.req.write.apply(this.req, arguments)
1218
+ }
1219
+ Request.prototype.end = function (chunk) {
1220
+ if (chunk) this.write(chunk)
1221
+ if (!this._started) this.start()
1222
+ this.req.end()
1223
+ }
1224
+ Request.prototype.pause = function () {
1225
+ if (!this.response) this._paused = true
1226
+ else this.response.pause.apply(this.response, arguments)
1227
+ }
1228
+ Request.prototype.resume = function () {
1229
+ if (!this.response) this._paused = false
1230
+ else this.response.resume.apply(this.response, arguments)
1231
+ }
1232
+ Request.prototype.destroy = function () {
1233
+ if (!this._ended) this.end()
1234
+ else if (this.response) this.response.destroy()
1235
+ }
1236
+
1237
+ function toJSON () {
1238
+ return getSafe(this, '__' + (((1+Math.random())*0x10000)|0).toString(16))
1239
+ }
1240
+
1241
+ Request.prototype.toJSON = toJSON
1242
+
1243
+
1244
+ module.exports = Request