Sha256: cf82253758306dbf94804cbd84448e7096477267d1898a1ab09bc46b95380514

Contents?: true

Size: 908 Bytes

Versions: 13

Compression:

Stored size: 908 Bytes

Contents

module Kurchatov
  module Responders
    class Http < Kurchatov::Plugin

      def initialize(conn)
        @host, @port = conn.split(':')
        @name = "http server #{@host}:#{@port}"
        @s_time = Time.now
      end

      def run
        @server ||= TCPServer.new(@host, @port)
        loop do
          client = @server.accept
          response = info
          client.gets
          headers = "HTTP/1.1 200 OK\r\n" +
            "Server: Kurchatov Ruby\r\n" +
            "Content-Length: #{response.bytesize}\r\n" +
            "Content-Type: application/json\r\n\r\n"
          client.print headers
          client.print response
          client.close
        end
      end

      def info
        {
          :version => Kurchatov::VERSION,
          :uptime => (Time.now - @s_time).to_i,
          :config => Kurchatov::Config.to_hash,
        }.to_json + "\n"
      end

    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
kurchatov-0.0.5.pre5 lib/kurchatov/responders/http.rb
kurchatov-0.0.5.pre4 lib/kurchatov/responders/http.rb
kurchatov-0.0.5.pre2 lib/kurchatov/responders/http.rb
kurchatov-0.0.5.pre1 lib/kurchatov/responders/http.rb
kurchatov-0.0.4 lib/kurchatov/responders/http.rb
kurchatov-0.0.4d lib/kurchatov/responders/http.rb
kurchatov-0.0.4c lib/kurchatov/responders/http.rb
kurchatov-0.0.4b lib/kurchatov/responders/http.rb
kurchatov-0.0.3 lib/kurchatov/responders/http.rb
kurchatov-0.0.3b lib/kurchatov/responders/http.rb
kurchatov-0.0.3a lib/kurchatov/responders/http.rb
kurchatov-0.0.2 lib/kurchatov/responders/http.rb
kurchatov-0.0.2b lib/kurchatov/responders/http.rb