httpclient 2.1.5 → 2.8.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +85 -0
  3. data/bin/httpclient +77 -0
  4. data/bin/jsonclient +85 -0
  5. data/lib/hexdump.rb +50 -0
  6. data/lib/http-access2.rb +6 -4
  7. data/lib/httpclient/auth.rb +575 -173
  8. data/lib/httpclient/cacert.pem +3952 -0
  9. data/lib/httpclient/cacert1024.pem +3866 -0
  10. data/lib/httpclient/connection.rb +6 -2
  11. data/lib/httpclient/cookie.rb +162 -504
  12. data/lib/httpclient/http.rb +334 -119
  13. data/lib/httpclient/include_client.rb +85 -0
  14. data/lib/httpclient/jruby_ssl_socket.rb +588 -0
  15. data/lib/httpclient/session.rb +385 -288
  16. data/lib/httpclient/ssl_config.rb +195 -155
  17. data/lib/httpclient/ssl_socket.rb +150 -0
  18. data/lib/httpclient/timeout.rb +14 -10
  19. data/lib/httpclient/util.rb +142 -6
  20. data/lib/httpclient/version.rb +3 -0
  21. data/lib/httpclient/webagent-cookie.rb +459 -0
  22. data/lib/httpclient.rb +509 -202
  23. data/lib/jsonclient.rb +63 -0
  24. data/lib/oauthclient.rb +111 -0
  25. data/sample/async.rb +8 -0
  26. data/sample/auth.rb +11 -0
  27. data/sample/cookie.rb +18 -0
  28. data/sample/dav.rb +103 -0
  29. data/sample/howto.rb +49 -0
  30. data/sample/jsonclient.rb +67 -0
  31. data/sample/oauth_buzz.rb +57 -0
  32. data/sample/oauth_friendfeed.rb +59 -0
  33. data/sample/oauth_twitter.rb +61 -0
  34. data/sample/ssl/0cert.pem +22 -0
  35. data/sample/ssl/0key.pem +30 -0
  36. data/sample/ssl/1000cert.pem +19 -0
  37. data/sample/ssl/1000key.pem +18 -0
  38. data/sample/ssl/htdocs/index.html +10 -0
  39. data/sample/ssl/ssl_client.rb +22 -0
  40. data/sample/ssl/webrick_httpsd.rb +29 -0
  41. data/sample/stream.rb +21 -0
  42. data/sample/thread.rb +27 -0
  43. data/sample/wcat.rb +21 -0
  44. data/test/ca-chain.pem +44 -0
  45. data/test/ca.cert +23 -0
  46. data/test/client-pass.key +18 -0
  47. data/test/client.cert +19 -0
  48. data/test/client.key +15 -0
  49. data/test/helper.rb +131 -0
  50. data/test/htdigest +1 -0
  51. data/test/htpasswd +2 -0
  52. data/test/jruby_ssl_socket/test_pemutils.rb +32 -0
  53. data/test/runner.rb +2 -0
  54. data/test/server.cert +19 -0
  55. data/test/server.key +15 -0
  56. data/test/sslsvr.rb +65 -0
  57. data/test/subca.cert +21 -0
  58. data/test/test_auth.rb +492 -0
  59. data/test/test_cookie.rb +309 -0
  60. data/test/test_hexdump.rb +14 -0
  61. data/test/test_http-access2.rb +508 -0
  62. data/test/test_httpclient.rb +2145 -0
  63. data/test/test_include_client.rb +52 -0
  64. data/test/test_jsonclient.rb +80 -0
  65. data/test/test_ssl.rb +559 -0
  66. data/test/test_webagent-cookie.rb +465 -0
  67. metadata +85 -44
  68. data/lib/httpclient/auth.rb.orig +0 -513
  69. data/lib/httpclient/cacert.p7s +0 -1579
  70. data/lib/httpclient.rb.orig +0 -1020
  71. data/lib/tags +0 -908
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 45217dcc777d36d71246dd468e40b79caad351d6
4
+ data.tar.gz: afcf1a175414e0a1dde95eb5823b0fa339655d9c
5
+ SHA512:
6
+ metadata.gz: f5ae105eb3b269d67521a35446e3518b359e7a359c0c8a14500ef9e9ff8c4681c20b103bb4d5a2f96cdd9caa337fc149f39df3754bb9f3185b6914f284adfdc0
7
+ data.tar.gz: 005d1769b6906e0c107ba63e7a178c4d73aae59198ed3efe866e8722fdadcf4c4142c3724c167b6db5f8a45cb03f517083164c18fdd1aa65074dc4ab362bc9de
data/README.md ADDED
@@ -0,0 +1,85 @@
1
+ httpclient - HTTP accessing library. [![Gem Version](https://badge.fury.io/rb/httpclient.svg)](http://badge.fury.io/rb/httpclient)
2
+
3
+ Copyright (C) 2000-2015 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
4
+
5
+ 'httpclient' gives something like the functionality of libwww-perl (LWP) in
6
+ Ruby. 'httpclient' formerly known as 'http-access2'.
7
+
8
+ See [HTTPClient](http://www.rubydoc.info/gems/httpclient/frames) for documentation.
9
+
10
+
11
+ ## Features
12
+
13
+ * methods like GET/HEAD/POST/* via HTTP/1.1.
14
+ * HTTPS(SSL), Cookies, proxy, authentication(Digest, NTLM, Basic), etc.
15
+ * asynchronous HTTP request, streaming HTTP request.
16
+ * debug mode CLI.
17
+ * by contrast with net/http in standard distribution;
18
+ * Cookies support
19
+ * MT-safe
20
+ * streaming POST (POST with File/IO)
21
+ * Digest auth
22
+ * Negotiate/NTLM auth for WWW-Authenticate (requires net/ntlm module; rubyntlm gem)
23
+ * NTLM auth for Proxy-Authenticate (requires 'win32/sspi' module; rubysspi gem)
24
+ * extensible with filter interface
25
+ * you don't have to care HTTP/1.1 persistent connection
26
+ (httpclient cares instead of you)
27
+ * Not supported now
28
+ * Cache
29
+ * Rather advanced HTTP/1.1 usage such as Range, deflate, etc.
30
+ (of course you can set it in header by yourself)
31
+
32
+ ## httpclient command
33
+
34
+ Usage: 1) `httpclient get https://www.google.co.jp/?q=ruby`
35
+ Usage: 2) `httpclient`
36
+
37
+ For 1) it issues a GET request to the given URI and shows the wiredump and
38
+ the parsed result. For 2) it invokes irb shell with the binding that has a
39
+ HTTPClient as 'self'. You can call HTTPClient instance methods like;
40
+
41
+ ```ruby
42
+ get "https://www.google.co.jp/", :q => :ruby
43
+ ```
44
+
45
+ ## Author
46
+
47
+ * Name:: Hiroshi Nakamura
48
+ * E-mail:: nahi@ruby-lang.org
49
+ * Project web site:: http://github.com/nahi/httpclient
50
+
51
+
52
+ ## License
53
+
54
+ This program is copyrighted free software by NAKAMURA, Hiroshi. You can
55
+ redistribute it and/or modify it under the same terms of Ruby's license;
56
+ either the dual license version in 2003, or any later version.
57
+
58
+ httpclient/session.rb is based on http-access.rb in http-access/0.0.4. Some
59
+ part of it is copyrighted by Maebashi-san who made and published
60
+ http-access/0.0.4. http-access/0.0.4 did not include license notice but when
61
+ I asked Maebashi-san he agreed that I can redistribute it under the same terms
62
+ of Ruby. Many thanks to Maebashi-san.
63
+
64
+
65
+ ## Install
66
+
67
+ You can install httpclient via rubygems: `gem install httpclient`
68
+
69
+
70
+ ## Usage
71
+
72
+ See [HTTPClient](http://www.rubydoc.info/gems/httpclient/frames) for documentation.
73
+ You can also check sample/howto.rb how to use APIs.
74
+
75
+ ## Bug report or Feature request
76
+
77
+ Please file a ticket at the project web site.
78
+
79
+ 1. find a similar ticket from https://github.com/nahi/httpclient/issues
80
+ 2. create a new ticket by clicking 'Create Issue' button.
81
+ 3. you can use github features such as pull-request if you like.
82
+
83
+ ## Changes
84
+
85
+ See [ChangeLog](https://github.com/nahi/httpclient/blob/master/CHANGELOG.md)
data/bin/httpclient ADDED
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # httpclient shell command.
4
+ #
5
+ # Usage: 1) % httpclient get https://www.google.co.jp/ q=ruby
6
+ # Usage: 2) % httpclient
7
+ #
8
+ # For 1) it issues a GET request to the given URI and shows the wiredump and
9
+ # the parsed result. For 2) it invokes irb shell with the binding that has a
10
+ # HTTPClient as 'self'. You can call HTTPClient instance methods like;
11
+ # > get "https://www.google.co.jp/", :q => :ruby
12
+ require 'httpclient'
13
+
14
+ method = ARGV.shift
15
+ if method == 'version'
16
+ puts HTTPClient::VERSION
17
+ exit
18
+ end
19
+
20
+ url = ARGV.shift
21
+ if method && url
22
+ client = HTTPClient.new
23
+ client.strict_response_size_check = true
24
+ if method == 'download'
25
+ print client.get_content(url)
26
+ else
27
+ client.debug_dev = STDERR
28
+ $DEBUG = true
29
+ require 'pp'
30
+ pp client.send(method, url, *ARGV)
31
+ end
32
+ exit
33
+ end
34
+
35
+ require 'irb'
36
+ require 'irb/completion'
37
+
38
+ class Runner
39
+ def initialize
40
+ @httpclient = HTTPClient.new
41
+ @httpclient.strict_response_size_check = true
42
+ end
43
+
44
+ def method_missing(msg, *a, &b)
45
+ debug, $DEBUG = $DEBUG, true
46
+ begin
47
+ @httpclient.send(msg, *a, &b)
48
+ ensure
49
+ $DEBUG = debug
50
+ end
51
+ end
52
+
53
+ def run
54
+ IRB.setup(nil)
55
+ ws = IRB::WorkSpace.new(binding)
56
+ irb = IRB::Irb.new(ws)
57
+ IRB.conf[:MAIN_CONTEXT] = irb.context
58
+
59
+ trap("SIGINT") do
60
+ irb.signal_handle
61
+ end
62
+
63
+ begin
64
+ catch(:IRB_EXIT) do
65
+ irb.eval_input
66
+ end
67
+ ensure
68
+ IRB.irb_at_exit
69
+ end
70
+ end
71
+
72
+ def to_s
73
+ 'HTTPClient'
74
+ end
75
+ end
76
+
77
+ Runner.new.run
data/bin/jsonclient ADDED
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # jsonclient shell command.
4
+ #
5
+ # Usage: 1) % jsonclient post https://www.example.com/ content.json
6
+ # Usage: 2) % jsonclient
7
+ #
8
+ # For 1) it issues a GET request to the given URI and shows the wiredump and
9
+ # the parsed result. For 2) it invokes irb shell with the binding that has a
10
+ # JSONClient as 'self'. You can call JSONClient instance methods like;
11
+ # > post "https://www.example.com/resource", {'hello' => 'world'}
12
+ require 'jsonclient'
13
+
14
+ method = ARGV.shift
15
+ url = ARGV.shift
16
+ body = []
17
+ if ['post', 'put'].include?(method)
18
+ if ARGV.size == 1 && File.exist?(ARGV[0])
19
+ body << File.read(ARGV[0])
20
+ else
21
+ body << ARGF.read
22
+ end
23
+ end
24
+ if method && url
25
+ require 'pp'
26
+ client = JSONClient.new
27
+ client.debug_dev = STDERR if $DEBUG
28
+ res = client.send(method, url, *body)
29
+ STDERR.puts('RESPONSE HEADER: ')
30
+ PP.pp(res.headers, STDERR)
31
+ if res.ok?
32
+ begin
33
+ puts JSON.pretty_generate(res.content)
34
+ rescue JSON::GeneratorError
35
+ puts res.content
36
+ end
37
+ exit 0
38
+ else
39
+ STDERR.puts res.content
40
+ exit 1
41
+ end
42
+ end
43
+
44
+ require 'irb'
45
+ require 'irb/completion'
46
+
47
+ class Runner
48
+ def initialize
49
+ @httpclient = JSONClient.new
50
+ end
51
+
52
+ def method_missing(msg, *a, &b)
53
+ debug, $DEBUG = $DEBUG, true
54
+ begin
55
+ @httpclient.send(msg, *a, &b)
56
+ ensure
57
+ $DEBUG = debug
58
+ end
59
+ end
60
+
61
+ def run
62
+ IRB.setup(nil)
63
+ ws = IRB::WorkSpace.new(binding)
64
+ irb = IRB::Irb.new(ws)
65
+ IRB.conf[:MAIN_CONTEXT] = irb.context
66
+
67
+ trap("SIGINT") do
68
+ irb.signal_handle
69
+ end
70
+
71
+ begin
72
+ catch(:IRB_EXIT) do
73
+ irb.eval_input
74
+ end
75
+ ensure
76
+ IRB.irb_at_exit
77
+ end
78
+ end
79
+
80
+ def to_s
81
+ 'JSONClient'
82
+ end
83
+ end
84
+
85
+ Runner.new.run
data/lib/hexdump.rb ADDED
@@ -0,0 +1,50 @@
1
+ # encoding: binary
2
+
3
+ # This was written by Arai-san and published at
4
+ # http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/31987
5
+
6
+
7
+ module HexDump
8
+ # str must be in BINARY encoding in 1.9
9
+ def encode(str)
10
+ offset = 0
11
+ result = []
12
+ while raw = str.slice(offset, 16) and raw.length > 0
13
+ # data field
14
+ data = ''
15
+ for v in raw.unpack('N* a*')
16
+ if v.kind_of? Integer
17
+ data << sprintf("%08x ", v)
18
+ else
19
+ v.each_byte {|c| data << sprintf("%02x", c) }
20
+ end
21
+ end
22
+ # text field
23
+ text = raw.tr("\000-\037\177-\377", ".")
24
+ result << sprintf("%08x %-36s %s", offset, data, text)
25
+ offset += 16
26
+ # omit duplicate line
27
+ if /^(#{regex_quote_n(raw)})+/n =~ str[offset .. -1]
28
+ result << sprintf("%08x ...", offset)
29
+ offset += $&.length
30
+ # should print at the end
31
+ if offset == str.length
32
+ result << sprintf("%08x %-36s %s", offset-16, data, text)
33
+ end
34
+ end
35
+ end
36
+ result
37
+ end
38
+ module_function :encode
39
+
40
+ if RUBY_VERSION >= "1.9"
41
+ # raw must be in BINARY encoding in 1.9
42
+ def self.regex_quote_n(raw)
43
+ Regexp.quote(raw)
44
+ end
45
+ else
46
+ def self.regex_quote_n(raw)
47
+ Regexp.quote(raw, 'n')
48
+ end
49
+ end
50
+ end
data/lib/http-access2.rb CHANGED
@@ -5,9 +5,11 @@
5
5
  # redistribute it and/or modify it under the same terms of Ruby's license;
6
6
  # either the dual license version in 2003, or any later version.
7
7
 
8
- # http-access2.rb is based on http-access.rb in http-access/0.0.4. Some part
9
- # of code in http-access.rb was recycled in http-access2.rb. Those part is
10
- # copyrighted by Maehashi-san.
8
+ # http-access2.rb is based on http-access.rb in http-access/0.0.4. Some
9
+ # part of it is copyrighted by Maebashi-san who made and published
10
+ # http-access/0.0.4. http-access/0.0.4 did not include license notice but
11
+ # when I asked Maebashi-san he agreed that I can redistribute it under the
12
+ # same terms of Ruby. Many thanks to Maebashi-san.
11
13
 
12
14
 
13
15
  require 'httpclient'
@@ -37,7 +39,7 @@ module HTTPAccess2
37
39
  Site = ::HTTPClient::Site
38
40
  Connection = ::HTTPClient::Connection
39
41
  SessionManager = ::HTTPClient::SessionManager
40
- SSLSocketWrap = ::HTTPClient::SSLSocketWrap
42
+ SSLSocketWrap = ::HTTPClient::SSLSocket
41
43
  DebugSocket = ::HTTPClient::DebugSocket
42
44
 
43
45
  class Session < ::HTTPClient::Session