Sha256: e92f06a6b338d1b97801d46a5df4ff0208e35cdb5038bf4cf986a546e172a0a3

Contents?: true

Size: 1.38 KB

Versions: 1

Compression:

Stored size: 1.38 KB

Contents

require 'net/http/server/daemon'

require 'net/protocol'

module Net
  class HTTP < Protocol
    module Server
      #
      # Starts the HTTP Server.
      #
      # @param [Boolean] background
      #   Specifies whether to run the server in the background or
      #   foreground.
      #
      # @param [Hash{Symbol => Object}] kwargs
      #   Additional keyword arguments for {Daemon#initialize}.
      #
      # @option kwargs [String] :host (DEFAULT_HOST)
      #   The host to run on.
      #
      # @option kwargs [String] :port (DEFAULT_PORT)
      #   The port to listen on.
      #
      # @option kwargs [Integer] :max_connections (MAX_CONNECTIONS)
      #   The maximum number of simultaneous connections.
      #
      # @option kwargs [#call] :handler
      #   The HTTP Request Handler object.
      #
      # @yield [request, socket]
      #   If a block is given, it will be used to process HTTP Requests.
      #
      # @yieldparam [Hash{Symbol => String,Array,Hash}] request
      #   The HTTP Request.
      #
      # @yieldparam [TCPSocket] socket
      #   The TCP socket of the client.
      #
      # @raise [ArgumentError]
      #   No `handler:` value was given.
      #
      def Server.run(background: false, **kwargs,&block)
        daemon = Daemon.new(**kwargs,&block)

        daemon.start
        daemon.join unless background
        return daemon
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
net-http-server-0.2.3 lib/net/http/server/server.rb