Sha256: eec6c8de9d1140b9488e0b246161495cdc8beb87d375140420019a4f8c8a4db3

Contents?: true

Size: 1.25 KB

Versions: 2

Compression:

Stored size: 1.25 KB

Contents

require 'asir/transport/http'
require 'webrick'

module ASIR
  class Transport
    # !SLIDE
    # WEBrick Transport server.
    class Webrick < HTTP

      # Server-side: WEBrick

      # Receive the Message payload from the HTTP Message body.
      def _receive_message state
        http_message = state.in_stream
        state.message_payload = http_message.body
        state.message_opaque  = http_message
      end

      # Send the Result payload in the HTTP Response body as application/binary.
      def _send_result state
        http_result = state.out_stream
        http_result[CONTENT_TYPE] = APPLICATION_BINARY
        http_result.body = state.result_payload
      end

      def prepare_server! opts = { }
        u = URI.parse(uri)
        port = u.port
        path = u.path
        opts[:Port] ||= port
        @server = ::WEBrick::HTTPServer.new(opts)
        @server.mount_proc path, lambda { | rq, rs |
          serve_message! rq, rs
        }
        self
      rescue ::Exception => exc
        raise Error, "Webrick Server #{uri.inspect}: #{exc.inspect}", exc.backtrace
      end

      def run_server!
        @server.start
        self
      end

      def stop_server!
        @server.stop
        self
      end
    end
    # !SLIDE END
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
asir-1.2.1 lib/asir/transport/webrick.rb
asir-1.2.0 lib/asir/transport/webrick.rb