module WEBrick
  class HTTPServerError < ServerError
  end

  class HTTPServer < ::WEBrick::GenericServer
    @http_version: HTTPVersion

    @mount_tab: MountTable

    @virtual_hosts: Array[untyped]

    def initialize: (?Hash[Symbol, untyped] config, ?Hash[Symbol, untyped] default) -> void

    def run: (TCPSocket sock) -> void

    def service: (HTTPRequest req, HTTPResponse res) -> void

    def do_OPTIONS: (HTTPRequest req, HTTPResponse res) -> void

    def mount: (String dir, singleton(HTTPServlet::AbstractServlet) servlet, *untyped options) -> void

    def mount_proc: (String dir, ?HTTPServlet::ProcHandler::_Callable proc) -> void
                  | (String dir, ?nil proc) { (HTTPRequest, HTTPResponse) -> void } -> void

    def unmount: (String dir) -> MountTable::value_type

    alias umount unmount

    def search_servlet: (String path) -> [singleton(HTTPServlet::AbstractServlet), Array[untyped], String, String]?

    def virtual_host: (instance server) -> void

    def lookup_server: (HTTPRequest req) -> instance?

    def access_log: (Hash[Symbol, untyped] config, HTTPRequest req, HTTPResponse res) -> void

    #
    # Creates the HTTPRequest used when handling the HTTP
    # request. Can be overridden by subclasses.
    def create_request: (Hash[Symbol, untyped] with_webrick_config) -> HTTPRequest

    #
    # Creates the HTTPResponse used when handling the HTTP
    # request. Can be overridden by subclasses.
    def create_response: (Hash[Symbol, untyped] with_webrick_config) -> HTTPResponse

    class MountTable
      type value_type = [singleton(HTTPServlet::AbstractServlet), Array[untyped]]

      @tab: Hash[String, value_type]

      @scanner: Regexp

      def initialize: () -> void

      def []: (String dir) -> value_type

      def []=: (String dir, value_type val) -> value_type

      def delete: (String dir) -> value_type

      def scan: (String path) -> [String, String]

      private

      def compile: () -> void

      def normalize: (String dir) -> String
    end
  end
end
