3
require "webrick/https"
5
# SSL features cannot be tested
7
require 'webrick/httpservlet/abstract'
9
module TestNetHTTPUtils
15
klass = Net::HTTP::Proxy(config('proxy_host'), config('proxy_port'))
16
http = klass.new(config('host'), config('port'))
17
http.set_debug_output logfile()
22
self.class::CONFIG[key]
26
$DEBUG ? $stderr : NullWriter.new
35
until @server.status == :Stop
44
:BindAddress => config('host'),
45
:Port => config('port'),
46
:Logger => WEBrick::Log.new(NullWriter.new),
48
:ShutdownSocketWithoutClose => true,
49
:ServerType => Thread,
51
if defined?(OpenSSL) and config('ssl_enable')
52
server_config.update({
54
:SSLCertificate => config('ssl_certificate'),
55
:SSLPrivateKey => config('ssl_private_key'),
58
@server = WEBrick::HTTPServer.new(server_config)
59
@server.mount('/', Servlet)
63
TCPSocket.open(config('host'), config('port')).close
64
rescue Errno::ECONNREFUSED
67
raise 'cannot spawn server; give up' if n_try_max < 0
73
$test_net_http_data = (0...256).to_a.map {|i| i.chr }.join('') * 64
74
$test_net_http_data_type = 'application/octet-stream'
76
class Servlet < WEBrick::HTTPServlet::AbstractServlet
78
res['Content-Type'] = $test_net_http_data_type
79
res.body = $test_net_http_data
84
res['Content-Type'] = req['Content-Type']