diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-25 15:13:14 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-25 15:13:14 +0000 |
commit | d0233291bc8a5068e52c69c210e5979e5324b5bc (patch) | |
tree | 7d9459449c33792c63eeb7baa071e76352e0baab /trunk/test/net/http/utils.rb | |
parent | 0dc342de848a642ecce8db697b8fecd83a63e117 (diff) | |
parent | 72eaacaa15256ab95c3b52ea386f88586fb9da40 (diff) |
re-adding tag v1_9_0_4 as an alias of trunk@18848v1_9_0_4
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_9_0_4@18849 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'trunk/test/net/http/utils.rb')
-rw-r--r-- | trunk/test/net/http/utils.rb | 96 |
1 files changed, 0 insertions, 96 deletions
diff --git a/trunk/test/net/http/utils.rb b/trunk/test/net/http/utils.rb deleted file mode 100644 index e685a8ff61..0000000000 --- a/trunk/test/net/http/utils.rb +++ /dev/null @@ -1,96 +0,0 @@ -require 'webrick' -begin - require "webrick/https" -rescue LoadError - # SSL features cannot be tested -end -require 'webrick/httpservlet/abstract' - -module TestNetHTTPUtils - def start(&block) - new().start(&block) - end - - def new - klass = Net::HTTP::Proxy(config('proxy_host'), config('proxy_port')) - http = klass.new(config('host'), config('port')) - http.set_debug_output logfile() - http - end - - def config(key) - self.class::CONFIG[key] - end - - def logfile - $DEBUG ? $stderr : NullWriter.new - end - - def setup - spawn_server - end - - def teardown - @server.shutdown - until @server.status == :Stop - sleep 0.1 - end - # resume global state - Net::HTTP.version_1_2 - end - - def spawn_server - server_config = { - :BindAddress => config('host'), - :Port => config('port'), - :Logger => WEBrick::Log.new(NullWriter.new), - :AccessLog => [], - :ShutdownSocketWithoutClose => true, - :ServerType => Thread, - } - if defined?(OpenSSL) and config('ssl_enable') - server_config.update({ - :SSLEnable => true, - :SSLCertificate => config('ssl_certificate'), - :SSLPrivateKey => config('ssl_private_key'), - }) - end - @server = WEBrick::HTTPServer.new(server_config) - @server.mount('/', Servlet) - @server.start - n_try_max = 5 - begin - TCPSocket.open(config('host'), config('port')).close - rescue Errno::ECONNREFUSED - sleep 0.2 - n_try_max -= 1 - raise 'cannot spawn server; give up' if n_try_max < 0 - retry - end - end - - $test_net_http = nil - $test_net_http_data = (0...256).to_a.map {|i| i.chr }.join('') * 64 - $test_net_http_data.force_encoding("ASCII-8BIT") - $test_net_http_data_type = 'application/octet-stream' - - class Servlet < WEBrick::HTTPServlet::AbstractServlet - def do_GET(req, res) - res['Content-Type'] = $test_net_http_data_type - res.body = $test_net_http_data - end - - # echo server - def do_POST(req, res) - res['Content-Type'] = req['Content-Type'] - res.body = req.body - end - end - - class NullWriter - def <<(s) end - def puts(*args) end - def print(*args) end - def printf(*args) end - end -end |