httpclient 2.1.0 → 2.1.1

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 (3) hide show
  1. data/lib/httpclient.rb +106 -28
  2. data/lib/httpclient/cookie.rb +2 -0
  3. metadata +4 -4
data/lib/httpclient.rb CHANGED
@@ -15,6 +15,7 @@ require 'timeout'
15
15
  require 'uri'
16
16
  require 'socket'
17
17
  require 'thread'
18
+ require 'stringio'
18
19
  require 'digest/md5'
19
20
 
20
21
  # Extra library
@@ -51,9 +52,9 @@ require 'httpclient/cookie'
51
52
  #
52
53
  class HTTPClient
53
54
 
54
- VERSION = '2.1.0'
55
+ VERSION = '2.1.1'
55
56
  RUBY_VERSION_STRING = "ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
56
- s = %w$Id: httpclient.rb 172 2007-07-14 06:56:59Z nahi $
57
+ s = %w$Id: httpclient.rb 178 2007-08-28 13:47:27Z nahi $
57
58
  RCS_FILE, RCS_REVISION = s[1][/.*(?=,v$)/], s[2]
58
59
 
59
60
  SSLEnabled = begin
@@ -800,6 +801,8 @@ class SessionManager # :nodoc:
800
801
 
801
802
  attr_accessor :ssl_config
802
803
 
804
+ attr_reader :test_loopback_http_response
805
+
803
806
  def initialize
804
807
  @proxy = nil
805
808
 
@@ -818,6 +821,7 @@ class SessionManager # :nodoc:
818
821
  @read_block_size = 8192
819
822
 
820
823
  @ssl_config = nil
824
+ @test_loopback_http_response = []
821
825
 
822
826
  @sess_pool = []
823
827
  @sess_pool_mutex = Mutex.new
@@ -880,6 +884,7 @@ private
880
884
  sess.read_block_size = @read_block_size
881
885
  sess.ssl_config = @ssl_config
882
886
  sess.debug_dev = @debug_dev
887
+ sess.test_loopback_http_response = @test_loopback_http_response
883
888
  end
884
889
  sess
885
890
  end
@@ -959,7 +964,7 @@ class SSLSocketWrap
959
964
  raise OpenSSL::SSL::SSLError, "no peer cert"
960
965
  end
961
966
  hostname = host.host
962
- if @ssl_socket.respond_to?(:post_connection_check)
967
+ if @ssl_socket.respond_to?(:post_connection_check) and RUBY_VERSION > "1.8.4"
963
968
  @ssl_socket.post_connection_check(hostname)
964
969
  else
965
970
  @context.post_connection_check(@ssl_socket.peer_cert, hostname)
@@ -1038,52 +1043,111 @@ private
1038
1043
  end
1039
1044
 
1040
1045
 
1041
- # HTTPClient::DebugSocket -- debugging support
1042
- #
1043
- class DebugSocket < TCPSocket
1044
- attr_accessor :debug_dev # Device for logging.
1046
+ module SocketWrap
1047
+ def initialize(socket, *args)
1048
+ super(*args)
1049
+ @socket = socket
1050
+ end
1045
1051
 
1046
- class << self
1047
- def create_socket(host, port, debug_dev)
1048
- debug_dev << "! CONNECT TO #{host}:#{port}\n"
1049
- socket = new(host, port)
1050
- socket.debug_dev = debug_dev
1051
- socket.log_connect
1052
- socket
1053
- end
1052
+ def addr
1053
+ @socket.addr
1054
+ end
1054
1055
 
1055
- private :new
1056
+ def close
1057
+ @socket.close
1056
1058
  end
1057
1059
 
1058
- def initialize(*args)
1059
- super
1060
- @debug_dev = nil
1060
+ def closed?
1061
+ @socket.closed?
1062
+ end
1063
+
1064
+ def eof?
1065
+ @socket.eof?
1066
+ end
1067
+
1068
+ def gets(*args)
1069
+ @socket.gets(*args)
1070
+ end
1071
+
1072
+ def read(*args)
1073
+ @socket.read(*args)
1074
+ end
1075
+
1076
+ def <<(str)
1077
+ @socket << str
1078
+ end
1079
+
1080
+ def flush
1081
+ @socket.flush
1082
+ end
1083
+
1084
+ def sync
1085
+ @socket.sync
1061
1086
  end
1062
1087
 
1063
- def log_connect
1064
- @debug_dev << '! CONNECTION ESTABLISHED' << "\n"
1088
+ def sync=(sync)
1089
+ @socket.sync = sync
1090
+ end
1091
+ end
1092
+
1093
+
1094
+ # HTTPClient::DebugSocket -- debugging support
1095
+ #
1096
+ class DebugSocket
1097
+ include SocketWrap
1098
+
1099
+ def initialize(socket, debug_dev)
1100
+ super(socket)
1101
+ @debug_dev = debug_dev
1065
1102
  end
1066
1103
 
