Class: Tep::Proxy::UpstreamHead

Inherits:
Object
  • Object
show all
Defined in:
lib/tep/proxy.rb

Overview

Parsed upstream response head, produced by read_upstream_head. ‘fill_from` parses a header blob (“Status-LinernH: vrn…”, no trailing blank line) into status + the downcased-name header bag + the chunked / SSE transport flags.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUpstreamHead

Returns a new instance of UpstreamHead.



671
672
673
674
675
676
677
678
# File 'lib/tep/proxy.rb', line 671

def initialize
  @status     = 0
  @headers    = Tep.str_hash
  @is_chunked = false
  @is_sse     = false
  @leftover   = ""
  @ok         = false
end

Instance Attribute Details

#headersObject

Returns the value of attribute headers.



669
670
671
# File 'lib/tep/proxy.rb', line 669

def headers
  @headers
end

#is_chunkedObject

Returns the value of attribute is_chunked.



669
670
671
# File 'lib/tep/proxy.rb', line 669

def is_chunked
  @is_chunked
end

#is_sseObject

Returns the value of attribute is_sse.



669
670
671
# File 'lib/tep/proxy.rb', line 669

def is_sse
  @is_sse
end

#leftoverObject

Returns the value of attribute leftover.



669
670
671
# File 'lib/tep/proxy.rb', line 669

def leftover
  @leftover
end

#okObject

Returns the value of attribute ok.



669
670
671
# File 'lib/tep/proxy.rb', line 669

def ok
  @ok
end

#statusObject

Returns the value of attribute status.



669
670
671
# File 'lib/tep/proxy.rb', line 669

def status
  @status
end

Instance Method Details

#fill_from(blob) ⇒ Object



680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
# File 'lib/tep/proxy.rb', line 680

def fill_from(blob)
  eol = Tep.str_find(blob, "\r\n", 0)
  if eol < 0
    return 0
  end
  line = blob[0, eol]
  sp1 = Tep.str_find(line, " ", 0)
  if sp1 >= 0
    rest = line[sp1 + 1, line.length - sp1 - 1]
    sp2 = Tep.str_find(rest, " ", 0)
    if sp2 >= 0
      @status = rest[0, sp2].to_i
    else
      @status = rest.to_i
    end
  end
  # Header lines.
  pos = eol + 2
  while pos < blob.length
    neol = Tep.str_find(blob, "\r\n", pos)
    stop = neol
    if stop < 0
      stop = blob.length
    end
    line2 = blob[pos, stop - pos]
    ci = Tep.str_find(line2, ":", 0)
    if ci > 0
      name = line2[0, ci].downcase
      vpos = ci + 1
      # skip one leading space
      if vpos < line2.length && line2[vpos, 1] == " "
        vpos += 1
      end
      val = line2[vpos, line2.length - vpos]
      @headers[name] = val
      if name == "transfer-encoding" && Tep.str_find(val.downcase, "chunked", 0) >= 0
        @is_chunked = true
      end
      if name == "content-type" && val.downcase.start_with?("text/event-stream")
        @is_sse = true
      end
    end
    if neol < 0
      return 0
    end
    pos = neol + 2
  end
  0
end