ruby_on_ruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (493) hide show
  1. data/.gitignore +18 -0
  2. data/.rvmrc +1 -0
  3. data/Gemfile +6 -0
  4. data/LICENSE +22 -0
  5. data/README.md +66 -0
  6. data/Rakefile +1 -0
  7. data/lib/ruby_on_ruby.rb +5 -0
  8. data/lib/ruby_on_ruby/console.rb +7 -0
  9. data/lib/ruby_on_ruby/context.rb +33 -0
  10. data/lib/ruby_on_ruby/file_loader.rb +31 -0
  11. data/lib/ruby_on_ruby/ruby_stream.rb +27 -0
  12. data/lib/ruby_on_ruby/version.rb +3 -0
  13. data/lib/rubyonruby.rb +1 -0
  14. data/ruby_in_ruby.gemspec +19 -0
  15. data/vendor/javascripts/emscripted-ruby/lib/.document +106 -0
  16. data/vendor/javascripts/emscripted-ruby/lib/English.rb +155 -0
  17. data/vendor/javascripts/emscripted-ruby/lib/Env.rb +18 -0
  18. data/vendor/javascripts/emscripted-ruby/lib/README +96 -0
  19. data/vendor/javascripts/emscripted-ruby/lib/abbrev.rb +103 -0
  20. data/vendor/javascripts/emscripted-ruby/lib/base64.rb +133 -0
  21. data/vendor/javascripts/emscripted-ruby/lib/benchmark.rb +572 -0
  22. data/vendor/javascripts/emscripted-ruby/lib/cgi-lib.rb +272 -0
  23. data/vendor/javascripts/emscripted-ruby/lib/cgi.rb +2308 -0
  24. data/vendor/javascripts/emscripted-ruby/lib/cgi/.document +2 -0
  25. data/vendor/javascripts/emscripted-ruby/lib/cgi/session.rb +498 -0
  26. data/vendor/javascripts/emscripted-ruby/lib/cgi/session/pstore.rb +111 -0
  27. data/vendor/javascripts/emscripted-ruby/lib/complex.rb +663 -0
  28. data/vendor/javascripts/emscripted-ruby/lib/csv.rb +992 -0
  29. data/vendor/javascripts/emscripted-ruby/lib/date.rb +1767 -0
  30. data/vendor/javascripts/emscripted-ruby/lib/date/format.rb +1190 -0
  31. data/vendor/javascripts/emscripted-ruby/lib/date2.rb +5 -0
  32. data/vendor/javascripts/emscripted-ruby/lib/debug.rb +947 -0
  33. data/vendor/javascripts/emscripted-ruby/lib/delegate.rb +337 -0
  34. data/vendor/javascripts/emscripted-ruby/lib/drb.rb +2 -0
  35. data/vendor/javascripts/emscripted-ruby/lib/drb/acl.rb +146 -0
  36. data/vendor/javascripts/emscripted-ruby/lib/drb/drb.rb +1782 -0
  37. data/vendor/javascripts/emscripted-ruby/lib/drb/eq.rb +16 -0
  38. data/vendor/javascripts/emscripted-ruby/lib/drb/extserv.rb +64 -0
  39. data/vendor/javascripts/emscripted-ruby/lib/drb/extservm.rb +89 -0
  40. data/vendor/javascripts/emscripted-ruby/lib/drb/gw.rb +122 -0
  41. data/vendor/javascripts/emscripted-ruby/lib/drb/invokemethod.rb +36 -0
  42. data/vendor/javascripts/emscripted-ruby/lib/drb/observer.rb +22 -0
  43. data/vendor/javascripts/emscripted-ruby/lib/drb/ssl.rb +190 -0
  44. data/vendor/javascripts/emscripted-ruby/lib/drb/timeridconv.rb +91 -0
  45. data/vendor/javascripts/emscripted-ruby/lib/drb/unix.rb +108 -0
  46. data/vendor/javascripts/emscripted-ruby/lib/e2mmap.rb +195 -0
  47. data/vendor/javascripts/emscripted-ruby/lib/erb.rb +880 -0
  48. data/vendor/javascripts/emscripted-ruby/lib/eregex.rb +37 -0
  49. data/vendor/javascripts/emscripted-ruby/lib/fileutils.rb +1591 -0
  50. data/vendor/javascripts/emscripted-ruby/lib/finalize.rb +193 -0
  51. data/vendor/javascripts/emscripted-ruby/lib/find.rb +79 -0
  52. data/vendor/javascripts/emscripted-ruby/lib/forwardable.rb +218 -0
  53. data/vendor/javascripts/emscripted-ruby/lib/ftools.rb +261 -0
  54. data/vendor/javascripts/emscripted-ruby/lib/generator.rb +418 -0
  55. data/vendor/javascripts/emscripted-ruby/lib/getoptlong.rb +621 -0
  56. data/vendor/javascripts/emscripted-ruby/lib/getopts.rb +127 -0
  57. data/vendor/javascripts/emscripted-ruby/lib/gserver.rb +253 -0
  58. data/vendor/javascripts/emscripted-ruby/lib/importenv.rb +33 -0
  59. data/vendor/javascripts/emscripted-ruby/lib/ipaddr.rb +814 -0
  60. data/vendor/javascripts/emscripted-ruby/lib/irb.rb +346 -0
  61. data/vendor/javascripts/emscripted-ruby/lib/irb/cmd/chws.rb +33 -0
  62. data/vendor/javascripts/emscripted-ruby/lib/irb/cmd/fork.rb +39 -0
  63. data/vendor/javascripts/emscripted-ruby/lib/irb/cmd/help.rb +34 -0
  64. data/vendor/javascripts/emscripted-ruby/lib/irb/cmd/load.rb +67 -0
  65. data/vendor/javascripts/emscripted-ruby/lib/irb/cmd/nop.rb +39 -0
  66. data/vendor/javascripts/emscripted-ruby/lib/irb/cmd/pushws.rb +39 -0
  67. data/vendor/javascripts/emscripted-ruby/lib/irb/cmd/subirb.rb +43 -0
  68. data/vendor/javascripts/emscripted-ruby/lib/irb/completion.rb +205 -0
  69. data/vendor/javascripts/emscripted-ruby/lib/irb/context.rb +255 -0
  70. data/vendor/javascripts/emscripted-ruby/lib/irb/ext/change-ws.rb +62 -0
  71. data/vendor/javascripts/emscripted-ruby/lib/irb/ext/history.rb +110 -0
  72. data/vendor/javascripts/emscripted-ruby/lib/irb/ext/loader.rb +120 -0
  73. data/vendor/javascripts/emscripted-ruby/lib/irb/ext/math-mode.rb +37 -0
  74. data/vendor/javascripts/emscripted-ruby/lib/irb/ext/multi-irb.rb +241 -0
  75. data/vendor/javascripts/emscripted-ruby/lib/irb/ext/save-history.rb +85 -0
  76. data/vendor/javascripts/emscripted-ruby/lib/irb/ext/tracer.rb +61 -0
  77. data/vendor/javascripts/emscripted-ruby/lib/irb/ext/use-loader.rb +65 -0
  78. data/vendor/javascripts/emscripted-ruby/lib/irb/ext/workspaces.rb +56 -0
  79. data/vendor/javascripts/emscripted-ruby/lib/irb/extend-command.rb +264 -0
  80. data/vendor/javascripts/emscripted-ruby/lib/irb/frame.rb +67 -0
  81. data/vendor/javascripts/emscripted-ruby/lib/irb/help.rb +33 -0
  82. data/vendor/javascripts/emscripted-ruby/lib/irb/init.rb +259 -0
  83. data/vendor/javascripts/emscripted-ruby/lib/irb/input-method.rb +120 -0
  84. data/vendor/javascripts/emscripted-ruby/lib/irb/lc/error.rb +30 -0
  85. data/vendor/javascripts/emscripted-ruby/lib/irb/lc/help-message +35 -0
  86. data/vendor/javascripts/emscripted-ruby/lib/irb/lc/ja/error.rb +27 -0
  87. data/vendor/javascripts/emscripted-ruby/lib/irb/lc/ja/help-message +36 -0
  88. data/vendor/javascripts/emscripted-ruby/lib/irb/locale.rb +184 -0
  89. data/vendor/javascripts/emscripted-ruby/lib/irb/notifier.rb +145 -0
  90. data/vendor/javascripts/emscripted-ruby/lib/irb/output-method.rb +85 -0
  91. data/vendor/javascripts/emscripted-ruby/lib/irb/ruby-lex.rb +1149 -0
  92. data/vendor/javascripts/emscripted-ruby/lib/irb/ruby-token.rb +273 -0
  93. data/vendor/javascripts/emscripted-ruby/lib/irb/slex.rb +285 -0
  94. data/vendor/javascripts/emscripted-ruby/lib/irb/version.rb +16 -0
  95. data/vendor/javascripts/emscripted-ruby/lib/irb/workspace.rb +107 -0
  96. data/vendor/javascripts/emscripted-ruby/lib/irb/ws-for-case-2.rb +15 -0
  97. data/vendor/javascripts/emscripted-ruby/lib/irb/xmp.rb +86 -0
  98. data/vendor/javascripts/emscripted-ruby/lib/jcode.rb +220 -0
  99. data/vendor/javascripts/emscripted-ruby/lib/logger.rb +703 -0
  100. data/vendor/javascripts/emscripted-ruby/lib/mailread.rb +62 -0
  101. data/vendor/javascripts/emscripted-ruby/lib/mathn.rb +308 -0
  102. data/vendor/javascripts/emscripted-ruby/lib/matrix.rb +1278 -0
  103. data/vendor/javascripts/emscripted-ruby/lib/mkmf.rb +1811 -0
  104. data/vendor/javascripts/emscripted-ruby/lib/monitor.rb +352 -0
  105. data/vendor/javascripts/emscripted-ruby/lib/mutex_m.rb +122 -0
  106. data/vendor/javascripts/emscripted-ruby/lib/net/ftp.rb +927 -0
  107. data/vendor/javascripts/emscripted-ruby/lib/net/http.rb +2277 -0
  108. data/vendor/javascripts/emscripted-ruby/lib/net/https.rb +173 -0
  109. data/vendor/javascripts/emscripted-ruby/lib/net/imap.rb +3371 -0
  110. data/vendor/javascripts/emscripted-ruby/lib/net/pop.rb +999 -0
  111. data/vendor/javascripts/emscripted-ruby/lib/net/protocol.rb +392 -0
  112. data/vendor/javascripts/emscripted-ruby/lib/net/smtp.rb +1014 -0
  113. data/vendor/javascripts/emscripted-ruby/lib/net/telnet.rb +756 -0
  114. data/vendor/javascripts/emscripted-ruby/lib/observer.rb +192 -0
  115. data/vendor/javascripts/emscripted-ruby/lib/open-uri.rb +678 -0
  116. data/vendor/javascripts/emscripted-ruby/lib/open3.rb +101 -0
  117. data/vendor/javascripts/emscripted-ruby/lib/optparse.rb +1790 -0
  118. data/vendor/javascripts/emscripted-ruby/lib/optparse/date.rb +17 -0
  119. data/vendor/javascripts/emscripted-ruby/lib/optparse/shellwords.rb +6 -0
  120. data/vendor/javascripts/emscripted-ruby/lib/optparse/time.rb +10 -0
  121. data/vendor/javascripts/emscripted-ruby/lib/optparse/uri.rb +6 -0
  122. data/vendor/javascripts/emscripted-ruby/lib/optparse/version.rb +70 -0
  123. data/vendor/javascripts/emscripted-ruby/lib/ostruct.rb +146 -0
  124. data/vendor/javascripts/emscripted-ruby/lib/parsearg.rb +87 -0
  125. data/vendor/javascripts/emscripted-ruby/lib/parsedate.rb +53 -0
  126. data/vendor/javascripts/emscripted-ruby/lib/pathname.rb +1062 -0
  127. data/vendor/javascripts/emscripted-ruby/lib/ping.rb +64 -0
  128. data/vendor/javascripts/emscripted-ruby/lib/pp.rb +654 -0
  129. data/vendor/javascripts/emscripted-ruby/lib/prettyprint.rb +896 -0
  130. data/vendor/javascripts/emscripted-ruby/lib/profile.rb +6 -0
  131. data/vendor/javascripts/emscripted-ruby/lib/profiler.rb +59 -0
  132. data/vendor/javascripts/emscripted-ruby/lib/pstore.rb +395 -0
  133. data/vendor/javascripts/emscripted-ruby/lib/racc/parser.rb +442 -0
  134. data/vendor/javascripts/emscripted-ruby/lib/rational.rb +564 -0
  135. data/vendor/javascripts/emscripted-ruby/lib/readbytes.rb +41 -0
  136. data/vendor/javascripts/emscripted-ruby/lib/resolv-replace.rb +62 -0
  137. data/vendor/javascripts/emscripted-ruby/lib/resolv.rb +2210 -0
  138. data/vendor/javascripts/emscripted-ruby/lib/rexml/attlistdecl.rb +62 -0
  139. data/vendor/javascripts/emscripted-ruby/lib/rexml/attribute.rb +185 -0
  140. data/vendor/javascripts/emscripted-ruby/lib/rexml/cdata.rb +67 -0
  141. data/vendor/javascripts/emscripted-ruby/lib/rexml/child.rb +96 -0
  142. data/vendor/javascripts/emscripted-ruby/lib/rexml/comment.rb +80 -0
  143. data/vendor/javascripts/emscripted-ruby/lib/rexml/doctype.rb +271 -0
  144. data/vendor/javascripts/emscripted-ruby/lib/rexml/document.rb +208 -0
  145. data/vendor/javascripts/emscripted-ruby/lib/rexml/dtd/attlistdecl.rb +10 -0
  146. data/vendor/javascripts/emscripted-ruby/lib/rexml/dtd/dtd.rb +51 -0
  147. data/vendor/javascripts/emscripted-ruby/lib/rexml/dtd/elementdecl.rb +17 -0
  148. data/vendor/javascripts/emscripted-ruby/lib/rexml/dtd/entitydecl.rb +56 -0
  149. data/vendor/javascripts/emscripted-ruby/lib/rexml/dtd/notationdecl.rb +39 -0
  150. data/vendor/javascripts/emscripted-ruby/lib/rexml/element.rb +1227 -0
  151. data/vendor/javascripts/emscripted-ruby/lib/rexml/encoding.rb +71 -0
  152. data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/CP-1252.rb +103 -0
  153. data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/EUC-JP.rb +35 -0
  154. data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/ICONV.rb +22 -0
  155. data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/ISO-8859-1.rb +7 -0
  156. data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/ISO-8859-15.rb +72 -0
  157. data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/SHIFT-JIS.rb +37 -0
  158. data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/SHIFT_JIS.rb +1 -0
  159. data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/UNILE.rb +34 -0
  160. data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/US-ASCII.rb +30 -0
  161. data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/UTF-16.rb +35 -0
  162. data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/UTF-8.rb +18 -0
  163. data/vendor/javascripts/emscripted-ruby/lib/rexml/entity.rb +165 -0
  164. data/vendor/javascripts/emscripted-ruby/lib/rexml/formatters/default.rb +109 -0
  165. data/vendor/javascripts/emscripted-ruby/lib/rexml/formatters/pretty.rb +137 -0
  166. data/vendor/javascripts/emscripted-ruby/lib/rexml/formatters/transitive.rb +56 -0
  167. data/vendor/javascripts/emscripted-ruby/lib/rexml/functions.rb +382 -0
  168. data/vendor/javascripts/emscripted-ruby/lib/rexml/instruction.rb +70 -0
  169. data/vendor/javascripts/emscripted-ruby/lib/rexml/light/node.rb +196 -0
  170. data/vendor/javascripts/emscripted-ruby/lib/rexml/namespace.rb +47 -0
  171. data/vendor/javascripts/emscripted-ruby/lib/rexml/node.rb +75 -0
  172. data/vendor/javascripts/emscripted-ruby/lib/rexml/output.rb +24 -0
  173. data/vendor/javascripts/emscripted-ruby/lib/rexml/parent.rb +166 -0
  174. data/vendor/javascripts/emscripted-ruby/lib/rexml/parseexception.rb +51 -0
  175. data/vendor/javascripts/emscripted-ruby/lib/rexml/parsers/baseparser.rb +503 -0
  176. data/vendor/javascripts/emscripted-ruby/lib/rexml/parsers/lightparser.rb +60 -0
  177. data/vendor/javascripts/emscripted-ruby/lib/rexml/parsers/pullparser.rb +196 -0
  178. data/vendor/javascripts/emscripted-ruby/lib/rexml/parsers/sax2parser.rb +238 -0
  179. data/vendor/javascripts/emscripted-ruby/lib/rexml/parsers/streamparser.rb +46 -0
  180. data/vendor/javascripts/emscripted-ruby/lib/rexml/parsers/treeparser.rb +97 -0
  181. data/vendor/javascripts/emscripted-ruby/lib/rexml/parsers/ultralightparser.rb +56 -0
  182. data/vendor/javascripts/emscripted-ruby/lib/rexml/parsers/xpathparser.rb +698 -0
  183. data/vendor/javascripts/emscripted-ruby/lib/rexml/quickpath.rb +266 -0
  184. data/vendor/javascripts/emscripted-ruby/lib/rexml/rexml.rb +32 -0
  185. data/vendor/javascripts/emscripted-ruby/lib/rexml/sax2listener.rb +97 -0
  186. data/vendor/javascripts/emscripted-ruby/lib/rexml/source.rb +251 -0
  187. data/vendor/javascripts/emscripted-ruby/lib/rexml/streamlistener.rb +92 -0
  188. data/vendor/javascripts/emscripted-ruby/lib/rexml/syncenumerator.rb +33 -0
  189. data/vendor/javascripts/emscripted-ruby/lib/rexml/text.rb +344 -0
  190. data/vendor/javascripts/emscripted-ruby/lib/rexml/undefinednamespaceexception.rb +8 -0
  191. data/vendor/javascripts/emscripted-ruby/lib/rexml/validation/relaxng.rb +559 -0
  192. data/vendor/javascripts/emscripted-ruby/lib/rexml/validation/validation.rb +155 -0
  193. data/vendor/javascripts/emscripted-ruby/lib/rexml/validation/validationexception.rb +9 -0
  194. data/vendor/javascripts/emscripted-ruby/lib/rexml/xmldecl.rb +119 -0
  195. data/vendor/javascripts/emscripted-ruby/lib/rexml/xmltokens.rb +18 -0
  196. data/vendor/javascripts/emscripted-ruby/lib/rexml/xpath.rb +66 -0
  197. data/vendor/javascripts/emscripted-ruby/lib/rexml/xpath_parser.rb +792 -0
  198. data/vendor/javascripts/emscripted-ruby/lib/rinda/rinda.rb +283 -0
  199. data/vendor/javascripts/emscripted-ruby/lib/rinda/ring.rb +271 -0
  200. data/vendor/javascripts/emscripted-ruby/lib/rinda/tuplespace.rb +642 -0
  201. data/vendor/javascripts/emscripted-ruby/lib/rss.rb +19 -0
  202. data/vendor/javascripts/emscripted-ruby/lib/rss/0.9.rb +428 -0
  203. data/vendor/javascripts/emscripted-ruby/lib/rss/1.0.rb +452 -0
  204. data/vendor/javascripts/emscripted-ruby/lib/rss/2.0.rb +111 -0
  205. data/vendor/javascripts/emscripted-ruby/lib/rss/atom.rb +749 -0
  206. data/vendor/javascripts/emscripted-ruby/lib/rss/content.rb +31 -0
  207. data/vendor/javascripts/emscripted-ruby/lib/rss/content/1.0.rb +10 -0
  208. data/vendor/javascripts/emscripted-ruby/lib/rss/content/2.0.rb +12 -0
  209. data/vendor/javascripts/emscripted-ruby/lib/rss/converter.rb +162 -0
  210. data/vendor/javascripts/emscripted-ruby/lib/rss/dublincore.rb +161 -0
  211. data/vendor/javascripts/emscripted-ruby/lib/rss/dublincore/1.0.rb +13 -0
  212. data/vendor/javascripts/emscripted-ruby/lib/rss/dublincore/2.0.rb +13 -0
  213. data/vendor/javascripts/emscripted-ruby/lib/rss/dublincore/atom.rb +17 -0
  214. data/vendor/javascripts/emscripted-ruby/lib/rss/image.rb +193 -0
  215. data/vendor/javascripts/emscripted-ruby/lib/rss/itunes.rb +410 -0
  216. data/vendor/javascripts/emscripted-ruby/lib/rss/maker.rb +44 -0
  217. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/0.9.rb +467 -0
  218. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/1.0.rb +434 -0
  219. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/2.0.rb +223 -0
  220. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/atom.rb +172 -0
  221. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/base.rb +868 -0
  222. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/content.rb +21 -0
  223. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/dublincore.rb +124 -0
  224. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/entry.rb +163 -0
  225. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/feed.rb +429 -0
  226. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/image.rb +111 -0
  227. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/itunes.rb +242 -0
  228. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/slash.rb +33 -0
  229. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/syndication.rb +18 -0
  230. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/taxonomy.rb +118 -0
  231. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/trackback.rb +61 -0
  232. data/vendor/javascripts/emscripted-ruby/lib/rss/parser.rb +541 -0
  233. data/vendor/javascripts/emscripted-ruby/lib/rss/rexmlparser.rb +54 -0
  234. data/vendor/javascripts/emscripted-ruby/lib/rss/rss.rb +1312 -0
  235. data/vendor/javascripts/emscripted-ruby/lib/rss/slash.rb +49 -0
  236. data/vendor/javascripts/emscripted-ruby/lib/rss/syndication.rb +67 -0
  237. data/vendor/javascripts/emscripted-ruby/lib/rss/taxonomy.rb +145 -0
  238. data/vendor/javascripts/emscripted-ruby/lib/rss/trackback.rb +288 -0
  239. data/vendor/javascripts/emscripted-ruby/lib/rss/utils.rb +111 -0
  240. data/vendor/javascripts/emscripted-ruby/lib/rss/xml-stylesheet.rb +105 -0
  241. data/vendor/javascripts/emscripted-ruby/lib/rss/xml.rb +71 -0
  242. data/vendor/javascripts/emscripted-ruby/lib/rss/xmlparser.rb +93 -0
  243. data/vendor/javascripts/emscripted-ruby/lib/rss/xmlscanner.rb +121 -0
  244. data/vendor/javascripts/emscripted-ruby/lib/rubyunit.rb +6 -0
  245. data/vendor/javascripts/emscripted-ruby/lib/runit/assert.rb +73 -0
  246. data/vendor/javascripts/emscripted-ruby/lib/runit/cui/testrunner.rb +51 -0
  247. data/vendor/javascripts/emscripted-ruby/lib/runit/error.rb +9 -0
  248. data/vendor/javascripts/emscripted-ruby/lib/runit/testcase.rb +45 -0
  249. data/vendor/javascripts/emscripted-ruby/lib/runit/testresult.rb +44 -0
  250. data/vendor/javascripts/emscripted-ruby/lib/runit/testsuite.rb +26 -0
  251. data/vendor/javascripts/emscripted-ruby/lib/runit/topublic.rb +8 -0
  252. data/vendor/javascripts/emscripted-ruby/lib/scanf.rb +702 -0
  253. data/vendor/javascripts/emscripted-ruby/lib/securerandom.rb +137 -0
  254. data/vendor/javascripts/emscripted-ruby/lib/set.rb +1233 -0
  255. data/vendor/javascripts/emscripted-ruby/lib/shell.rb +269 -0
  256. data/vendor/javascripts/emscripted-ruby/lib/shell/builtin-command.rb +154 -0
  257. data/vendor/javascripts/emscripted-ruby/lib/shell/command-processor.rb +592 -0
  258. data/vendor/javascripts/emscripted-ruby/lib/shell/error.rb +26 -0
  259. data/vendor/javascripts/emscripted-ruby/lib/shell/filter.rb +110 -0
  260. data/vendor/javascripts/emscripted-ruby/lib/shell/process-controller.rb +260 -0
  261. data/vendor/javascripts/emscripted-ruby/lib/shell/system-command.rb +168 -0
  262. data/vendor/javascripts/emscripted-ruby/lib/shell/version.rb +16 -0
  263. data/vendor/javascripts/emscripted-ruby/lib/shellwords.rb +172 -0
  264. data/vendor/javascripts/emscripted-ruby/lib/singleton.rb +360 -0
  265. data/vendor/javascripts/emscripted-ruby/lib/soap/attachment.rb +107 -0
  266. data/vendor/javascripts/emscripted-ruby/lib/soap/baseData.rb +942 -0
  267. data/vendor/javascripts/emscripted-ruby/lib/soap/element.rb +258 -0
  268. data/vendor/javascripts/emscripted-ruby/lib/soap/encodingstyle/aspDotNetHandler.rb +213 -0
  269. data/vendor/javascripts/emscripted-ruby/lib/soap/encodingstyle/handler.rb +100 -0
  270. data/vendor/javascripts/emscripted-ruby/lib/soap/encodingstyle/literalHandler.rb +226 -0
  271. data/vendor/javascripts/emscripted-ruby/lib/soap/encodingstyle/soapHandler.rb +582 -0
  272. data/vendor/javascripts/emscripted-ruby/lib/soap/generator.rb +268 -0
  273. data/vendor/javascripts/emscripted-ruby/lib/soap/header/handler.rb +57 -0
  274. data/vendor/javascripts/emscripted-ruby/lib/soap/header/handlerset.rb +70 -0
  275. data/vendor/javascripts/emscripted-ruby/lib/soap/header/simplehandler.rb +44 -0
  276. data/vendor/javascripts/emscripted-ruby/lib/soap/httpconfigloader.rb +119 -0
  277. data/vendor/javascripts/emscripted-ruby/lib/soap/mapping.rb +10 -0
  278. data/vendor/javascripts/emscripted-ruby/lib/soap/mapping/factory.rb +355 -0
  279. data/vendor/javascripts/emscripted-ruby/lib/soap/mapping/mapping.rb +381 -0
  280. data/vendor/javascripts/emscripted-ruby/lib/soap/mapping/registry.rb +541 -0
  281. data/vendor/javascripts/emscripted-ruby/lib/soap/mapping/rubytypeFactory.rb +475 -0
  282. data/vendor/javascripts/emscripted-ruby/lib/soap/mapping/typeMap.rb +50 -0
  283. data/vendor/javascripts/emscripted-ruby/lib/soap/mapping/wsdlencodedregistry.rb +280 -0
  284. data/vendor/javascripts/emscripted-ruby/lib/soap/mapping/wsdlliteralregistry.rb +418 -0
  285. data/vendor/javascripts/emscripted-ruby/lib/soap/marshal.rb +59 -0
  286. data/vendor/javascripts/emscripted-ruby/lib/soap/mimemessage.rb +240 -0
  287. data/vendor/javascripts/emscripted-ruby/lib/soap/netHttpClient.rb +190 -0
  288. data/vendor/javascripts/emscripted-ruby/lib/soap/parser.rb +251 -0
  289. data/vendor/javascripts/emscripted-ruby/lib/soap/processor.rb +66 -0
  290. data/vendor/javascripts/emscripted-ruby/lib/soap/property.rb +333 -0
  291. data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/cgistub.rb +206 -0
  292. data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/driver.rb +254 -0
  293. data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/element.rb +325 -0
  294. data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/httpserver.rb +129 -0
  295. data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/proxy.rb +497 -0
  296. data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/router.rb +594 -0
  297. data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/rpc.rb +25 -0
  298. data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/soaplet.rb +162 -0
  299. data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/standaloneServer.rb +43 -0
  300. data/vendor/javascripts/emscripted-ruby/lib/soap/soap.rb +140 -0
  301. data/vendor/javascripts/emscripted-ruby/lib/soap/streamHandler.rb +229 -0
  302. data/vendor/javascripts/emscripted-ruby/lib/soap/wsdlDriver.rb +575 -0
  303. data/vendor/javascripts/emscripted-ruby/lib/sync.rb +311 -0
  304. data/vendor/javascripts/emscripted-ruby/lib/tempfile.rb +209 -0
  305. data/vendor/javascripts/emscripted-ruby/lib/test/unit.rb +280 -0
  306. data/vendor/javascripts/emscripted-ruby/lib/test/unit/assertionfailederror.rb +14 -0
  307. data/vendor/javascripts/emscripted-ruby/lib/test/unit/assertions.rb +622 -0
  308. data/vendor/javascripts/emscripted-ruby/lib/test/unit/autorunner.rb +220 -0
  309. data/vendor/javascripts/emscripted-ruby/lib/test/unit/collector.rb +43 -0
  310. data/vendor/javascripts/emscripted-ruby/lib/test/unit/collector/dir.rb +107 -0
  311. data/vendor/javascripts/emscripted-ruby/lib/test/unit/collector/objectspace.rb +34 -0
  312. data/vendor/javascripts/emscripted-ruby/lib/test/unit/error.rb +56 -0
  313. data/vendor/javascripts/emscripted-ruby/lib/test/unit/failure.rb +51 -0
  314. data/vendor/javascripts/emscripted-ruby/lib/test/unit/testcase.rb +160 -0
  315. data/vendor/javascripts/emscripted-ruby/lib/test/unit/testresult.rb +80 -0
  316. data/vendor/javascripts/emscripted-ruby/lib/test/unit/testsuite.rb +76 -0
  317. data/vendor/javascripts/emscripted-ruby/lib/test/unit/ui/console/testrunner.rb +127 -0
  318. data/vendor/javascripts/emscripted-ruby/lib/test/unit/ui/fox/testrunner.rb +268 -0
  319. data/vendor/javascripts/emscripted-ruby/lib/test/unit/ui/gtk/testrunner.rb +416 -0
  320. data/vendor/javascripts/emscripted-ruby/lib/test/unit/ui/gtk2/testrunner.rb +465 -0
  321. data/vendor/javascripts/emscripted-ruby/lib/test/unit/ui/testrunnermediator.rb +68 -0
  322. data/vendor/javascripts/emscripted-ruby/lib/test/unit/ui/testrunnerutilities.rb +46 -0
  323. data/vendor/javascripts/emscripted-ruby/lib/test/unit/ui/tk/testrunner.rb +260 -0
  324. data/vendor/javascripts/emscripted-ruby/lib/test/unit/util/backtracefilter.rb +40 -0
  325. data/vendor/javascripts/emscripted-ruby/lib/test/unit/util/observable.rb +90 -0
  326. data/vendor/javascripts/emscripted-ruby/lib/test/unit/util/procwrapper.rb +48 -0
  327. data/vendor/javascripts/emscripted-ruby/lib/thread.rb +479 -0
  328. data/vendor/javascripts/emscripted-ruby/lib/thwait.rb +169 -0
  329. data/vendor/javascripts/emscripted-ruby/lib/time.rb +797 -0
  330. data/vendor/javascripts/emscripted-ruby/lib/timeout.rb +122 -0
  331. data/vendor/javascripts/emscripted-ruby/lib/tmpdir.rb +130 -0
  332. data/vendor/javascripts/emscripted-ruby/lib/tracer.rb +167 -0
  333. data/vendor/javascripts/emscripted-ruby/lib/tsort.rb +290 -0
  334. data/vendor/javascripts/emscripted-ruby/lib/un.rb +235 -0
  335. data/vendor/javascripts/emscripted-ruby/lib/uri.rb +29 -0
  336. data/vendor/javascripts/emscripted-ruby/lib/uri/common.rb +611 -0
  337. data/vendor/javascripts/emscripted-ruby/lib/uri/ftp.rb +198 -0
  338. data/vendor/javascripts/emscripted-ruby/lib/uri/generic.rb +1122 -0
  339. data/vendor/javascripts/emscripted-ruby/lib/uri/http.rb +100 -0
  340. data/vendor/javascripts/emscripted-ruby/lib/uri/https.rb +20 -0
  341. data/vendor/javascripts/emscripted-ruby/lib/uri/ldap.rb +190 -0
  342. data/vendor/javascripts/emscripted-ruby/lib/uri/ldaps.rb +12 -0
  343. data/vendor/javascripts/emscripted-ruby/lib/uri/mailto.rb +266 -0
  344. data/vendor/javascripts/emscripted-ruby/lib/weakref.rb +100 -0
  345. data/vendor/javascripts/emscripted-ruby/lib/webrick.rb +29 -0
  346. data/vendor/javascripts/emscripted-ruby/lib/webrick/accesslog.rb +67 -0
  347. data/vendor/javascripts/emscripted-ruby/lib/webrick/cgi.rb +257 -0
  348. data/vendor/javascripts/emscripted-ruby/lib/webrick/compat.rb +15 -0
  349. data/vendor/javascripts/emscripted-ruby/lib/webrick/config.rb +97 -0
  350. data/vendor/javascripts/emscripted-ruby/lib/webrick/cookie.rb +110 -0
  351. data/vendor/javascripts/emscripted-ruby/lib/webrick/htmlutils.rb +25 -0
  352. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpauth.rb +45 -0
  353. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpauth/authenticator.rb +79 -0
  354. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpauth/basicauth.rb +65 -0
  355. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpauth/digestauth.rb +343 -0
  356. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpauth/htdigest.rb +91 -0
  357. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpauth/htgroup.rb +61 -0
  358. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpauth/htpasswd.rb +83 -0
  359. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpauth/userdb.rb +29 -0
  360. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpproxy.rb +254 -0
  361. data/vendor/javascripts/emscripted-ruby/lib/webrick/httprequest.rb +365 -0
  362. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpresponse.rb +327 -0
  363. data/vendor/javascripts/emscripted-ruby/lib/webrick/https.rb +63 -0
  364. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpserver.rb +210 -0
  365. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpservlet.rb +22 -0
  366. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpservlet/abstract.rb +71 -0
  367. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpservlet/cgi_runner.rb +47 -0
  368. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpservlet/cgihandler.rb +108 -0
  369. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpservlet/erbhandler.rb +54 -0
  370. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpservlet/filehandler.rb +435 -0
  371. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpservlet/prochandler.rb +33 -0
  372. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpstatus.rb +126 -0
  373. data/vendor/javascripts/emscripted-ruby/lib/webrick/httputils.rb +399 -0
  374. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpversion.rb +49 -0
  375. data/vendor/javascripts/emscripted-ruby/lib/webrick/log.rb +88 -0
  376. data/vendor/javascripts/emscripted-ruby/lib/webrick/server.rb +200 -0
  377. data/vendor/javascripts/emscripted-ruby/lib/webrick/ssl.rb +126 -0
  378. data/vendor/javascripts/emscripted-ruby/lib/webrick/utils.rb +100 -0
  379. data/vendor/javascripts/emscripted-ruby/lib/webrick/version.rb +13 -0
  380. data/vendor/javascripts/emscripted-ruby/lib/wsdl/binding.rb +65 -0
  381. data/vendor/javascripts/emscripted-ruby/lib/wsdl/data.rb +64 -0
  382. data/vendor/javascripts/emscripted-ruby/lib/wsdl/definitions.rb +250 -0
  383. data/vendor/javascripts/emscripted-ruby/lib/wsdl/documentation.rb +32 -0
  384. data/vendor/javascripts/emscripted-ruby/lib/wsdl/import.rb +80 -0
  385. data/vendor/javascripts/emscripted-ruby/lib/wsdl/importer.rb +38 -0
  386. data/vendor/javascripts/emscripted-ruby/lib/wsdl/info.rb +39 -0
  387. data/vendor/javascripts/emscripted-ruby/lib/wsdl/message.rb +54 -0
  388. data/vendor/javascripts/emscripted-ruby/lib/wsdl/operation.rb +130 -0
  389. data/vendor/javascripts/emscripted-ruby/lib/wsdl/operationBinding.rb +108 -0
  390. data/vendor/javascripts/emscripted-ruby/lib/wsdl/param.rb +85 -0
  391. data/vendor/javascripts/emscripted-ruby/lib/wsdl/parser.rb +163 -0
  392. data/vendor/javascripts/emscripted-ruby/lib/wsdl/part.rb +52 -0
  393. data/vendor/javascripts/emscripted-ruby/lib/wsdl/port.rb +84 -0
  394. data/vendor/javascripts/emscripted-ruby/lib/wsdl/portType.rb +73 -0
  395. data/vendor/javascripts/emscripted-ruby/lib/wsdl/service.rb +61 -0
  396. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/address.rb +40 -0
  397. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/binding.rb +49 -0
  398. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/body.rb +56 -0
  399. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/cgiStubCreator.rb +76 -0
  400. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/classDefCreator.rb +314 -0
  401. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/classDefCreatorSupport.rb +126 -0
  402. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/clientSkeltonCreator.rb +78 -0
  403. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/complexType.rb +161 -0
  404. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/data.rb +42 -0
  405. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/definitions.rb +149 -0
  406. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/driverCreator.rb +95 -0
  407. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/element.rb +28 -0
  408. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/fault.rb +56 -0
  409. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/header.rb +86 -0
  410. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/headerfault.rb +56 -0
  411. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/mappingRegistryCreator.rb +92 -0
  412. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/methodDefCreator.rb +228 -0
  413. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/operation.rb +122 -0
  414. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/servantSkeltonCreator.rb +67 -0
  415. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/standaloneServerStubCreator.rb +85 -0
  416. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/wsdl2ruby.rb +176 -0
  417. data/vendor/javascripts/emscripted-ruby/lib/wsdl/types.rb +43 -0
  418. data/vendor/javascripts/emscripted-ruby/lib/wsdl/wsdl.rb +23 -0
  419. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/all.rb +69 -0
  420. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/annotation.rb +34 -0
  421. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/any.rb +56 -0
  422. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/attribute.rb +127 -0
  423. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/choice.rb +69 -0
  424. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/complexContent.rb +92 -0
  425. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/complexType.rb +139 -0
  426. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/content.rb +96 -0
  427. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/data.rb +80 -0
  428. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/element.rb +154 -0
  429. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/enumeration.rb +36 -0
  430. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/import.rb +65 -0
  431. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/importer.rb +87 -0
  432. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/include.rb +54 -0
  433. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/length.rb +35 -0
  434. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/parser.rb +166 -0
  435. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/pattern.rb +36 -0
  436. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/schema.rb +143 -0
  437. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/sequence.rb +69 -0
  438. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/simpleContent.rb +65 -0
  439. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/simpleExtension.rb +54 -0
  440. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/simpleRestriction.rb +73 -0
  441. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/simpleType.rb +73 -0
  442. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/unique.rb +34 -0
  443. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/xsd2ruby.rb +107 -0
  444. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/.document +1 -0
  445. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/README.txt +31 -0
  446. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/base64.rb +81 -0
  447. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/client.rb +624 -0
  448. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/config.rb +40 -0
  449. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/create.rb +290 -0
  450. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/datetime.rb +142 -0
  451. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/httpserver.rb +178 -0
  452. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/marshal.rb +76 -0
  453. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/parser.rb +813 -0
  454. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/server.rb +780 -0
  455. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/utils.rb +165 -0
  456. data/vendor/javascripts/emscripted-ruby/lib/xsd/charset.rb +187 -0
  457. data/vendor/javascripts/emscripted-ruby/lib/xsd/codegen.rb +12 -0
  458. data/vendor/javascripts/emscripted-ruby/lib/xsd/codegen/classdef.rb +203 -0
  459. data/vendor/javascripts/emscripted-ruby/lib/xsd/codegen/commentdef.rb +34 -0
  460. data/vendor/javascripts/emscripted-ruby/lib/xsd/codegen/gensupport.rb +166 -0
  461. data/vendor/javascripts/emscripted-ruby/lib/xsd/codegen/methoddef.rb +63 -0
  462. data/vendor/javascripts/emscripted-ruby/lib/xsd/codegen/moduledef.rb +191 -0
  463. data/vendor/javascripts/emscripted-ruby/lib/xsd/datatypes.rb +1269 -0
  464. data/vendor/javascripts/emscripted-ruby/lib/xsd/datatypes1999.rb +20 -0
  465. data/vendor/javascripts/emscripted-ruby/lib/xsd/iconvcharset.rb +33 -0
  466. data/vendor/javascripts/emscripted-ruby/lib/xsd/mapping.rb +42 -0
  467. data/vendor/javascripts/emscripted-ruby/lib/xsd/namedelements.rb +95 -0
  468. data/vendor/javascripts/emscripted-ruby/lib/xsd/ns.rb +140 -0
  469. data/vendor/javascripts/emscripted-ruby/lib/xsd/qname.rb +78 -0
  470. data/vendor/javascripts/emscripted-ruby/lib/xsd/xmlparser.rb +61 -0
  471. data/vendor/javascripts/emscripted-ruby/lib/xsd/xmlparser/parser.rb +96 -0
  472. data/vendor/javascripts/emscripted-ruby/lib/xsd/xmlparser/rexmlparser.rb +54 -0
  473. data/vendor/javascripts/emscripted-ruby/lib/xsd/xmlparser/xmlparser.rb +50 -0
  474. data/vendor/javascripts/emscripted-ruby/lib/xsd/xmlparser/xmlscanner.rb +147 -0
  475. data/vendor/javascripts/emscripted-ruby/lib/yaml.rb +440 -0
  476. data/vendor/javascripts/emscripted-ruby/lib/yaml/baseemitter.rb +247 -0
  477. data/vendor/javascripts/emscripted-ruby/lib/yaml/basenode.rb +216 -0
  478. data/vendor/javascripts/emscripted-ruby/lib/yaml/constants.rb +45 -0
  479. data/vendor/javascripts/emscripted-ruby/lib/yaml/dbm.rb +111 -0
  480. data/vendor/javascripts/emscripted-ruby/lib/yaml/encoding.rb +33 -0
  481. data/vendor/javascripts/emscripted-ruby/lib/yaml/error.rb +34 -0
  482. data/vendor/javascripts/emscripted-ruby/lib/yaml/loader.rb +14 -0
  483. data/vendor/javascripts/emscripted-ruby/lib/yaml/rubytypes.rb +408 -0
  484. data/vendor/javascripts/emscripted-ruby/lib/yaml/store.rb +43 -0
  485. data/vendor/javascripts/emscripted-ruby/lib/yaml/stream.rb +40 -0
  486. data/vendor/javascripts/emscripted-ruby/lib/yaml/stringio.rb +83 -0
  487. data/vendor/javascripts/emscripted-ruby/lib/yaml/syck.rb +19 -0
  488. data/vendor/javascripts/emscripted-ruby/lib/yaml/tag.rb +91 -0
  489. data/vendor/javascripts/emscripted-ruby/lib/yaml/types.rb +192 -0
  490. data/vendor/javascripts/emscripted-ruby/lib/yaml/yamlnode.rb +54 -0
  491. data/vendor/javascripts/emscripted-ruby/lib/yaml/ypath.rb +52 -0
  492. data/vendor/javascripts/emscripted-ruby/ruby.closure.js +7201 -0
  493. metadata +554 -0
