Sha256: 0b7cb9d9646aea4ffff36f548af614a284ccb274340f7210cae2917b3d4761f9

Contents?: true

Size: 1.41 KB

Versions: 20

Compression:

Stored size: 1.41 KB

Contents

require 'asir'

require 'rubygems'
gem 'httpclient'
require 'httpclient'
require 'uri'

module ASIR
  class Transport
    # !SLIDE
    # HTTP Transport
    #
    # Using HTTPClient.
    class HTTP < self
      attr_accessor :uri, :server, :debug

      # Client-side: HTTPClient

      def client
        @client ||=
          Channel.new(:on_connect =>
            lambda { | channel | ::HTTPClient.new })
      end

      def close
        @client.close if @client
      ensure
        @client = nil unless Channel === @client
      end

      # Send the Message payload String using HTTP POST.
      # Returns the HTTPClient::Request response object.
      def _send_message message, message_payload
        client.with_stream! do | client |
          client.post(uri, message_payload)
        end
      end

      # Recieve the Result payload String from the opaque
      # HTTPClient::Request response object returned from #_send_message.
      def _receive_result message, http_result_message
        # $stderr.puts " ### http_result_message.content.encoding = #{http_result_message.content.encoding.inspect}" rescue nil
        # $stderr.puts " ### http_result_message.content = #{http_result_message.content.inspect}" rescue nil
        http_result_message.content.to_s
      end

      CONTENT_TYPE = 'Content-Type'.freeze
      APPLICATION_BINARY = 'application/binary'.freeze

    end
    # !SLIDE END
  end # class
end # module

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
asir-1.1.12 lib/asir/transport/http.rb
asir-1.1.11 lib/asir/transport/http.rb
asir-1.1.10 lib/asir/transport/http.rb
asir-1.1.9 lib/asir/transport/http.rb
asir-1.1.8 lib/asir/transport/http.rb
asir-1.1.7 lib/asir/transport/http.rb
asir-1.1.6 lib/asir/transport/http.rb
asir-1.1.5 lib/asir/transport/http.rb
asir-1.1.4 lib/asir/transport/http.rb
asir-1.1.3 lib/asir/transport/http.rb
asir-1.1.2 lib/asir/transport/http.rb
asir-1.1.1 lib/asir/transport/http.rb
asir-1.1.0 lib/asir/transport/http.rb
asir-1.0.8 lib/asir/transport/http.rb
asir-1.0.7 lib/asir/transport/http.rb
asir-1.0.6 lib/asir/transport/http.rb
asir-1.0.5 lib/asir/transport/http.rb
asir-1.0.4 lib/asir/transport/http.rb
asir-1.0.1 lib/asir/transport/http.rb
asir-0.2.0 lib/asir/transport/http.rb