Class: Gitlab::BufferedIo

Inherits:
Object
  • Object
show all
Extended by:
Utils::Override
Defined in:
lib/gitlab/buffered_io.rb

Constant Summary collapse

HEADER_READ_TIMEOUT =
20

Instance Method Summary collapse

Methods included from Utils::Override

extended, extensions, included, method_added, override, prepended, queue_verification, verify!

Instance Method Details

#readuntil(terminator, ignore_eof = false) ⇒ Object


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/gitlab/buffered_io.rb', line 24

def readuntil(terminator, ignore_eof = false)
  start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)

  begin
    until idx = @rbuf.index(terminator)
      if (elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time) > HEADER_READ_TIMEOUT
        raise Gitlab::HTTP::HeaderReadTimeout, "Request timed out after reading headers for #{elapsed} seconds"
      end

      rbuf_fill
    end

    return rbuf_consume(idx + terminator.size)
  rescue EOFError
    raise unless ignore_eof
    return rbuf_consume(@rbuf.size)
  end
end