Sha256: e0722a72c05adcaf08a8d9859fdb5253cc9a867cedc3d0cc13d752d262facb71

Contents?: true

Size: 1.3 KB

Versions: 9

Compression:

Stored size: 1.3 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 *Error::Unrecoverable.modules
        raise
      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

9 entries across 9 versions & 1 rubygems

Version Path
asir-1.2.11 lib/asir/transport/webrick.rb
asir-1.2.10 lib/asir/transport/webrick.rb
asir-1.2.9 lib/asir/transport/webrick.rb
asir-1.2.8 lib/asir/transport/webrick.rb
asir-1.2.7 lib/asir/transport/webrick.rb
asir-1.2.6 lib/asir/transport/webrick.rb
asir-1.2.5 lib/asir/transport/webrick.rb
asir-1.2.3 lib/asir/transport/webrick.rb
asir-1.2.2 lib/asir/transport/webrick.rb