Class List Method List File List

# Class: Vertx::HttpServer

Inherits:
  Object
  - Object
  - Vertx::HttpServer
  show all
Includes:
  SSLSupport, TCPSupport
Defined in:
  src/main/ruby_scripts/core/http.rb

## Overview

An HTTP and websockets server

Author:

- Tim Fox

## Instance Method Summary (collapse)

- - (Object) client_auth_required=(val)

  Client authentication is an extra level of security in SSL, and requires clients to provide client certificates.

- - (Object) close(&hndlr)

  Close the server.

- - (HttpServer) initialize constructor

  Create a new HttpServer.

- - (Object) listen(port, host = "0.0.0.0")

  Instruct the server to listen for incoming connections.

- - (Object) request_handler(proc = nil, &hndlr)

  Set the HTTP request handler for the server.

- - (Object) websocket_handler(proc = nil, &hndlr)

  Set the websocket handler for the server.

### Methods included from SSLSupport

#key_store_password=, #key_store_path=, #ssl=, #trust_store_password=, #trust_store_path=

### Methods included from TCPSupport

#receive_buffer_size=, #reuse_address=, #send_buffer_size=, #so_linger=, #tcp_keep_alive=, #traffic_class=

## Constructor Details

### - (`HttpServer`) initialize

Create a new HttpServer

    29
    30
    31

    # File 'src/main/ruby_scripts/core/http.rb', line 29

    def initialize
      @j_del = org.vertx.java.deploy.impl.VertxLocator.vertx.createHttpServer
    end

## Instance Method Details

### - (`Object`) client_auth_required=(val)

Client authentication is an extra level of security in SSL, and requires clients to provide client certificates. Those certificates must be added to the server trust store. do not authenticate then they will not make a connection.

Parameters:

- val. (`Boolean`) —

  If true then the server will request client authentication from any connecting clients, if they

    68
    69
    70
    71

    # File 'src/main/ruby_scripts/core/http.rb', line 68

    def client_auth_required=(val)
      @j_del.setClientAuthRequired(val)
      self
    end

### - (`Object`) close(&hndlr)

Close the server. The handler will be called when the close is complete.

    74
    75
    76

    # File 'src/main/ruby_scripts/core/http.rb', line 74

    def close(&hndlr)
      @j_del.close(hndlr)
    end

### - (`Object`) listen(port, host = "0.0.0.0")

Instruct the server to listen for incoming connections.

Parameters:

- port. (`FixNum`) —

  The port to listen on.

- host. (`FixNum`) —

  The host name or ip address to listen on.

    59
    60
    61
    62

    # File 'src/main/ruby_scripts/core/http.rb', line 59

    def listen(port, host = "0.0.0.0")
      @j_del.listen(port, host)
      self
    end

### - (`Object`) request_handler(proc = nil, &hndlr)

Set the HTTP request handler for the server. As HTTP requests arrive on the server a new Vertx::HttpServerRequest instance will be created and passed to the handler.

Parameters:

- proc (`Proc`) (defaults to: `nil`) —

  A proc to be used as the handler

- hndlr (`Block`) —

  A block to be used as the handler

    37
    38
    39
    40
    41

    # File 'src/main/ruby_scripts/core/http.rb', line 37

    def request_handler(proc = nil, &hndlr)
      hndlr = proc if proc
      @j_del.requestHandler { |j_del| hndlr.call(HttpServerRequest.new(j_del)) }
      self
    end

### - (`Object`) websocket_handler(proc = nil, &hndlr)

Set the websocket handler for the server. As websocket requests arrive on the server and are accepted a new WebSocket instance will be created and passed to the handler.

Parameters:

- proc (`Proc`) (defaults to: `nil`) —

  A proc to be used as the handler

- hndlr (`Block`) —

  A block to be used as the handler

    47
    48
    49
    50
    51
    52
    53
    54

    # File 'src/main/ruby_scripts/core/http.rb', line 47

    def websocket_handler(proc = nil, &hndlr)
      hndlr = proc if proc
      @j_del.websocketHandler do |param|
        hndlr.call(ServerWebSocket.new(param))
      end

      self
    end