1067
1104
  def close
1068
1105
  super
1069
- @debug_dev << '! CONNECTION CLOSED' << "\n"
1106
+ debug("! CONNECTION CLOSED\n")
1070
1107
  end
1071
1108
 
1072
1109
  def gets(*args)
1073
1110
  str = super
1074
- @debug_dev << str if str
1111
+ debug(str)
1075
1112
  str
1076
1113
  end
1077
1114
 
1078
1115
  def read(*args)
1079
1116
  str = super
1080
- @debug_dev << str if str
1117
+ debug(str)
1081
1118
  str
1082
1119
  end
1083
1120
 
1084
1121
  def <<(str)
1085
1122
  super
1086
- @debug_dev << str
1123
+ debug(str)
1124
+ end
1125
+
1126
+ private
1127
+
1128
+ def debug(str)
1129
+ @debug_dev << str if @debug_dev
1130
+ end
1131
+ end
1132
+
1133
+
1134
+ # HTTPClient::LoopBackSocket -- dummy socket for dummy response
1135
+ #
1136
+ class LoopBackSocket
1137
+ include SocketWrap
1138
+
1139
+ def initialize(host, port, response)
1140
+ super(StringIO.new(response))
1141
+ @host = host
1142
+ @port = port
1143
+ end
1144
+
1145
+ def addr
1146
+ [nil, @port, @host, @host]
1147
+ end
1148
+
1149
+ def <<(str)
1150
+ # ignored
1087
1151
  end
1088
1152
  end
1089
1153
 
@@ -1124,6 +1188,7 @@ class Session # :nodoc:
1124
1188
 
1125
1189
  attr_accessor :ssl_config
1126
1190
  attr_reader :ssl_peer_cert
1191
+ attr_accessor :test_loopback_http_response
1127
1192
 
1128
1193
  def initialize(dest, user_agent, from)
1129
1194
  @dest = dest
@@ -1143,6 +1208,8 @@ class Session # :nodoc:
1143
1208
  @ssl_config = nil
1144
1209
  @ssl_peer_cert = nil
1145
1210
 
1211
+ @test_loopback_http_response = nil
1212
+
1146
1213
  @user_agent = user_agent
1147
1214
  @from = from
1148
1215
  @state = :INIT
@@ -1338,11 +1405,17 @@ private
1338
1405
  end
1339
1406
 
1340
1407
  def create_socket(site)
1408
+ socket = nil
1341
1409
  begin
1342
- if @debug_dev
1343
- DebugSocket.create_socket(site.host, site.port, @debug_dev)
1410
+ @debug_dev << "! CONNECT TO #{site.host}:#{site.port}\n" if @debug_dev
1411
+ if str = @test_loopback_http_response.shift
1412
+ socket = LoopBackSocket.new(site.host, site.port, str)
1344
1413
  else
1345
- TCPSocket.new(site.host, site.port)
1414
+ socket = TCPSocket.new(site.host, site.port)
1415
+ end
1416
+ if @debug_dev
1417
+ @debug_dev << "! CONNECTION ESTABLISHED\n"
1418
+ socket = DebugSocket.new(socket, @debug_dev)
1346
1419
  end
1347
1420
  rescue SystemCallError => e
1348
1421
  e.message << " (#{site})"
@@ -1351,6 +1424,7 @@ private
1351
1424
  e.message << " (#{site})"
1352
1425
  raise
1353
1426
  end
1427
+ socket
1354
1428
  end
1355
1429
 
1356
1430
  # wrap socket with OpenSSL.
@@ -1708,6 +1782,10 @@ end
1708
1782
  @redirect_uri_callback = redirect_uri_callback
1709
1783
  end
1710
1784
 
1785
+ def test_loopback_http_response
1786
+ @session_manager.test_loopback_http_response
1787
+ end
1788
+
1711
1789
  # SYNOPSIS
1712
1790
  # Client#get_content(uri, query = nil, extheader = {}, &block = nil)
1713
1791
  #
@@ -30,6 +30,8 @@ class WebAgent
30
30
  end
31
31
 
32
32
  def domain_match(host, domain)
33
+ domain = domain.downcase
34
+ host = host.downcase
33
35
  case domain
34
36
  when /\d+\.\d+\.\d+\.\d+/
35
37
  return (host == domain)
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
2
+ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: httpclient
5
5
  version: !ruby/object:Gem::Version
6
- version: 2.1.0
7
- date: 2007-07-12 00:00:00 +09:00
6
+ version: 2.1.1
7
+ date: 2007-08-28 00:00:00 +09:00
8
8
  summary: gives something like the functionality of libwww-perl (LWP) in Ruby
9
9
  require_paths:
10
10
  - lib
11
11
  email: nahi@ruby-lang.org
12
- homepage: http://dev.ctor.org/http-access2
12
+ homepage: http://dev.ctor.org/httpclient
13
13
  rubyforge_project:
14
14
  description:
15
15
  autorequire: