Class: Request

Inherits:
Object
  • Object
show all
Defined in:
lib/fresco/runtime/runtime.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, path, body) ⇒ Request

The HTTP verb is exposed as ‘req.verb` (not `req.method`). Spinel mis-types any accessor named `method`: it conflates the reader with Ruby’s ‘Object#method(:sym)` reflection and boxes the const-char* return as sp_Method (cls_id 45), which then breaks dispatch when handle_connection calls dispatch_request with the boxed value. Renaming sidesteps the analyzer collision.



599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
# File 'lib/fresco/runtime/runtime.rb', line 599

def initialize(method, path, body)
  @verb    = method
  @path    = path
  @body    = body
  @version = "HTTP/1.0" # parser overwrites; CLI mode keeps the default
  # 0 = parsed OK; 400 = malformed request; 413 = body too large.
  # parse_http_request always returns a Request (no Request|nil
  # union) so Spinel keeps `parsed` pinned to sp_Request * through
  # the dispatch chain — otherwise every #handle / #call along the
  # way widens to sp_RbVal req and the polymorphic call to each
  # subclass's #call falls back to the base 500 fallback.
  @parse_status = 0
  # Seed-and-clear pins ivar hashes to their concrete specialisation;
  # see plan's Spinel quirks. The Params wrapper keeps Request's
  # public surface stable while letting actions reach typed coercion
  # via `req.params.int(:id)` etc.
  raw = { __t: "" }
  raw.delete(:__t)
  @params  = Params.new(raw)
  @query   = { __t: "" }
  @query.delete(:__t)
  @headers = { "__t" => "" }
  @headers.delete("__t")
  # Cookies are Str→Str (raw Cookie header pairs after url_decode).
  # Same StrStrHash pinning as @headers.
  @cookies = { "__t" => "" }
  @cookies.delete("__t")
  # Session is allocated fresh per request. Stays empty unless
  # parse_http_request / parse_dev_request finds a valid signed
  # cookie and load_from succeeds.
  @session = Session.new
  # Flash is the one-shot companion to session. promote_flash!
  # populates read_data after session load; consume_flash_writes!
  # bakes write_data back in before the response cookie ships.
  @flash   = Flash.new
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



590
591
592
# File 'lib/fresco/runtime/runtime.rb', line 590

def body
  @body
end

#cookiesObject

Returns the value of attribute cookies.



590
591
592
# File 'lib/fresco/runtime/runtime.rb', line 590

def cookies
  @cookies
end

#flashObject

Returns the value of attribute flash.



590
591
592
# File 'lib/fresco/runtime/runtime.rb', line 590

def flash
  @flash
end

#headersObject

Returns the value of attribute headers.



590
591
592
# File 'lib/fresco/runtime/runtime.rb', line 590

def headers
  @headers
end

#paramsObject

Returns the value of attribute params.



590
591
592
# File 'lib/fresco/runtime/runtime.rb', line 590

def params
  @params
end

#parse_statusObject

Returns the value of attribute parse_status.



590
591
592
# File 'lib/fresco/runtime/runtime.rb', line 590

def parse_status
  @parse_status
end

#pathObject

Returns the value of attribute path.



590
591
592
# File 'lib/fresco/runtime/runtime.rb', line 590

def path
  @path
end

#queryObject

Returns the value of attribute query.



590
591
592
# File 'lib/fresco/runtime/runtime.rb', line 590

def query
  @query
end

#sessionObject

Returns the value of attribute session.



590
591
592
# File 'lib/fresco/runtime/runtime.rb', line 590

def session
  @session
end

#verbObject

Returns the value of attribute verb.



590
591
592
# File 'lib/fresco/runtime/runtime.rb', line 590

def verb
  @verb
end

#versionObject

Returns the value of attribute version.



590
591
592
# File 'lib/fresco/runtime/runtime.rb', line 590

def version
  @version
end

Instance Method Details

#keep_alive?Boolean

HTTP/1.1 keep-alive defaults to on; explicit ‘Connection: close` opts out. HTTP/1.0 defaults to off; `Connection: keep-alive` opts in. Header lookup is case-insensitive on the wire, but our parser already lowercased keys.

Returns:

  • (Boolean)


640
641
642
643
644
645
646
647
648
649
# File 'lib/fresco/runtime/runtime.rb', line 640

def keep_alive?
  conn = ""
  if @headers.key?("connection")
    conn = @headers["connection"].downcase
  end
  if @version == "HTTP/1.1"
    return conn != "close"
  end
  conn == "keep-alive"
end