lib/microget.rb
# Buffer the data from the socket until we encounter the end of the headers (2x CRLF).
# Do it per byte so we can leave the socket exactly at byte offset 0 of the response body.
Buffer the data from the socket until we encounter the end of the headers (2x CRLF).
Do it per byte so we can leave the socket exactly at byte offset 0 of the response body.
Buffer the data from the socket until we encounter the end of the headers ( 2x CRLF ) . Do it per byte so we can leave the socket exactly at byte offset 0 of the response body .
def read_ahead_headers(socket)
    headers_str = ''
    headers_and_start_of_body = ''
    start_of_body = ''
    while byte = socket.read(1) do
      raise "Response header size limit reached" if headers_and_start_of_body.bytesize > HEADER_LIMIT
      headers_and_start_of_body << byte
      if headers_and_start_of_body[-4..-1] == HEADER_SEPARATOR
        headers_str = headers_and_start_of_body[0...-4]
        return headers_str
      end
    end
    raise 'No header terminating \r\n\r\n found in the response'
  end
def read_ahead_headers ( socket ) headers_str = '' headers_and_start_of_body = '' start_of_body = '' while byte = socket . read ( 1 ) do raise "Response header size limit reached" if headers_and_start_of_body . bytesize > HEADER_LIMIT headers_and_start_of_body << byte if headers_and_start_of_body [ - 4 .. - 1 ] == HEADER_SEPARATOR headers_str = headers_and_start_of_body [ 0 ... - 4 ] return headers_str end end raise 'No header terminating \r\n\r\n found in the response' end
Buffer the data from the socket until we encounter the end of the headers (2x CRLF).
Buffer the data from the socket until we encounter the end of the headers ( 2x CRLF ) .
socket