Sha256: 8da51499ee0c7fbd543a2f9b6f06dc37001d2ae1e9ef250e8d6a92871a8023f7

Contents?: true

Size: 1.07 KB

Versions: 6

Compression:

Stored size: 1.07 KB

Contents

#
# A little wrap to handle iOS HTTP requests receiving
#
class UnderOs::HTTP::Request
  class Receiver
    def initialize(request, stream=false)
      @request = request
      @stream  = stream
      @data    = NSMutableData.dataWithCapacity(0)
    end

    def connection(connection, didReceiveResponse:response)
      @data.setLength(0)
      @response = UnderOs::HTTP::Response.new(response, @data)

      emit(:response)
    end

    def connection(connection, didReceiveData:data)
      @data.setLength(0) if @stream
      @data.appendData(data)
      emit(:data)
    end

    # def connection(connection, willCacheResponse:cachedResponse)
    #   return nil # don't cache
    # end

    def connection(connection, didFailWithError:error)
      @response = UnderOs::HTTP::Response.new(error, @data)

      emit(:failure)
    end

    def connectionDidFinishLoading(connection)
      emit(:success)
    end

    def emit(event)
      @request.emit(event, response: @response)
      @request.emit(:complete, response: @response) if event == :failure || event == :success
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
under-os-http-1.4.0 lib/under_os/http/receiver.rb
under-os-1.3.0 lib/under_os/http/receiver.rb
under-os-1.2.1 lib/under_os/http/receiver.rb
under-os-1.2.0 lib/under_os/http/receiver.rb
under-os-1.1.0 lib/under_os/http/receiver.rb
under-os-1.0.0 lib/under_os/http/receiver.rb