shoesgem 0.1424.0

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