@@ -0,0 +1,2277 @@
1
+ #
2
+ # = net/http.rb
3
+ #
4
+ # Copyright (c) 1999-2006 Yukihiro Matsumoto
5
+ # Copyright (c) 1999-2006 Minero Aoki
6
+ # Copyright (c) 2001 GOTOU Yuuzou
7
+ #
8
+ # Written and maintained by Minero Aoki <aamine@loveruby.net>.
9
+ # HTTPS support added by GOTOU Yuuzou <gotoyuzo@notwork.org>.
10
+ #
11
+ # This file is derived from "http-access.rb".
12
+ #
13
+ # Documented by Minero Aoki; converted to RDoc by William Webber.
14
+ #
15
+ # This program is free software. You can re-distribute and/or
16
+ # modify this program under the same terms of ruby itself ---
17
+ # Ruby Distribution License or GNU General Public License.
18
+ #
19
+ # See Net::HTTP for an overview and examples.
20
+ #
21
+ # NOTE: You can find Japanese version of this document here:
22
+ # http://www.ruby-lang.org/ja/man/?cmd=view;name=net%2Fhttp.rb
23
+ #
24
+ #--
25
+ # $Id: http.rb 13657 2007-10-08 11:16:54Z gotoyuzo $
26
+ #++
27
+
28
+ require 'net/protocol'
29
+ require 'uri'
30
+
31
+ module Net #:nodoc:
32
+
33
+ # :stopdoc:
34
+ class HTTPBadResponse < StandardError; end
35
+ class HTTPHeaderSyntaxError < StandardError; end
36
+ # :startdoc:
37
+
38
+ # == What Is This Library?
39
+ #
40
+ # This library provides your program functions to access WWW
41
+ # documents via HTTP, Hyper Text Transfer Protocol version 1.1.
42
+ # For details of HTTP, refer [RFC2616]
43
+ # (http://www.ietf.org/rfc/rfc2616.txt).
44
+ #
45
+ # == Examples
46
+ #
47
+ # === Getting Document From WWW Server
48
+ #
49
+ # Example #1: Simple GET+print
50
+ #
51
+ # require 'net/http'
52
+ # Net::HTTP.get_print 'www.example.com', '/index.html'
53
+ #
54
+ # Example #2: Simple GET+print by URL
55
+ #
56
+ # require 'net/http'
57
+ # require 'uri'
58
+ # Net::HTTP.get_print URI.parse('http://www.example.com/index.html')
59
+ #
60
+ # Example #3: More generic GET+print
61
+ #
62
+ # require 'net/http'
63
+ # require 'uri'
64
+ #
65
+ # url = URI.parse('http://www.example.com/index.html')
66
+ # res = Net::HTTP.start(url.host, url.port) {|http|
67
+ # http.get('/index.html')
68
+ # }
69
+ # puts res.body
70
+ #
71
+ # Example #4: More generic GET+print
72
+ #
73
+ # require 'net/http'
74
+ #
75
+ # url = URI.parse('http://www.example.com/index.html')
76
+ # req = Net::HTTP::Get.new(url.path)
77
+ # res = Net::HTTP.start(url.host, url.port) {|http|
78
+ # http.request(req)
79
+ # }
80
+ # puts res.body
81
+ #
82
+ # === Posting Form Data
83
+ #
84
+ # require 'net/http'
85
+ # require 'uri'
86
+ #
87
+ # #1: Simple POST
88
+ # res = Net::HTTP.post_form(URI.parse('http://www.example.com/search.cgi'),
89
+ # {'q'=>'ruby', 'max'=>'50'})
90
+ # puts res.body
91
+ #
92
+ # #2: POST with basic authentication
93
+ # res = Net::HTTP.post_form(URI.parse('http://jack:pass@www.example.com/todo.cgi'),
94
+ # {'from'=>'2005-01-01', 'to'=>'2005-03-31'})
95
+ # puts res.body
96
+ #
97
+ # #3: Detailed control
98
+ # url = URI.parse('http://www.example.com/todo.cgi')
99
+ # req = Net::HTTP::Post.new(url.path)
100
+ # req.basic_auth 'jack', 'pass'
101
+ # req.set_form_data({'from'=>'2005-01-01', 'to'=>'2005-03-31'}, ';')
102
+ # res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }
103
+ # case res
104
+ # when Net::HTTPSuccess, Net::HTTPRedirection
105
+ # # OK
106
+ # else
107
+ # res.error!
108
+ # end
109
+ #
110
+ # === Accessing via Proxy
111
+ #
112
+ # Net::HTTP.Proxy creates http proxy class. It has same
113
+ # methods of Net::HTTP but its instances always connect to
114
+ # proxy, instead of given host.
115
+ #
116
+ # require 'net/http'
117
+ #
118
+ # proxy_addr = 'your.proxy.host'
119
+ # proxy_port = 8080
120
+ # :
121
+ # Net::HTTP::Proxy(proxy_addr, proxy_port).start('www.example.com') {|http|
122
+ # # always connect to your.proxy.addr:8080
123
+ # :
124
+ # }
125
+ #
126
+ # Since Net::HTTP.Proxy returns Net::HTTP itself when proxy_addr is nil,
127
+ # there's no need to change code if there's proxy or not.
128
+ #
129
+ # There are two additional parameters in Net::HTTP.Proxy which allow to
130
+ # specify proxy user name and password:
131
+ #
132
+ # Net::HTTP::Proxy(proxy_addr, proxy_port, proxy_user = nil, proxy_pass = nil)
133
+ #
134
+ # You may use them to work with authorization-enabled proxies:
135
+ #
136
+ # require 'net/http'
137
+ # require 'uri'
138
+ #
139
+ # proxy_host = 'your.proxy.host'
140
+ # proxy_port = 8080
141
+ # uri = URI.parse(ENV['http_proxy'])
142
+ # proxy_user, proxy_pass = uri.userinfo.split(/:/) if uri.userinfo
143
+ # Net::HTTP::Proxy(proxy_host, proxy_port,
144
+ # proxy_user, proxy_pass).start('www.example.com') {|http|
145
+ # # always connect to your.proxy.addr:8080 using specified username and password
146
+ # :
147
+ # }
148
+ #
149
+ # Note that net/http never rely on HTTP_PROXY environment variable.
150
+ # If you want to use proxy, set it explicitly.
151
+ #
152
+ # === Following Redirection
153
+ #
154
+ # require 'net/http'
155
+ # require 'uri'
156
+ #
157
+ # def fetch(uri_str, limit = 10)
158
+ # # You should choose better exception.
159
+ # raise ArgumentError, 'HTTP redirect too deep' if limit == 0
160
+ #
161
+ # response = Net::HTTP.get_response(URI.parse(uri_str))
162
+ # case response
163
+ # when Net::HTTPSuccess then response
164
+ # when Net::HTTPRedirection then fetch(response['location'], limit - 1)
165
+ # else
166
+ # response.error!
167
+ # end
168
+ # end
169
+ #
170
+ # print fetch('http://www.ruby-lang.org')
171
+ #
172
+ # Net::HTTPSuccess and Net::HTTPRedirection is a HTTPResponse class.
173
+ # All HTTPResponse objects belong to its own response class which
174
+ # indicate HTTP result status. For details of response classes,
175
+ # see section "HTTP Response Classes".
176
+ #
177
+ # === Basic Authentication
178
+ #
179
+ # require 'net/http'
180
+ #
181
+ # Net::HTTP.start('www.example.com') {|http|
182
+ # req = Net::HTTP::Get.new('/secret-page.html')
183
+ # req.basic_auth 'account', 'password'
184
+ # response = http.request(req)
185
+ # print response.body
186
+ # }
187
+ #
188
+ # === HTTP Request Classes
189
+ #
190
+ # Here is HTTP request class hierarchy.
191
+ #
192
+ # Net::HTTPRequest
193
+ # Net::HTTP::Get
194
+ # Net::HTTP::Head
195
+ # Net::HTTP::Post
196
+ # Net::HTTP::Put
197
+ # Net::HTTP::Proppatch
198
+ # Net::HTTP::Lock
199
+ # Net::HTTP::Unlock
200
+ # Net::HTTP::Options
201
+ # Net::HTTP::Propfind
202
+ # Net::HTTP::Delete
203
+ # Net::HTTP::Move
204
+ # Net::HTTP::Copy
205
+ # Net::HTTP::Mkcol
206
+ # Net::HTTP::Trace
207
+ #
208
+ # === HTTP Response Classes
209
+ #
210
+ # Here is HTTP response class hierarchy.
211
+ # All classes are defined in Net module.
212
+ #
213
+ # HTTPResponse
214
+ # HTTPUnknownResponse
215
+ # HTTPInformation # 1xx
216
+ # HTTPContinue # 100
217
+ # HTTPSwitchProtocl # 101
218
+ # HTTPSuccess # 2xx
219
+ # HTTPOK # 200
220
+ # HTTPCreated # 201
221
+ # HTTPAccepted # 202
222
+ # HTTPNonAuthoritativeInformation # 203
223
+ # HTTPNoContent # 204
224
+ # HTTPResetContent # 205
225
+ # HTTPPartialContent # 206
226
+ # HTTPRedirection # 3xx
227
+ # HTTPMultipleChoice # 300
228
+ # HTTPMovedPermanently # 301
229
+ # HTTPFound # 302
230
+ # HTTPSeeOther # 303
231
+ # HTTPNotModified # 304
232
+ # HTTPUseProxy # 305
233
+ # HTTPTemporaryRedirect # 307
234
+ # HTTPClientError # 4xx
235
+ # HTTPBadRequest # 400
236
+ # HTTPUnauthorized # 401
237
+ # HTTPPaymentRequired # 402
238
+ # HTTPForbidden # 403
239
+ # HTTPNotFound # 404
240
+ # HTTPMethodNotAllowed # 405
241
+ # HTTPNotAcceptable # 406
242
+ # HTTPProxyAuthenticationRequired # 407
243
+ # HTTPRequestTimeOut # 408
244
+ # HTTPConflict # 409
245
+ # HTTPGone # 410
246
+ # HTTPLengthRequired # 411
247
+ # HTTPPreconditionFailed # 412
248
+ # HTTPRequestEntityTooLarge # 413
249
+ # HTTPRequestURITooLong # 414
250
+ # HTTPUnsupportedMediaType # 415
251
+ # HTTPRequestedRangeNotSatisfiable # 416
252
+ # HTTPExpectationFailed # 417
253
+ # HTTPServerError # 5xx
254
+ # HTTPInternalServerError # 500
255
+ # HTTPNotImplemented # 501
256
+ # HTTPBadGateway # 502
257
+ # HTTPServiceUnavailable # 503
258
+ # HTTPGatewayTimeOut # 504
259
+ # HTTPVersionNotSupported # 505
260
+ #
261
+ # == Switching Net::HTTP versions
262
+ #
263
+ # You can use net/http.rb 1.1 features (bundled with Ruby 1.6)
264
+ # by calling HTTP.version_1_1. Calling Net::HTTP.version_1_2
265
+ # allows you to use 1.2 features again.
266
+ #
267
+ # # example
268
+ # Net::HTTP.start {|http1| ...(http1 has 1.2 features)... }
269
+ #
270
+ # Net::HTTP.version_1_1
271
+ # Net::HTTP.start {|http2| ...(http2 has 1.1 features)... }
272
+ #
273
+ # Net::HTTP.version_1_2
274
+ # Net::HTTP.start {|http3| ...(http3 has 1.2 features)... }
275
+ #
276
+ # This function is NOT thread-safe.
277
+ #
278
+ class HTTP < Protocol
279
+
280
+ # :stopdoc:
281
+ Revision = %q$Revision: 13657 $.split[1]
282
+ HTTPVersion = '1.1'
283
+ @newimpl = true
284
+ # :startdoc:
285
+
286
+ # Turns on net/http 1.2 (ruby 1.8) features.
287
+ # Defaults to ON in ruby 1.8.
288
+ #
289
+ # I strongly recommend to call this method always.
290
+ #
291
+ # require 'net/http'
292
+ # Net::HTTP.version_1_2
293
+ #
294
+ def HTTP.version_1_2
295
+ @newimpl = true
296
+ end
297
+
298
+ # Turns on net/http 1.1 (ruby 1.6) features.
299
+ # Defaults to OFF in ruby 1.8.
300
+ def HTTP.version_1_1
301
+ @newimpl = false
302
+ end
303
+
304
+ # true if net/http is in version 1.2 mode.
305
+ # Defaults to true.
306
+ def HTTP.version_1_2?
307
+ @newimpl
308
+ end
309
+
310
+ # true if net/http is in version 1.1 compatible mode.
311
+ # Defaults to true.
312
+ def HTTP.version_1_1?
313
+ not @newimpl
314
+ end
315
+
316
+ class << HTTP
317
+ alias is_version_1_1? version_1_1? #:nodoc:
318
+ alias is_version_1_2? version_1_2? #:nodoc:
319
+ end
320
+
321
+ #
322
+ # short cut methods
323
+ #
324
+
325
+ #
326
+ # Get body from target and output it to +$stdout+. The
327
+ # target can either be specified as (+uri+), or as
328
+ # (+host+, +path+, +port+ = 80); so:
329
+ #
330
+ # Net::HTTP.get_print URI.parse('http://www.example.com/index.html')
331
+ #
332
+ # or:
333
+ #
334
+ # Net::HTTP.get_print 'www.example.com', '/index.html'
335
+ #
336
+ def HTTP.get_print(uri_or_host, path = nil, port = nil)
337
+ get_response(uri_or_host, path, port) {|res|
338
+ res.read_body do |chunk|
339
+ $stdout.print chunk
340
+ end
341
+ }
342
+ nil
343
+ end
344
+
345
+ # Send a GET request to the target and return the response
346
+ # as a string. The target can either be specified as
347
+ # (+uri+), or as (+host+, +path+, +port+ = 80); so:
348
+ #
349
+ # print Net::HTTP.get(URI.parse('http://www.example.com/index.html'))
350
+ #
351
+ # or:
352
+ #
353
+ # print Net::HTTP.get('www.example.com', '/index.html')
354
+ #
355
+ def HTTP.get(uri_or_host, path = nil, port = nil)
356
+ get_response(uri_or_host, path, port).body
357
+ end
358
+
359
+ # Send a GET request to the target and return the response
360
+ # as a Net::HTTPResponse object. The target can either be specified as
361
+ # (+uri+), or as (+host+, +path+, +port+ = 80); so:
362
+ #
363
+ # res = Net::HTTP.get_response(URI.parse('http://www.example.com/index.html'))
364
+ # print res.body
365
+ #
366
+ # or:
367
+ #
368
+ # res = Net::HTTP.get_response('www.example.com', '/index.html')
369
+ # print res.body
370
+ #
371
+ def HTTP.get_response(uri_or_host, path = nil, port = nil, &block)
372
+ if path
373
+ host = uri_or_host
374
+ new(host, port || HTTP.default_port).start {|http|
375
+ return http.request_get(path, &block)
376
+ }
377
+ else
378
+ uri = uri_or_host
379
+ new(uri.host, uri.port).start {|http|
380
+ return http.request_get(uri.request_uri, &block)
381
+ }
382
+ end
383
+ end
384
+
385
+ # Posts HTML form data to the +URL+.
386
+ # Form data must be represented as a Hash of String to String, e.g:
387
+ #
388
+ # { "cmd" => "search", "q" => "ruby", "max" => "50" }
389
+ #
390
+ # This method also does Basic Authentication iff +URL+.user exists.
391
+ #
392
+ # Example:
393
+ #
394
+ # require 'net/http'
395
+ # require 'uri'
396
+ #
397
+ # HTTP.post_form URI.parse('http://www.example.com/search.cgi'),
398
+ # { "q" => "ruby", "max" => "50" }
399
+ #
400
+ def HTTP.post_form(url, params)
401
+ req = Post.new(url.path)
402
+ req.form_data = params
403
+ req.basic_auth url.user, url.password if url.user
404
+ new(url.host, url.port).start {|http|
405
+ http.request(req)
406
+ }
407
+ end
408
+
409
+ #
410
+ # HTTP session management
411
+ #
412
+
413
+ # The default port to use for HTTP requests; defaults to 80.
414
+ def HTTP.default_port
415
+ http_default_port()
416
+ end
417
+
418
+ # The default port to use for HTTP requests; defaults to 80.
419
+ def HTTP.http_default_port
420
+ 80
421
+ end
422
+
423
+ # The default port to use for HTTPS requests; defaults to 443.
424
+ def HTTP.https_default_port
425
+ 443
426
+ end
427
+
428
+ def HTTP.socket_type #:nodoc: obsolete
429
+ BufferedIO
430
+ end
431
+
432
+ # creates a new Net::HTTP object and opens its TCP connection and
433
+ # HTTP session. If the optional block is given, the newly
434
+ # created Net::HTTP object is passed to it and closed when the
435
+ # block finishes. In this case, the return value of this method
436
+ # is the return value of the block. If no block is given, the
437
+ # return value of this method is the newly created Net::HTTP object
438
+ # itself, and the caller is responsible for closing it upon completion.
439
+ def HTTP.start(address, port = nil, p_addr = nil, p_port = nil, p_user = nil, p_pass = nil, &block) # :yield: +http+
440
+ new(address, port, p_addr, p_port, p_user, p_pass).start(&block)
441
+ end
442
+
443
+ class << HTTP
444
+ alias newobj new
445
+ end
446
+
447
+ # Creates a new Net::HTTP object.
448
+ # If +proxy_addr+ is given, creates an Net::HTTP object with proxy support.
449
+ # This method does not open the TCP connection.
450
+ def HTTP.new(address, port = nil, p_addr = nil, p_port = nil, p_user = nil, p_pass = nil)
451
+ h = Proxy(p_addr, p_port, p_user, p_pass).newobj(address, port)
452
+ h.instance_eval {
453
+ @newimpl = ::Net::HTTP.version_1_2?
454
+ }
455
+ h
456
+ end
457
+
458
+ # Creates a new Net::HTTP object for the specified +address+.
459
+ # This method does not open the TCP connection.
460
+ def initialize(address, port = nil)
461
+ @address = address
462
+ @port = (port || HTTP.default_port)
463
+ @curr_http_version = HTTPVersion
464
+ @seems_1_0_server = false
465
+ @close_on_empty_response = false
466
+ @socket = nil
467
+ @started = false
468
+ @open_timeout = nil
469
+ @read_timeout = 60
470
+ @debug_output = nil
471
+ @use_ssl = false
472
+ @ssl_context = nil
473
+ end
474
+
475
+ def inspect
476
+ "#<#{self.class} #{@address}:#{@port} open=#{started?}>"
477
+ end
478
+
479
+ # *WARNING* This method causes serious security hole.
480
+ # Never use this method in production code.
481
+ #
482
+ # Set an output stream for debugging.
483
+ #
484
+ # http = Net::HTTP.new
485
+ # http.set_debug_output $stderr
486
+ # http.start { .... }
487
+ #
488
+ def set_debug_output(output)
489
+ warn 'Net::HTTP#set_debug_output called after HTTP started' if started?
490
+ @debug_output = output
491
+ end
492
+
493
+ # The host name to connect to.
494
+ attr_reader :address
495
+
496
+ # The port number to connect to.
497
+ attr_reader :port
498
+
499
+ # Seconds to wait until connection is opened.
500
+ # If the HTTP object cannot open a connection in this many seconds,
501
+ # it raises a TimeoutError exception.
502
+ attr_accessor :open_timeout
503
+
504
+ # Seconds to wait until reading one block (by one read(2) call).
505
+ # If the HTTP object cannot open a connection in this many seconds,
506
+ # it raises a TimeoutError exception.
507
+ attr_reader :read_timeout
508
+
509
+ # Setter for the read_timeout attribute.
510
+ def read_timeout=(sec)
511
+ @socket.read_timeout = sec if @socket
512
+ @read_timeout = sec
513
+ end
514
+
515
+ # returns true if the HTTP session is started.
516
+ def started?
517
+ @started
518
+ end
519
+
520
+ alias active? started? #:nodoc: obsolete
521
+
522
+ attr_accessor :close_on_empty_response
523
+
524
+ # returns true if use SSL/TLS with HTTP.
525
+ def use_ssl?
526
+ false # redefined in net/https
527
+ end
528
+
529
+ # Opens TCP connection and HTTP session.
530
+ #
531
+ # When this method is called with block, gives a HTTP object
532
+ # to the block and closes the TCP connection / HTTP session
533
+ # after the block executed.
534
+ #
535
+ # When called with a block, returns the return value of the
536
+ # block; otherwise, returns self.
537
+ #
538
+ def start # :yield: http
539
+ raise IOError, 'HTTP session already opened' if @started
540
+ if block_given?
541
+ begin
542
+ do_start
543
+ return yield(self)
544
+ ensure
545
+ do_finish
546
+ end
547
+ end
548
+ do_start
549
+ self
550
+ end
551
+
552
+ def do_start
553
+ connect
554
+ @started = true
555
+ end
556
+ private :do_start
557
+
558
+ def connect
559
+ D "opening connection to #{conn_address()}..."
560
+ s = timeout(@open_timeout) { TCPSocket.open(conn_address(), conn_port()) }
561
+ D "opened"
562
+ if use_ssl?
563
+ unless @ssl_context.verify_mode
564
+ warn "warning: peer certificate won't be verified in this SSL session"
565
+ @ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
566
+ end
567
+ s = OpenSSL::SSL::SSLSocket.new(s, @ssl_context)
568
+ s.sync_close = true
569
+ end
570
+ @socket = BufferedIO.new(s)
571
+ @socket.read_timeout = @read_timeout
572
+ @socket.debug_output = @debug_output
573
+ if use_ssl?
574
+ if proxy?
575
+ @socket.writeline sprintf('CONNECT %s:%s HTTP/%s',
576
+ @address, @port, HTTPVersion)
577
+ @socket.writeline "Host: #{@address}:#{@port}"
578
+ if proxy_user
579
+ credential = ["#{proxy_user}:#{proxy_pass}"].pack('m')
580
+ credential.delete!("\r\n")
581
+ @socket.writeline "Proxy-Authorization: Basic #{credential}"
582
+ end
583
+ @socket.writeline ''
584
+ HTTPResponse.read_new(@socket).value
585
+ end
586
+ s.connect
587
+ if @ssl_context.verify_mode != OpenSSL::SSL::VERIFY_NONE
588
+ s.post_connection_check(@address)
589
+ end
590
+ end
591
+ on_connect
592
+ end
593
+ private :connect
594
+
595
+ def on_connect
596
+ end
597
+ private :on_connect
598
+
599
+ # Finishes HTTP session and closes TCP connection.
600
+ # Raises IOError if not started.
601
+ def finish
602
+ raise IOError, 'HTTP session not yet started' unless started?
603
+ do_finish
604
+ end
605
+
606
+ def do_finish
607
+ @started = false
608
+ @socket.close if @socket and not @socket.closed?
609
+ @socket = nil
610
+ end
611
+ private :do_finish
612
+
613
+ #
614
+ # proxy
615
+ #
616
+
617
+ public
618
+
619
+ # no proxy
620
+ @is_proxy_class = false
621
+ @proxy_addr = nil
622
+ @proxy_port = nil
623
+ @proxy_user = nil
624
+ @proxy_pass = nil
625
+
626
+ # Creates an HTTP proxy class.
627
+ # Arguments are address/port of proxy host and username/password
628
+ # if authorization on proxy server is required.
629
+ # You can replace the HTTP class with created proxy class.
630
+ #
631
+ # If ADDRESS is nil, this method returns self (Net::HTTP).
632
+ #
633
+ # # Example
634
+ # proxy_class = Net::HTTP::Proxy('proxy.example.com', 8080)
635
+ # :
636
+ # proxy_class.start('www.ruby-lang.org') {|http|
637
+ # # connecting proxy.foo.org:8080
638
+ # :
639
+ # }
640
+ #
641
+ def HTTP.Proxy(p_addr, p_port = nil, p_user = nil, p_pass = nil)
642
+ return self unless p_addr
643
+ delta = ProxyDelta
644
+ proxyclass = Class.new(self)
645
+ proxyclass.module_eval {
646
+ include delta
647
+ # with proxy
648
+ @is_proxy_class = true
649
+ @proxy_address = p_addr
650
+ @proxy_port = p_port || default_port()
651
+ @proxy_user = p_user
652
+ @proxy_pass = p_pass
653
+ }
654
+ proxyclass
655
+ end
656
+
657
+ class << HTTP
658
+ # returns true if self is a class which was created by HTTP::Proxy.
659
+ def proxy_class?
660
+ @is_proxy_class
661
+ end
662
+
663
+ attr_reader :proxy_address
664
+ attr_reader :proxy_port
665
+ attr_reader :proxy_user
666
+ attr_reader :proxy_pass
667
+ end
668
+
669
+ # True if self is a HTTP proxy class.
670
+ def proxy?
671
+ self.class.proxy_class?
672
+ end
673
+
674
+ # Address of proxy host. If self does not use a proxy, nil.
675
+ def proxy_address
676
+ self.class.proxy_address
677
+ end
678
+
679
+ # Port number of proxy host. If self does not use a proxy, nil.
680
+ def proxy_port
681
+ self.class.proxy_port
682
+ end
683
+
684
+ # User name for accessing proxy. If self does not use a proxy, nil.
685
+ def proxy_user
686
+ self.class.proxy_user
687
+ end
688
+
689
+ # User password for accessing proxy. If self does not use a proxy, nil.
690
+ def proxy_pass
691
+ self.class.proxy_pass
692
+ end
693
+
694
+ alias proxyaddr proxy_address #:nodoc: obsolete
695
+ alias proxyport proxy_port #:nodoc: obsolete
696
+
697
+ private
698
+
699
+ # without proxy
700
+
701
+ def conn_address
702
+ address()
703
+ end
704
+
705
+ def conn_port
706
+ port()
707
+ end
708
+
709
+ def edit_path(path)
710
+ path
711
+ end
712
+
713
+ module ProxyDelta #:nodoc: internal use only
714
+ private
715
+
716
+ def conn_address
717
+ proxy_address()
718
+ end
719
+
720
+ def conn_port
721
+ proxy_port()
722
+ end
723
+
724
+ def edit_path(path)
725
+ use_ssl? ? path : "http://#{addr_port()}#{path}"
726
+ end
727
+ end
728
+
729
+ #
730
+ # HTTP operations
731
+ #
732
+
733
+ public
734
+
735
+ # Gets data from +path+ on the connected-to host.
736
+ # +header+ must be a Hash like { 'Accept' => '*/*', ... }.
737
+ #
738
+ # In version 1.1 (ruby 1.6), this method returns a pair of objects,
739
+ # a Net::HTTPResponse object and the entity body string.
740
+ # In version 1.2 (ruby 1.8), this method returns a Net::HTTPResponse
741
+ # object.
742
+ #
743
+ # If called with a block, yields each fragment of the
744
+ # entity body in turn as a string as it is read from
745
+ # the socket. Note that in this case, the returned response
746
+ # object will *not* contain a (meaningful) body.
747
+ #
748
+ # +dest+ argument is obsolete.
749
+ # It still works but you must not use it.
750
+ #
751
+ # In version 1.1, this method might raise an exception for
752
+ # 3xx (redirect). In this case you can get a HTTPResponse object
753
+ # by "anException.response".
754
+ #
755
+ # In version 1.2, this method never raises exception.
756
+ #
757
+ # # version 1.1 (bundled with Ruby 1.6)
758
+ # response, body = http.get('/index.html')
759
+ #
760
+ # # version 1.2 (bundled with Ruby 1.8 or later)
761
+ # response = http.get('/index.html')
762
+ #
763
+ # # using block
764
+ # File.open('result.txt', 'w') {|f|
765
+ # http.get('/~foo/') do |str|
766
+ # f.write str
767
+ # end
768
+ # }
769
+ #
770
+ def get(path, initheader = nil, dest = nil, &block) # :yield: +body_segment+
771
+ res = nil
772
+ request(Get.new(path, initheader)) {|r|
773
+ r.read_body dest, &block
774
+ res = r
775
+ }
776
+ unless @newimpl
777
+ res.value
778
+ return res, res.body
779
+ end
780
+
781
+ res
782
+ end
783
+
784
+ # Gets only the header from +path+ on the connected-to host.
785
+ # +header+ is a Hash like { 'Accept' => '*/*', ... }.
786
+ #
787
+ # This method returns a Net::HTTPResponse object.
788
+ #
789
+ # In version 1.1, this method might raise an exception for
790
+ # 3xx (redirect). On the case you can get a HTTPResponse object
791
+ # by "anException.response".
792
+ # In version 1.2, this method never raises an exception.
793
+ #
794
+ # response = nil
795
+ # Net::HTTP.start('some.www.server', 80) {|http|
796
+ # response = http.head('/index.html')
797
+ # }
798
+ # p response['content-type']
799
+ #
800
+ def head(path, initheader = nil)
801
+ res = request(Head.new(path, initheader))
802
+ res.value unless @newimpl
803
+ res
804
+ end
805
+
806
+ # Posts +data+ (must be a String) to +path+. +header+ must be a Hash
807
+ # like { 'Accept' => '*/*', ... }.
808
+ #
809
+ # In version 1.1 (ruby 1.6), this method returns a pair of objects, a
810
+ # Net::HTTPResponse object and an entity body string.
811
+ # In version 1.2 (ruby 1.8), this method returns a Net::HTTPResponse object.
812
+ #
813
+ # If called with a block, yields each fragment of the
814
+ # entity body in turn as a string as it are read from
815
+ # the socket. Note that in this case, the returned response
816
+ # object will *not* contain a (meaningful) body.
817
+ #
818
+ # +dest+ argument is obsolete.
819
+ # It still works but you must not use it.
820
+ #
821
+ # In version 1.1, this method might raise an exception for
822
+ # 3xx (redirect). In this case you can get an HTTPResponse object
823
+ # by "anException.response".
824
+ # In version 1.2, this method never raises exception.
825
+ #
826
+ # # version 1.1
827
+ # response, body = http.post('/cgi-bin/search.rb', 'query=foo')
828
+ #
829
+ # # version 1.2
830
+ # response = http.post('/cgi-bin/search.rb', 'query=foo')
831
+ #
832
+ # # using block
833
+ # File.open('result.txt', 'w') {|f|
834
+ # http.post('/cgi-bin/search.rb', 'query=foo') do |str|
835
+ # f.write str
836
+ # end
837
+ # }
838
+ #
839
+ # You should set Content-Type: header field for POST.
840
+ # If no Content-Type: field given, this method uses
841
+ # "application/x-www-form-urlencoded" by default.
842
+ #
843
+ def post(path, data, initheader = nil, dest = nil, &block) # :yield: +body_segment+
844
+ res = nil
845
+ request(Post.new(path, initheader), data) {|r|
846
+ r.read_body dest, &block
847
+ res = r
848
+ }
849
+ unless @newimpl
850
+ res.value
851
+ return res, res.body
852
+ end
853
+ res
854
+ end
855
+
856
+ def put(path, data, initheader = nil) #:nodoc:
857
+ res = request(Put.new(path, initheader), data)
858
+ res.value unless @newimpl
859
+ res
860
+ end
861
+
862
+ # Sends a PROPPATCH request to the +path+ and gets a response,
863
+ # as an HTTPResponse object.
864
+ def proppatch(path, body, initheader = nil)
865
+ request(Proppatch.new(path, initheader), body)
866
+ end
867
+
868
+ # Sends a LOCK request to the +path+ and gets a response,
869
+ # as an HTTPResponse object.
870
+ def lock(path, body, initheader = nil)
871
+ request(Lock.new(path, initheader), body)
872
+ end
873
+
874
+ # Sends a UNLOCK request to the +path+ and gets a response,
875
+ # as an HTTPResponse object.
876
+ def unlock(path, body, initheader = nil)
877
+ request(Unlock.new(path, initheader), body)
878
+ end
879
+
880
+ # Sends a OPTIONS request to the +path+ and gets a response,
881
+ # as an HTTPResponse object.
882
+ def options(path, initheader = nil)
883
+ request(Options.new(path, initheader))
884
+ end
885
+
886
+ # Sends a PROPFIND request to the +path+ and gets a response,
887
+ # as an HTTPResponse object.
888
+ def propfind(path, body = nil, initheader = {'Depth' => '0'})
889
+ request(Propfind.new(path, initheader), body)
890
+ end
891
+
892
+ # Sends a DELETE request to the +path+ and gets a response,
893
+ # as an HTTPResponse object.
894
+ def delete(path, initheader = {'Depth' => 'Infinity'})
895
+ request(Delete.new(path, initheader))
896
+ end
897
+
898
+ # Sends a MOVE request to the +path+ and gets a response,
899
+ # as an HTTPResponse object.
900
+ def move(path, initheader = nil)
901
+ request(Move.new(path, initheader))
902
+ end
903
+
904
+ # Sends a COPY request to the +path+ and gets a response,
905
+ # as an HTTPResponse object.
906
+ def copy(path, initheader = nil)
907
+ request(Copy.new(path, initheader))
908
+ end
909
+
910
+ # Sends a MKCOL request to the +path+ and gets a response,
911
+ # as an HTTPResponse object.
912
+ def mkcol(path, body = nil, initheader = nil)
913
+ request(Mkcol.new(path, initheader), body)
914
+ end
915
+
916
+ # Sends a TRACE request to the +path+ and gets a response,
917
+ # as an HTTPResponse object.
918
+ def trace(path, initheader = nil)
919
+ request(Trace.new(path, initheader))
920
+ end
921
+
922
+ # Sends a GET request to the +path+ and gets a response,
923
+ # as an HTTPResponse object.
924
+ #
925
+ # When called with a block, yields an HTTPResponse object.
926
+ # The body of this response will not have been read yet;
927
+ # the caller can process it using HTTPResponse#read_body,
928
+ # if desired.
929
+ #
930
+ # Returns the response.
931
+ #
932
+ # This method never raises Net::* exceptions.
933
+ #
934
+ # response = http.request_get('/index.html')
935
+ # # The entity body is already read here.
936
+ # p response['content-type']
937
+ # puts response.body
938
+ #
939
+ # # using block
940
+ # http.request_get('/index.html') {|response|
941
+ # p response['content-type']
942
+ # response.read_body do |str| # read body now
943
+ # print str
944
+ # end
945
+ # }
946
+ #
947
+ def request_get(path, initheader = nil, &block) # :yield: +response+
948
+ request(Get.new(path, initheader), &block)
949
+ end
950
+
951
+ # Sends a HEAD request to the +path+ and gets a response,
952
+ # as an HTTPResponse object.
953
+ #
954
+ # Returns the response.
955
+ #
956
+ # This method never raises Net::* exceptions.
957
+ #
958
+ # response = http.request_head('/index.html')
959
+ # p response['content-type']
960
+ #
961
+ def request_head(path, initheader = nil, &block)
962
+ request(Head.new(path, initheader), &block)
963
+ end
964
+
965
+ # Sends a POST request to the +path+ and gets a response,
966
+ # as an HTTPResponse object.
967
+ #
968
+ # When called with a block, yields an HTTPResponse object.
969
+ # The body of this response will not have been read yet;
970
+ # the caller can process it using HTTPResponse#read_body,
971
+ # if desired.
972
+ #
973
+ # Returns the response.
974
+ #
975
+ # This method never raises Net::* exceptions.
976
+ #
977
+ # # example
978
+ # response = http.request_post('/cgi-bin/nice.rb', 'datadatadata...')
979
+ # p response.status
980
+ # puts response.body # body is already read
981
+ #
982
+ # # using block
983
+ # http.request_post('/cgi-bin/nice.rb', 'datadatadata...') {|response|
984
+ # p response.status
985
+ # p response['content-type']
986
+ # response.read_body do |str| # read body now
987
+ # print str
988
+ # end
989
+ # }
990
+ #
991
+ def request_post(path, data, initheader = nil, &block) # :yield: +response+
992
+ request Post.new(path, initheader), data, &block
993
+ end
994
+
995
+ def request_put(path, data, initheader = nil, &block) #:nodoc:
996
+ request Put.new(path, initheader), data, &block
997
+ end
998
+
999
+ alias get2 request_get #:nodoc: obsolete
1000
+ alias head2 request_head #:nodoc: obsolete
1001
+ alias post2 request_post #:nodoc: obsolete
1002
+ alias put2 request_put #:nodoc: obsolete
1003
+
1004
+
1005
+ # Sends an HTTP request to the HTTP server.
1006
+ # This method also sends DATA string if DATA is given.
1007
+ #
1008
+ # Returns a HTTPResponse object.
1009
+ #
1010
+ # This method never raises Net::* exceptions.
1011
+ #
1012
+ # response = http.send_request('GET', '/index.html')
1013
+ # puts response.body
1014
+ #
1015
+ def send_request(name, path, data = nil, header = nil)
1016
+ r = HTTPGenericRequest.new(name,(data ? true : false),true,path,header)
1017
+ request r, data
1018
+ end
1019
+
1020
+ # Sends an HTTPRequest object REQUEST to the HTTP server.
1021
+ # This method also sends DATA string if REQUEST is a post/put request.
1022
+ # Giving DATA for get/head request causes ArgumentError.
1023
+ #
1024
+ # When called with a block, yields an HTTPResponse object.
1025
+ # The body of this response will not have been read yet;
1026
+ # the caller can process it using HTTPResponse#read_body,
1027
+ # if desired.
1028
+ #
1029
+ # Returns a HTTPResponse object.
1030
+ #
1031
+ # This method never raises Net::* exceptions.
1032
+ #
1033
+ def request(req, body = nil, &block) # :yield: +response+
1034
+ unless started?
1035
+ start {
1036
+ req['connection'] ||= 'close'
1037
+ return request(req, body, &block)
1038
+ }
1039
+ end
1040
+ if proxy_user()
1041
+ unless use_ssl?
1042
+ req.proxy_basic_auth proxy_user(), proxy_pass()
1043
+ end
1044
+ end
1045
+
1046
+ req.set_body_internal body
1047
+ begin_transport req
1048
+ req.exec @socket, @curr_http_version, edit_path(req.path)
1049
+ begin
1050
+ res = HTTPResponse.read_new(@socket)
1051
+ end while res.kind_of?(HTTPContinue)
1052
+ res.reading_body(@socket, req.response_body_permitted?) {
1053
+ yield res if block_given?
1054
+ }
1055
+ end_transport req, res
1056
+
1057
+ res
1058
+ end
1059
+
1060
+ private
1061
+
1062
+ def begin_transport(req)
1063
+ if @socket.closed?
1064
+ connect
1065
+ end
1066
+ if @seems_1_0_server
1067
+ req['connection'] ||= 'close'
1068
+ end
1069
+ if not req.response_body_permitted? and @close_on_empty_response
1070
+ req['connection'] ||= 'close'
1071
+ end
1072
+ req['host'] ||= addr_port()
1073
+ end
1074
+
1075
+ def end_transport(req, res)
1076
+ @curr_http_version = res.http_version
1077
+ if not res.body and @close_on_empty_response
1078
+ D 'Conn close'
1079
+ @socket.close
1080
+ elsif keep_alive?(req, res)
1081
+ D 'Conn keep-alive'
1082
+ if @socket.closed?
1083
+ D 'Conn (but seems 1.0 server)'
1084
+ @seems_1_0_server = true
1085
+ end
1086
+ else
1087
+ D 'Conn close'
1088
+ @socket.close
1089
+ end
1090
+ end
1091
+
1092
+ def keep_alive?(req, res)
1093
+ return false if /close/i =~ req['connection'].to_s
1094
+ return false if @seems_1_0_server
1095
+ return true if /keep-alive/i =~ res['connection'].to_s
1096
+ return false if /close/i =~ res['connection'].to_s
1097
+ return true if /keep-alive/i =~ res['proxy-connection'].to_s
1098
+ return false if /close/i =~ res['proxy-connection'].to_s
1099
+ (@curr_http_version == '1.1')
1100
+ end
1101
+
1102
+ #
1103
+ # utils
1104
+ #
1105
+
1106
+ private
1107
+
1108
+ def addr_port
1109
+ if use_ssl?
1110
+ address() + (port == HTTP.https_default_port ? '' : ":#{port()}")
1111
+ else
1112
+ address() + (port == HTTP.http_default_port ? '' : ":#{port()}")
1113
+ end
1114
+ end
1115
+
1116
+ def D(msg)
1117
+ return unless @debug_output
1118
+ @debug_output << msg
1119
+ @debug_output << "\n"
1120
+ end
1121
+
1122
+ end
1123
+
1124
+ HTTPSession = HTTP
1125
+
1126
+
1127
+ #
1128
+ # Header module.
1129
+ #
1130
+ # Provides access to @header in the mixed-into class as a hash-like
1131
+ # object, except with case-insensitive keys. Also provides
1132
+ # methods for accessing commonly-used header values in a more
1133
+ # convenient format.
1134
+ #
1135
+ module HTTPHeader
1136
+
1137
+ def initialize_http_header(initheader)
1138
+ @header = {}
1139
+ return unless initheader
1140
+ initheader.each do |key, value|
1141
+ warn "net/http: warning: duplicated HTTP header: #{key}" if key?(key) and $VERBOSE
1142
+ @header[key.downcase] = [value.strip]
1143
+ end
1144
+ end
1145
+
1146
+ def size #:nodoc: obsolete
1147
+ @header.size
1148
+ end
1149
+
1150
+ alias length size #:nodoc: obsolete
1151
+
1152
+ # Returns the header field corresponding to the case-insensitive key.
1153
+ # For example, a key of "Content-Type" might return "text/html"
1154
+ def [](key)
1155
+ a = @header[key.downcase] or return nil
1156
+ a.join(', ')
1157
+ end
1158
+
1159
+ # Sets the header field corresponding to the case-insensitive key.
1160
+ def []=(key, val)
1161
+ unless val
1162
+ @header.delete key.downcase
1163
+ return val
1164
+ end
1165
+ @header[key.downcase] = [val]
1166
+ end
1167
+
1168
+ # [Ruby 1.8.3]
1169
+ # Adds header field instead of replace.
1170
+ # Second argument +val+ must be a String.
1171
+ # See also #[]=, #[] and #get_fields.
1172
+ #
1173
+ # request.add_field 'X-My-Header', 'a'
1174
+ # p request['X-My-Header'] #=> "a"
1175
+ # p request.get_fields('X-My-Header') #=> ["a"]
1176
+ # request.add_field 'X-My-Header', 'b'
1177
+ # p request['X-My-Header'] #=> "a, b"
1178
+ # p request.get_fields('X-My-Header') #=> ["a", "b"]
1179
+ # request.add_field 'X-My-Header', 'c'
1180
+ # p request['X-My-Header'] #=> "a, b, c"
1181
+ # p request.get_fields('X-My-Header') #=> ["a", "b", "c"]
1182
+ #
1183
+ def add_field(key, val)
1184
+ if @header.key?(key.downcase)
1185
+ @header[key.downcase].push val
1186
+ else
1187
+ @header[key.downcase] = [val]
1188
+ end
1189
+ end
1190
+
1191
+ # [Ruby 1.8.3]
1192
+ # Returns an array of header field strings corresponding to the
1193
+ # case-insensitive +key+. This method allows you to get duplicated
1194
+ # header fields without any processing. See also #[].
1195
+ #
1196
+ # p response.get_fields('Set-Cookie')
1197
+ # #=> ["session=al98axx; expires=Fri, 31-Dec-1999 23:58:23",
1198
+ # "query=rubyscript; expires=Fri, 31-Dec-1999 23:58:23"]
1199
+ # p response['Set-Cookie']
1200
+ # #=> "session=al98axx; expires=Fri, 31-Dec-1999 23:58:23, query=rubyscript; expires=Fri, 31-Dec-1999 23:58:23"
1201
+ #
1202
+ def get_fields(key)
1203
+ return nil unless @header[key.downcase]
1204
+ @header[key.downcase].dup
1205
+ end
1206
+
1207
+ # Returns the header field corresponding to the case-insensitive key.
1208
+ # Returns the default value +args+, or the result of the block, or nil,
1209
+ # if there's no header field named key. See Hash#fetch
1210
+ def fetch(key, *args, &block) #:yield: +key+
1211
+ a = @header.fetch(key.downcase, *args, &block)
1212
+ a.join(', ')
1213
+ end
1214
+
1215
+ # Iterates for each header names and values.
1216
+ def each_header #:yield: +key+, +value+
1217
+ @header.each do |k,va|
1218
+ yield k, va.join(', ')
1219
+ end
1220
+ end
1221
+
1222
+ alias each each_header
1223
+
1224
+ # Iterates for each header names.
1225
+ def each_name(&block) #:yield: +key+
1226
+ @header.each_key(&block)
1227
+ end
1228
+
1229
+ alias each_key each_name
1230
+
1231
+ # Iterates for each capitalized header names.
1232
+ def each_capitalized_name(&block) #:yield: +key+
1233
+ @header.each_key do |k|
1234
+ yield capitalize(k)
1235
+ end
1236
+ end
1237
+
1238
+ # Iterates for each header values.
1239
+ def each_value #:yield: +value+
1240
+ @header.each_value do |va|
1241
+ yield va.join(', ')
1242
+ end
1243
+ end
1244
+
1245
+ # Removes a header field.
1246
+ def delete(key)
1247
+ @header.delete(key.downcase)
1248
+ end
1249
+
1250
+ # true if +key+ header exists.
1251
+ def key?(key)
1252
+ @header.key?(key.downcase)
1253
+ end
1254
+
1255
+ # Returns a Hash consist of header names and values.
1256
+ def to_hash
1257
+ @header.dup
1258
+ end
1259
+
1260
+ # As for #each_header, except the keys are provided in capitalized form.
1261
+ def each_capitalized
1262
+ @header.each do |k,v|
1263
+ yield capitalize(k), v.join(', ')
1264
+ end
1265
+ end
1266
+
1267
+ alias canonical_each each_capitalized
1268
+
1269
+ def capitalize(name)
1270
+ name.split(/-/).map {|s| s.capitalize }.join('-')
1271
+ end
1272
+ private :capitalize
1273
+
1274
+ # Returns an Array of Range objects which represents Range: header field,
1275
+ # or +nil+ if there is no such header.
1276
+ def range
1277
+ return nil unless @header['range']
1278
+ self['Range'].split(/,/).map {|spec|
1279
+ m = /bytes\s*=\s*(\d+)?\s*-\s*(\d+)?/i.match(spec) or
1280
+ raise HTTPHeaderSyntaxError, "wrong Range: #{spec}"
1281
+ d1 = m[1].to_i
1282
+ d2 = m[2].to_i
1283
+ if m[1] and m[2] then d1..d2
1284
+ elsif m[1] then d1..-1
1285
+ elsif m[2] then -d2..-1
1286
+ else
1287
+ raise HTTPHeaderSyntaxError, 'range is not specified'
1288
+ end
1289
+ }
1290
+ end
1291
+
1292
+ # Set Range: header from Range (arg r) or beginning index and
1293
+ # length from it (arg idx&len).
1294
+ #
1295
+ # req.range = (0..1023)
1296
+ # req.set_range 0, 1023
1297
+ #
1298
+ def set_range(r, e = nil)
1299
+ unless r
1300
+ @header.delete 'range'
1301
+ return r
1302
+ end
1303
+ r = (r...r+e) if e
1304
+ case r
1305
+ when Numeric
1306
+ n = r.to_i
1307
+ rangestr = (n > 0 ? "0-#{n-1}" : "-#{-n}")
1308
+ when Range
1309
+ first = r.first
1310
+ last = r.last
1311
+ last -= 1 if r.exclude_end?
1312
+ if last == -1
1313
+ rangestr = (first > 0 ? "#{first}-" : "-#{-first}")
1314
+ else
1315
+ raise HTTPHeaderSyntaxError, 'range.first is negative' if first < 0
1316
+ raise HTTPHeaderSyntaxError, 'range.last is negative' if last < 0
1317
+ raise HTTPHeaderSyntaxError, 'must be .first < .last' if first > last
1318
+ rangestr = "#{first}-#{last}"
1319
+ end
1320
+ else
1321
+ raise TypeError, 'Range/Integer is required'
1322
+ end
1323
+ @header['range'] = ["bytes=#{rangestr}"]
1324
+ r
1325
+ end
1326
+
1327
+ alias range= set_range
1328
+
1329
+ # Returns an Integer object which represents the Content-Length: header field
1330
+ # or +nil+ if that field is not provided.
1331
+ def content_length
1332
+ return nil unless key?('Content-Length')
1333
+ len = self['Content-Length'].slice(/\d+/) or
1334
+ raise HTTPHeaderSyntaxError, 'wrong Content-Length format'
1335
+ len.to_i
1336
+ end
1337
+
1338
+ def content_length=(len)
1339
+ unless len
1340
+ @header.delete 'content-length'
1341
+ return nil
1342
+ end
1343
+ @header['content-length'] = [len.to_i.to_s]
1344
+ end
1345
+
1346
+ # Returns "true" if the "transfer-encoding" header is present and
1347
+ # set to "chunked". This is an HTTP/1.1 feature, allowing the
1348
+ # the content to be sent in "chunks" without at the outset
1349
+ # stating the entire content length.
1350
+ def chunked?
1351
+ return false unless @header['transfer-encoding']
1352
+ field = self['Transfer-Encoding']
1353
+ (/(?:\A|[^\-\w])chunked(?![\-\w])/i =~ field) ? true : false
1354
+ end
1355
+
1356
+ # Returns a Range object which represents Content-Range: header field.
1357
+ # This indicates, for a partial entity body, where this fragment
1358
+ # fits inside the full entity body, as range of byte offsets.
1359
+ def content_range
1360
+ return nil unless @header['content-range']
1361
+ m = %r<bytes\s+(\d+)-(\d+)/(\d+|\*)>i.match(self['Content-Range']) or
1362
+ raise HTTPHeaderSyntaxError, 'wrong Content-Range format'
1363
+ m[1].to_i .. m[2].to_i + 1
1364
+ end
1365
+
1366
+ # The length of the range represented in Content-Range: header.
1367
+ def range_length
1368
+ r = content_range() or return nil
1369
+ r.end - r.begin
1370
+ end
1371
+
1372
+ # Returns a content type string such as "text/html".
1373
+ # This method returns nil if Content-Type: header field does not exist.
1374
+ def content_type
1375
+ return nil unless main_type()
1376
+ if sub_type()
1377
+ then "#{main_type()}/#{sub_type()}"
1378
+ else main_type()
1379
+ end
1380
+ end
1381
+
1382
+ # Returns a content type string such as "text".
1383
+ # This method returns nil if Content-Type: header field does not exist.
1384
+ def main_type
1385
+ return nil unless @header['content-type']
1386
+ self['Content-Type'].split(';').first.to_s.split('/')[0].to_s.strip
1387
+ end
1388
+
1389
+ # Returns a content type string such as "html".
1390
+ # This method returns nil if Content-Type: header field does not exist
1391
+ # or sub-type is not given (e.g. "Content-Type: text").
1392
+ def sub_type
1393
+ return nil unless @header['content-type']
1394
+ main, sub = *self['Content-Type'].split(';').first.to_s.split('/')
1395
+ return nil unless sub
1396
+ sub.strip
1397
+ end
1398
+
1399
+ # Returns content type parameters as a Hash as like
1400
+ # {"charset" => "iso-2022-jp"}.
1401
+ def type_params
1402
+ result = {}
1403
+ list = self['Content-Type'].to_s.split(';')
1404
+ list.shift
1405
+ list.each do |param|
1406
+ k, v = *param.split('=', 2)
1407
+ result[k.strip] = v.strip
1408
+ end
1409
+ result
1410
+ end
1411
+
1412
+ # Set Content-Type: header field by +type+ and +params+.
1413
+ # +type+ must be a String, +params+ must be a Hash.
1414
+ def set_content_type(type, params = {})
1415
+ @header['content-type'] = [type + params.map{|k,v|"; #{k}=#{v}"}.join('')]
1416
+ end
1417
+
1418
+ alias content_type= set_content_type
1419
+
1420
+ # Set header fields and a body from HTML form data.
1421
+ # +params+ should be a Hash containing HTML form data.
1422
+ # Optional argument +sep+ means data record separator.
1423
+ #
1424
+ # This method also set Content-Type: header field to
1425
+ # application/x-www-form-urlencoded.
1426
+ def set_form_data(params, sep = '&')
1427
+ self.body = params.map {|k,v| "#{urlencode(k.to_s)}=#{urlencode(v.to_s)}" }.join(sep)
1428
+ self.content_type = 'application/x-www-form-urlencoded'
1429
+ end
1430
+
1431
+ alias form_data= set_form_data
1432
+
1433
+ def urlencode(str)
1434
+ str.gsub(/[^a-zA-Z0-9_\.\-]/n) {|s| sprintf('%%%02x', s[0]) }
1435
+ end
1436
+ private :urlencode
1437
+
1438
+ # Set the Authorization: header for "Basic" authorization.
1439
+ def basic_auth(account, password)
1440
+ @header['authorization'] = [basic_encode(account, password)]
1441
+ end
1442
+
1443
+ # Set Proxy-Authorization: header for "Basic" authorization.
1444
+ def proxy_basic_auth(account, password)
1445
+ @header['proxy-authorization'] = [basic_encode(account, password)]
1446
+ end
1447
+
1448
+ def basic_encode(account, password)
1449
+ 'Basic ' + ["#{account}:#{password}"].pack('m').delete("\r\n")
1450
+ end
1451
+ private :basic_encode
1452
+
1453
+ end
1454
+
1455
+
1456
+ #
1457
+ # Parent of HTTPRequest class. Do not use this directly; use
1458
+ # a subclass of HTTPRequest.
1459
+ #
1460
+ # Mixes in the HTTPHeader module.
1461
+ #
1462
+ class HTTPGenericRequest
1463
+
1464
+ include HTTPHeader
1465
+
1466
+ def initialize(m, reqbody, resbody, path, initheader = nil)
1467
+ @method = m
1468
+ @request_has_body = reqbody
1469
+ @response_has_body = resbody
1470
+ raise ArgumentError, "HTTP request path is empty" if path.empty?
1471
+ @path = path
1472
+ initialize_http_header initheader
1473
+ self['Accept'] ||= '*/*'
1474
+ @body = nil
1475
+ @body_stream = nil
1476
+ end
1477
+
1478
+ attr_reader :method
1479
+ attr_reader :path
1480
+
1481
+ def inspect
1482
+ "\#<#{self.class} #{@method}>"
1483
+ end
1484
+
1485
+ def request_body_permitted?
1486
+ @request_has_body
1487
+ end
1488
+
1489
+ def response_body_permitted?
1490
+ @response_has_body
1491
+ end
1492
+
1493
+ def body_exist?
1494
+ warn "Net::HTTPRequest#body_exist? is obsolete; use response_body_permitted?" if $VERBOSE
1495
+ response_body_permitted?
1496
+ end
1497
+
1498
+ attr_reader :body
1499
+
1500
+ def body=(str)
1501
+ @body = str
1502
+ @body_stream = nil
1503
+ str
1504
+ end
1505
+
1506
+ attr_reader :body_stream
1507
+
1508
+ def body_stream=(input)
1509
+ @body = nil
1510
+ @body_stream = input
1511
+ input
1512
+ end
1513
+
1514
+ def set_body_internal(str) #:nodoc: internal use only
1515
+ raise ArgumentError, "both of body argument and HTTPRequest#body set" if str and (@body or @body_stream)
1516
+ self.body = str if str
1517
+ end
1518
+
1519
+ #
1520
+ # write
1521
+ #
1522
+
1523
+ def exec(sock, ver, path) #:nodoc: internal use only
1524
+ if @body
1525
+ send_request_with_body sock, ver, path, @body
1526
+ elsif @body_stream
1527
+ send_request_with_body_stream sock, ver, path, @body_stream
1528
+ else
1529
+ write_header sock, ver, path
1530
+ end
1531
+ end
1532
+
1533
+ private
1534
+
1535
+ def send_request_with_body(sock, ver, path, body)
1536
+ self.content_length = body.length
1537
+ delete 'Transfer-Encoding'
1538
+ supply_default_content_type
1539
+ write_header sock, ver, path
1540
+ sock.write body
1541
+ end
1542
+
1543
+ def send_request_with_body_stream(sock, ver, path, f)
1544
+ unless content_length() or chunked?
1545
+ raise ArgumentError,
1546
+ "Content-Length not given and Transfer-Encoding is not `chunked'"
1547
+ end
1548
+ supply_default_content_type
1549
+ write_header sock, ver, path
1550
+ if chunked?
1551
+ while s = f.read(1024)
1552
+ sock.write(sprintf("%x\r\n", s.length) << s << "\r\n")
1553
+ end
1554
+ sock.write "0\r\n\r\n"
1555
+ else
1556
+ while s = f.read(1024)
1557
+ sock.write s
1558
+ end
1559
+ end
1560
+ end
1561
+
1562
+ def supply_default_content_type
1563
+ return if content_type()
1564
+ warn 'net/http: warning: Content-Type did not set; using application/x-www-form-urlencoded' if $VERBOSE
1565
+ set_content_type 'application/x-www-form-urlencoded'
1566
+ end
1567
+
1568
+ def write_header(sock, ver, path)
1569
+ buf = "#{@method} #{path} HTTP/#{ver}\r\n"
1570
+ each_capitalized do |k,v|
1571
+ buf << "#{k}: #{v}\r\n"
1572
+ end
1573
+ buf << "\r\n"
1574
+ sock.write buf
1575
+ end
1576
+
1577
+ end
1578
+
1579
+
1580
+ #
1581
+ # HTTP request class. This class wraps request header and entity path.
1582
+ # You *must* use its subclass, Net::HTTP::Get, Post, Head.
1583
+ #
1584
+ class HTTPRequest < HTTPGenericRequest
1585
+
1586
+ # Creates HTTP request object.
1587
+ def initialize(path, initheader = nil)
1588
+ super self.class::METHOD,
1589
+ self.class::REQUEST_HAS_BODY,
1590
+ self.class::RESPONSE_HAS_BODY,
1591
+ path, initheader
1592
+ end
1593
+ end
1594
+
1595
+
1596
+ class HTTP # reopen
1597
+ #
1598
+ # HTTP 1.1 methods --- RFC2616
1599
+ #
1600
+
1601
+ class Get < HTTPRequest
1602
+ METHOD = 'GET'
1603
+ REQUEST_HAS_BODY = false
1604
+ RESPONSE_HAS_BODY = true
1605
+ end
1606
+
1607
+ class Head < HTTPRequest
1608
+ METHOD = 'HEAD'
1609
+ REQUEST_HAS_BODY = false
1610
+ RESPONSE_HAS_BODY = false
1611
+ end
1612
+
1613
+ class Post < HTTPRequest
1614
+ METHOD = 'POST'
1615
+ REQUEST_HAS_BODY = true
1616
+ RESPONSE_HAS_BODY = true
1617
+ end
1618
+
1619
+ class Put < HTTPRequest
1620
+ METHOD = 'PUT'
1621
+ REQUEST_HAS_BODY = true
1622
+ RESPONSE_HAS_BODY = true
1623
+ end
1624
+
1625
+ class Delete < HTTPRequest
1626
+ METHOD = 'DELETE'
1627
+ REQUEST_HAS_BODY = false
1628
+ RESPONSE_HAS_BODY = true
1629
+ end
1630
+
1631
+ class Options < HTTPRequest
1632
+ METHOD = 'OPTIONS'
1633
+ REQUEST_HAS_BODY = false
1634
+ RESPONSE_HAS_BODY = false
1635
+ end
1636
+
1637
+ class Trace < HTTPRequest
1638
+ METHOD = 'TRACE'
1639
+ REQUEST_HAS_BODY = false
1640
+ RESPONSE_HAS_BODY = true
1641
+ end
1642
+
1643
+ #
1644
+ # WebDAV methods --- RFC2518
1645
+ #
1646
+
1647
+ class Propfind < HTTPRequest
1648
+ METHOD = 'PROPFIND'
1649
+ REQUEST_HAS_BODY = true
1650
+ RESPONSE_HAS_BODY = true
1651
+ end
1652
+
1653
+ class Proppatch < HTTPRequest
1654
+ METHOD = 'PROPPATCH'
1655
+ REQUEST_HAS_BODY = true
1656
+ RESPONSE_HAS_BODY = true
1657
+ end
1658
+
1659
+ class Mkcol < HTTPRequest
1660
+ METHOD = 'MKCOL'
1661
+ REQUEST_HAS_BODY = true
1662
+ RESPONSE_HAS_BODY = true
1663
+ end
1664
+
1665
+ class Copy < HTTPRequest
1666
+ METHOD = 'COPY'
1667
+ REQUEST_HAS_BODY = false
1668
+ RESPONSE_HAS_BODY = true
1669
+ end
1670
+
1671
+ class Move < HTTPRequest
1672
+ METHOD = 'MOVE'
1673
+ REQUEST_HAS_BODY = false
1674
+ RESPONSE_HAS_BODY = true
1675
+ end
1676
+
1677
+ class Lock < HTTPRequest
1678
+ METHOD = 'LOCK'
1679
+ REQUEST_HAS_BODY = true
1680
+ RESPONSE_HAS_BODY = true
1681
+ end
1682
+
1683
+ class Unlock < HTTPRequest
1684
+ METHOD = 'UNLOCK'
1685
+ REQUEST_HAS_BODY = true
1686
+ RESPONSE_HAS_BODY = true
1687
+ end
1688
+ end
1689
+
1690
+
1691
+ ###
1692
+ ### Response
1693
+ ###
1694
+
1695
+ # HTTP exception class.
1696
+ # You must use its subclasses.
1697
+ module HTTPExceptions
1698
+ def initialize(msg, res) #:nodoc:
1699
+ super msg
1700
+ @response = res
1701
+ end
1702
+ attr_reader :response
1703
+ alias data response #:nodoc: obsolete
1704
+ end
1705
+ class HTTPError < ProtocolError
1706
+ include HTTPExceptions
1707
+ end
1708
+ class HTTPRetriableError < ProtoRetriableError
1709
+ include HTTPExceptions
1710
+ end
1711
+ class HTTPServerException < ProtoServerError
1712
+ # We cannot use the name "HTTPServerError", it is the name of the response.
1713
+ include HTTPExceptions
1714
+ end
1715
+ class HTTPFatalError < ProtoFatalError
1716
+ include HTTPExceptions
1717
+ end
1718
+
1719
+
1720
+ # HTTP response class. This class wraps response header and entity.
1721
+ # Mixes in the HTTPHeader module, which provides access to response
1722
+ # header values both via hash-like methods and individual readers.
1723
+ # Note that each possible HTTP response code defines its own
1724
+ # HTTPResponse subclass. These are listed below.
1725
+ # All classes are
1726
+ # defined under the Net module. Indentation indicates inheritance.
1727
+ #
1728
+ # xxx HTTPResponse
1729
+ #
1730
+ # 1xx HTTPInformation
1731
+ # 100 HTTPContinue
1732
+ # 101 HTTPSwitchProtocol
1733
+ #
1734
+ # 2xx HTTPSuccess
1735
+ # 200 HTTPOK
1736
+ # 201 HTTPCreated
1737
+ # 202 HTTPAccepted
1738
+ # 203 HTTPNonAuthoritativeInformation
1739
+ # 204 HTTPNoContent
1740
+ # 205 HTTPResetContent
1741
+ # 206 HTTPPartialContent
1742
+ #
1743
+ # 3xx HTTPRedirection
1744
+ # 300 HTTPMultipleChoice
1745
+ # 301 HTTPMovedPermanently
1746
+ # 302 HTTPFound
1747
+ # 303 HTTPSeeOther
1748
+ # 304 HTTPNotModified
1749
+ # 305 HTTPUseProxy
1750
+ # 307 HTTPTemporaryRedirect
1751
+ #
1752
+ # 4xx HTTPClientError
1753
+ # 400 HTTPBadRequest
1754
+ # 401 HTTPUnauthorized
1755
+ # 402 HTTPPaymentRequired
1756
+ # 403 HTTPForbidden
1757
+ # 404 HTTPNotFound
1758
+ # 405 HTTPMethodNotAllowed
1759
+ # 406 HTTPNotAcceptable
1760
+ # 407 HTTPProxyAuthenticationRequired
1761
+ # 408 HTTPRequestTimeOut
1762
+ # 409 HTTPConflict
1763
+ # 410 HTTPGone
1764
+ # 411 HTTPLengthRequired
1765
+ # 412 HTTPPreconditionFailed
1766
+ # 413 HTTPRequestEntityTooLarge
1767
+ # 414 HTTPRequestURITooLong
1768
+ # 415 HTTPUnsupportedMediaType
1769
+ # 416 HTTPRequestedRangeNotSatisfiable
1770
+ # 417 HTTPExpectationFailed
1771
+ #
1772
+ # 5xx HTTPServerError
1773
+ # 500 HTTPInternalServerError
1774
+ # 501 HTTPNotImplemented
1775
+ # 502 HTTPBadGateway
1776
+ # 503 HTTPServiceUnavailable
1777
+ # 504 HTTPGatewayTimeOut
1778
+ # 505 HTTPVersionNotSupported
1779
+ #
1780
+ # xxx HTTPUnknownResponse
1781
+ #
1782
+ class HTTPResponse
1783
+ # true if the response has body.
1784
+ def HTTPResponse.body_permitted?
1785
+ self::HAS_BODY
1786
+ end
1787
+
1788
+ def HTTPResponse.exception_type # :nodoc: internal use only
1789
+ self::EXCEPTION_TYPE
1790
+ end
1791
+ end # reopened after
1792
+
1793
+ # :stopdoc:
1794
+
1795
+ class HTTPUnknownResponse < HTTPResponse
1796
+ HAS_BODY = true
1797
+ EXCEPTION_TYPE = HTTPError
1798
+ end
1799
+ class HTTPInformation < HTTPResponse # 1xx
1800
+ HAS_BODY = false
1801
+ EXCEPTION_TYPE = HTTPError
1802
+ end
1803
+ class HTTPSuccess < HTTPResponse # 2xx
1804
+ HAS_BODY = true
1805
+ EXCEPTION_TYPE = HTTPError
1806
+ end
1807
+ class HTTPRedirection < HTTPResponse # 3xx
1808
+ HAS_BODY = true
1809
+ EXCEPTION_TYPE = HTTPRetriableError
1810
+ end
1811
+ class HTTPClientError < HTTPResponse # 4xx
1812
+ HAS_BODY = true
1813
+ EXCEPTION_TYPE = HTTPServerException # for backward compatibility
1814
+ end
1815
+ class HTTPServerError < HTTPResponse # 5xx
1816
+ HAS_BODY = true
1817
+ EXCEPTION_TYPE = HTTPFatalError # for backward compatibility
1818
+ end
1819
+
1820
+ class HTTPContinue < HTTPInformation # 100
1821
+ HAS_BODY = false
1822
+ end
1823
+ class HTTPSwitchProtocol < HTTPInformation # 101
1824
+ HAS_BODY = false
1825
+ end
1826
+
1827
+ class HTTPOK < HTTPSuccess # 200
1828
+ HAS_BODY = true
1829
+ end
1830
+ class HTTPCreated < HTTPSuccess # 201
1831
+ HAS_BODY = true
1832
+ end
1833
+ class HTTPAccepted < HTTPSuccess # 202
1834
+ HAS_BODY = true
1835
+ end
1836
+ class HTTPNonAuthoritativeInformation < HTTPSuccess # 203
1837
+ HAS_BODY = true
1838
+ end
1839
+ class HTTPNoContent < HTTPSuccess # 204
1840
+ HAS_BODY = false
1841
+ end
1842
+ class HTTPResetContent < HTTPSuccess # 205
1843
+ HAS_BODY = false
1844
+ end
1845
+ class HTTPPartialContent < HTTPSuccess # 206
1846
+ HAS_BODY = true
1847
+ end
1848
+
1849
+ class HTTPMultipleChoice < HTTPRedirection # 300
1850
+ HAS_BODY = true
1851
+ end
1852
+ class HTTPMovedPermanently < HTTPRedirection # 301
1853
+ HAS_BODY = true
1854
+ end
1855
+ class HTTPFound < HTTPRedirection # 302
1856
+ HAS_BODY = true
1857
+ end
1858
+ HTTPMovedTemporarily = HTTPFound
1859
+ class HTTPSeeOther < HTTPRedirection # 303
1860
+ HAS_BODY = true
1861
+ end
1862
+ class HTTPNotModified < HTTPRedirection # 304
1863
+ HAS_BODY = false
1864
+ end
1865
+ class HTTPUseProxy < HTTPRedirection # 305
1866
+ HAS_BODY = false
1867
+ end
1868
+ # 306 unused
1869
+ class HTTPTemporaryRedirect < HTTPRedirection # 307
1870
+ HAS_BODY = true
1871
+ end
1872
+
1873
+ class HTTPBadRequest < HTTPClientError # 400
1874
+ HAS_BODY = true
1875
+ end
1876
+ class HTTPUnauthorized < HTTPClientError # 401
1877
+ HAS_BODY = true
1878
+ end
1879
+ class HTTPPaymentRequired < HTTPClientError # 402
1880
+ HAS_BODY = true
1881
+ end
1882
+ class HTTPForbidden < HTTPClientError # 403
1883
+ HAS_BODY = true
1884
+ end
1885
+ class HTTPNotFound < HTTPClientError # 404
1886
+ HAS_BODY = true
1887
+ end
1888
+ class HTTPMethodNotAllowed < HTTPClientError # 405
1889
+ HAS_BODY = true
1890
+ end
1891
+ class HTTPNotAcceptable < HTTPClientError # 406
1892
+ HAS_BODY = true
1893
+ end
1894
+ class HTTPProxyAuthenticationRequired < HTTPClientError # 407
1895
+ HAS_BODY = true
1896
+ end
1897
+ class HTTPRequestTimeOut < HTTPClientError # 408
1898
+ HAS_BODY = true
1899
+ end
1900
+ class HTTPConflict < HTTPClientError # 409
1901
+ HAS_BODY = true
1902
+ end
1903
+ class HTTPGone < HTTPClientError # 410
1904
+ HAS_BODY = true
1905
+ end
1906
+ class HTTPLengthRequired < HTTPClientError # 411
1907
+ HAS_BODY = true
1908
+ end
1909
+ class HTTPPreconditionFailed < HTTPClientError # 412
1910
+ HAS_BODY = true
1911
+ end
1912
+ class HTTPRequestEntityTooLarge < HTTPClientError # 413
1913
+ HAS_BODY = true
1914
+ end
1915
+ class HTTPRequestURITooLong < HTTPClientError # 414
1916
+ HAS_BODY = true
1917
+ end
1918
+ HTTPRequestURITooLarge = HTTPRequestURITooLong
1919
+ class HTTPUnsupportedMediaType < HTTPClientError # 415
1920
+ HAS_BODY = true
1921
+ end
1922
+ class HTTPRequestedRangeNotSatisfiable < HTTPClientError # 416
1923
+ HAS_BODY = true
1924
+ end
1925
+ class HTTPExpectationFailed < HTTPClientError # 417
1926
+ HAS_BODY = true
1927
+ end
1928
+
1929
+ class HTTPInternalServerError < HTTPServerError # 500
1930
+ HAS_BODY = true
1931
+ end
1932
+ class HTTPNotImplemented < HTTPServerError # 501
1933
+ HAS_BODY = true
1934
+ end
1935
+ class HTTPBadGateway < HTTPServerError # 502
1936
+ HAS_BODY = true
1937
+ end
1938
+ class HTTPServiceUnavailable < HTTPServerError # 503
1939
+ HAS_BODY = true
1940
+ end
1941
+ class HTTPGatewayTimeOut < HTTPServerError # 504
1942
+ HAS_BODY = true
1943
+ end
1944
+ class HTTPVersionNotSupported < HTTPServerError # 505
1945
+ HAS_BODY = true
1946
+ end
1947
+
1948
+ # :startdoc:
1949
+
1950
+
1951
+ class HTTPResponse # reopen
1952
+
1953
+ CODE_CLASS_TO_OBJ = {
1954
+ '1' => HTTPInformation,
1955
+ '2' => HTTPSuccess,
1956
+ '3' => HTTPRedirection,
1957
+ '4' => HTTPClientError,
1958
+ '5' => HTTPServerError
1959
+ }
1960
+ CODE_TO_OBJ = {
1961
+ '100' => HTTPContinue,
1962
+ '101' => HTTPSwitchProtocol,
1963
+
1964
+ '200' => HTTPOK,
1965
+ '201' => HTTPCreated,
1966
+ '202' => HTTPAccepted,
1967
+ '203' => HTTPNonAuthoritativeInformation,
1968
+ '204' => HTTPNoContent,
1969
+ '205' => HTTPResetContent,
1970
+ '206' => HTTPPartialContent,
1971
+
1972
+ '300' => HTTPMultipleChoice,
1973
+ '301' => HTTPMovedPermanently,
1974
+ '302' => HTTPFound,
1975
+ '303' => HTTPSeeOther,
1976
+ '304' => HTTPNotModified,
1977
+ '305' => HTTPUseProxy,
1978
+ '307' => HTTPTemporaryRedirect,
1979
+
1980
+ '400' => HTTPBadRequest,
1981
+ '401' => HTTPUnauthorized,
1982
+ '402' => HTTPPaymentRequired,
1983
+ '403' => HTTPForbidden,
1984
+ '404' => HTTPNotFound,
1985
+ '405' => HTTPMethodNotAllowed,
1986
+ '406' => HTTPNotAcceptable,
1987
+ '407' => HTTPProxyAuthenticationRequired,
1988
+ '408' => HTTPRequestTimeOut,
1989
+ '409' => HTTPConflict,
1990
+ '410' => HTTPGone,
1991
+ '411' => HTTPLengthRequired,
1992
+ '412' => HTTPPreconditionFailed,
1993
+ '413' => HTTPRequestEntityTooLarge,
1994
+ '414' => HTTPRequestURITooLong,
1995
+ '415' => HTTPUnsupportedMediaType,
1996
+ '416' => HTTPRequestedRangeNotSatisfiable,
1997
+ '417' => HTTPExpectationFailed,
1998
+
1999
+ '500' => HTTPInternalServerError,
2000
+ '501' => HTTPNotImplemented,
2001
+ '502' => HTTPBadGateway,
2002
+ '503' => HTTPServiceUnavailable,
2003
+ '504' => HTTPGatewayTimeOut,
2004
+ '505' => HTTPVersionNotSupported
2005
+ }
2006
+
2007
+ class << HTTPResponse
2008
+ def read_new(sock) #:nodoc: internal use only
2009
+ httpv, code, msg = read_status_line(sock)
2010
+ res = response_class(code).new(httpv, code, msg)
2011
+ each_response_header(sock) do |k,v|
2012
+ res.add_field k, v
2013
+ end
2014
+ res
2015
+ end
2016
+
2017
+ private
2018
+
2019
+ def read_status_line(sock)
2020
+ str = sock.readline
2021
+ m = /\AHTTP(?:\/(\d+\.\d+))?\s+(\d\d\d)\s*(.*)\z/in.match(str) or
2022
+ raise HTTPBadResponse, "wrong status line: #{str.dump}"
2023
+ m.captures
2024
+ end
2025
+
2026
+ def response_class(code)
2027
+ CODE_TO_OBJ[code] or
2028
+ CODE_CLASS_TO_OBJ[code[0,1]] or
2029
+ HTTPUnknownResponse
2030
+ end
2031
+
2032
+ def each_response_header(sock)
2033
+ while true
2034
+ line = sock.readuntil("\n", true).sub(/\s+\z/, '')
2035
+ break if line.empty?
2036
+ m = /\A([^:]+):\s*/.match(line) or
2037
+ raise HTTPBadResponse, 'wrong header line format'
2038
+ yield m[1], m.post_match
2039
+ end
2040
+ end
2041
+ end
2042
+
2043
+ # next is to fix bug in RDoc, where the private inside class << self
2044
+ # spills out.
2045
+ public
2046
+
2047
+ include HTTPHeader
2048
+
2049
+ def initialize(httpv, code, msg) #:nodoc: internal use only
2050
+ @http_version = httpv
2051
+ @code = code
2052
+ @message = msg
2053
+ initialize_http_header nil
2054
+ @body = nil
2055
+ @read = false
2056
+ end
2057
+
2058
+ # The HTTP version supported by the server.
2059
+ attr_reader :http_version
2060
+
2061
+ # HTTP result code string. For example, '302'. You can also
2062
+ # determine the response type by which response subclass the
2063
+ # response object is an instance of.
2064
+ attr_reader :code
2065
+
2066
+ # HTTP result message. For example, 'Not Found'.
2067
+ attr_reader :message
2068
+ alias msg message # :nodoc: obsolete
2069
+
2070
+ def inspect
2071
+ "#<#{self.class} #{@code} #{@message} readbody=#{@read}>"
2072
+ end
2073
+
2074
+ # For backward compatibility.
2075
+ # To allow Net::HTTP 1.1 style assignment
2076
+ # e.g.
2077
+ # response, body = Net::HTTP.get(....)
2078
+ #
2079
+ def to_ary
2080
+ warn "net/http.rb: warning: Net::HTTP v1.1 style assignment found at #{caller(1)[0]}; use `response = http.get(...)' instead." if $VERBOSE
2081
+ res = self.dup
2082
+ class << res
2083
+ undef to_ary
2084
+ end
2085
+ [res, res.body]
2086
+ end
2087
+
2088
+ #
2089
+ # response <-> exception relationship
2090
+ #
2091
+
2092
+ def code_type #:nodoc:
2093
+ self.class
2094
+ end
2095
+
2096
+ def error! #:nodoc:
2097
+ raise error_type().new(@code + ' ' + @message.dump, self)
2098
+ end
2099
+
2100
+ def error_type #:nodoc:
2101
+ self.class::EXCEPTION_TYPE
2102
+ end
2103
+
2104
+ # Raises HTTP error if the response is not 2xx.
2105
+ def value
2106
+ error! unless self.kind_of?(HTTPSuccess)
2107
+ end
2108
+
2109
+ #
2110
+ # header (for backward compatibility only; DO NOT USE)
2111
+ #
2112
+
2113
+ def response #:nodoc:
2114
+ warn "#{caller(1)[0]}: warning: HTTPResponse#response is obsolete" if $VERBOSE
2115
+ self
2116
+ end
2117
+
2118
+ def header #:nodoc:
2119
+ warn "#{caller(1)[0]}: warning: HTTPResponse#header is obsolete" if $VERBOSE
2120
+ self
2121
+ end
2122
+
2123
+ def read_header #:nodoc:
2124
+ warn "#{caller(1)[0]}: warning: HTTPResponse#read_header is obsolete" if $VERBOSE
2125
+ self
2126
+ end
2127
+
2128
+ #
2129
+ # body
2130
+ #
2131
+
2132
+ def reading_body(sock, reqmethodallowbody) #:nodoc: internal use only
2133
+ @socket = sock
2134
+ @body_exist = reqmethodallowbody && self.class.body_permitted?
2135
+ begin
2136
+ yield
2137
+ self.body # ensure to read body
2138
+ ensure
2139
+ @socket = nil
2140
+ end
2141
+ end
2142
+
2143
+ # Gets entity body. If the block given, yields it to +block+.
2144
+ # The body is provided in fragments, as it is read in from the socket.
2145
+ #
2146
+ # Calling this method a second or subsequent time will return the
2147
+ # already read string.
2148
+ #
2149
+ # http.request_get('/index.html') {|res|
2150
+ # puts res.read_body
2151
+ # }
2152
+ #
2153
+ # http.request_get('/index.html') {|res|
2154
+ # p res.read_body.object_id # 538149362
2155
+ # p res.read_body.object_id # 538149362
2156
+ # }
2157
+ #
2158
+ # # using iterator
2159
+ # http.request_get('/index.html') {|res|
2160
+ # res.read_body do |segment|
2161
+ # print segment
2162
+ # end
2163
+ # }
2164
+ #
2165
+ def read_body(dest = nil, &block)
2166
+ if @read
2167
+ raise IOError, "#{self.class}\#read_body called twice" if dest or block
2168
+ return @body
2169
+ end
2170
+ to = procdest(dest, block)
2171
+ stream_check
2172
+ if @body_exist
2173
+ read_body_0 to
2174
+ @body = to
2175
+ else
2176
+ @body = nil
2177
+ end
2178
+ @read = true
2179
+
2180
+ @body
2181
+ end
2182
+
2183
+ # Returns the entity body.
2184
+ #
2185
+ # Calling this method a second or subsequent time will return the
2186
+ # already read string.
2187
+ #
2188
+ # http.request_get('/index.html') {|res|
2189
+ # puts res.body
2190
+ # }
2191
+ #
2192
+ # http.request_get('/index.html') {|res|
2193
+ # p res.body.object_id # 538149362
2194
+ # p res.body.object_id # 538149362
2195
+ # }
2196
+ #
2197
+ def body
2198
+ read_body()
2199
+ end
2200
+
2201
+ alias entity body #:nodoc: obsolete
2202
+
2203
+ private
2204
+
2205
+ def read_body_0(dest)
2206
+ if chunked?
2207
+ read_chunked dest
2208
+ return
2209
+ end
2210
+ clen = content_length()
2211
+ if clen
2212
+ @socket.read clen, dest, true # ignore EOF
2213
+ return
2214
+ end
2215
+ clen = range_length()
2216
+ if clen
2217
+ @socket.read clen, dest
2218
+ return
2219
+ end
2220
+ @socket.read_all dest
2221
+ end
2222
+
2223
+ def read_chunked(dest)
2224
+ len = nil
2225
+ total = 0
2226
+ while true
2227
+ line = @socket.readline
2228
+ hexlen = line.slice(/[0-9a-fA-F]+/) or
2229
+ raise HTTPBadResponse, "wrong chunk size line: #{line}"
2230
+ len = hexlen.hex
2231
+ break if len == 0
2232
+ @socket.read len, dest; total += len
2233
+ @socket.read 2 # \r\n
2234
+ end
2235
+ until @socket.readline.empty?
2236
+ # none
2237
+ end
2238
+ end
2239
+
2240
+ def stream_check
2241
+ raise IOError, 'attempt to read body out of block' if @socket.closed?
2242
+ end
2243
+
2244
+ def procdest(dest, block)
2245
+ raise ArgumentError, 'both arg and block given for HTTP method' \
2246
+ if dest and block
2247
+ if block
2248
+ ReadAdapter.new(block)
2249
+ else
2250
+ dest || ''
2251
+ end
2252
+ end
2253
+
2254
+ end
2255
+
2256
+
2257
+ # :enddoc:
2258
+
2259
+ #--
2260
+ # for backward compatibility
2261
+ class HTTP
2262
+ ProxyMod = ProxyDelta
2263
+ end
2264
+ module NetPrivate
2265
+ HTTPRequest = ::Net::HTTPRequest
2266
+ end
2267
+
2268
+ HTTPInformationCode = HTTPInformation
2269
+ HTTPSuccessCode = HTTPSuccess
2270
+ HTTPRedirectionCode = HTTPRedirection
2271
+ HTTPRetriableCode = HTTPRedirection
2272
+ HTTPClientErrorCode = HTTPClientError
2273
+ HTTPFatalErrorCode = HTTPClientError
2274
+ HTTPServerErrorCode = HTTPServerError
2275
+ HTTPResponceReceiver = HTTPResponse
2276
+
2277
+ end # module Net