rainbows.git  about / heads / tags
Unicorn for sleepy apps and slow clients
blob bcf1dbac6b5129ba1a10bc4bb395eb2bb45e73ad 675 bytes (raw)
$ git show HEAD:lib/rainbows/http_parser.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 
# -*- encoding: binary -*-
# :enddoc:
# avoid modifying Unicorn::HttpParser
class Rainbows::HttpParser < Unicorn::HttpParser
  @keepalive_requests = 100
  class << self
    attr_accessor :keepalive_requests
  end

  def initialize(*args)
    @keepalive_requests = self.class.keepalive_requests
    super
  end

  def next?
    return false if (@keepalive_requests -= 1) <= 0
    super
  end

  def hijack_setup(io)
    @hijack_io = io
    env['rack.hijack'] = self # avoid allocating a new proc this way
  end

  def call # for rack.hijack
    env['rack.hijack_io'] = @hijack_io
  end

  def self.quit
    alias_method :next?, :never!
  end

  def never!
    false
  end
end

git clone https://yhbt.net/rainbows.git