File: dummy_server.rb

package info (click to toggle)
ruby-http 4.4.1-6
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 704 kB
  • sloc: ruby: 5,388; makefile: 9
file content (43 lines) | stat: -rw-r--r-- 892 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# frozen_string_literal: true

require "webrick"
require "webrick/ssl"

require "support/black_hole"
require "support/dummy_server/servlet"
require "support/servers/config"
require "support/servers/runner"
require "support/ssl_helper"

class DummyServer < WEBrick::HTTPServer
  include ServerConfig

  CONFIG = {
    :BindAddress  => "127.0.0.1",
    :Port         => 0,
    :AccessLog    => BlackHole,
    :Logger       => BlackHole
  }.freeze

  SSL_CONFIG = CONFIG.merge(
    :SSLEnable            => true,
    :SSLStartImmediately  => true
  ).freeze

  def initialize(options = {}) # rubocop:disable Style/OptionHash
    super(options[:ssl] ? SSL_CONFIG : CONFIG)
    mount("/", Servlet)
  end

  def endpoint
    "#{scheme}://#{addr}:#{port}"
  end

  def scheme
    config[:SSLEnable] ? "https" : "http"
  end

  def ssl_context
    @ssl_context ||= SSLHelper.server_context
  end
end