class Gopher::Connection

Attributes

app[RW]

Public Instance Methods

receive_data(data) click to toggle source
# File lib/gopher.rb, line 255
def receive_data(data)
  begin
    raise InvalidRequest if data.length > 255
    response = app.request(data)        
    case response
    when String then send_data(response)
    when StringIO then send_data(response.read)
    when File
      while chunk = response.read(8192) do
        send_data(chunk)
      end
    end
    close_connection_after_writing
  rescue Gopher::NotFound
    send_data "not found"
    close_connection_after_writing
  rescue => e
    close_connection
    raise e
  end
end