Sha256: 43662de8a1b64401ef1b49253bd87d1a0cf28848dc33dcfb2430b82813aa377c

Contents?: true

Size: 1.06 KB

Versions: 11

Compression:

Stored size: 1.06 KB

Contents

# encoding: utf-8
module TestServer
  class StreamingController < ApplicationController
    include ActionController::Live

    add_breadcrumb I18n.t('views.root.link'), :root_path
    add_breadcrumb I18n.t('views.streaming.link'), :streaming_path

    def index
    end

    def plain
      params[:count].to_i.times do |n|
        response.stream.write(
          encode(params) { "#{n + 1}: data" }
        )
        sleep(params[:wait].to_f / 1_000.0)
      end

      response.stream.close
    end

    def eicar
      generate_eicar.each do |c|
        response.stream.write(
          encode(params) { c }
        )

        sleep(params[:wait].to_f / 1_000.0)
      end

      response.stream.close
    end

    def random
      params[:count].to_i.times do |n|
        
        response.stream.write(
          encode(params) { generate_random_string(1) }
        )
        sleep(params[:wait].to_f / 1_000.0)
      end

      response.stream.close
    end

    private

    def default_params
      {
        wait: 1_000,
        count: 1,
      }.merge super
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
test_server-0.5.2 app/controllers/test_server/streaming_controller.rb
test_server-0.5.1 app/controllers/test_server/streaming_controller.rb
test_server-0.5.0 app/controllers/test_server/streaming_controller.rb
test_server-0.4.1 app/controllers/test_server/streaming_controller.rb
test_server-0.4.0 app/controllers/test_server/streaming_controller.rb
test_server-0.3.7 app/controllers/test_server/streaming_controller.rb
test_server-0.3.6 app/controllers/test_server/streaming_controller.rb
test_server-0.3.5 app/controllers/test_server/streaming_controller.rb
test_server-0.3.4 app/controllers/test_server/streaming_controller.rb
test_server-0.3.2 app/controllers/test_server/streaming_controller.rb
test_server-0.3.1 app/controllers/test_server/streaming_controller.rb