Class: Hyperion::Server::RouteTable::StaticEntry

Inherits:
Struct
  • Object
show all
Defined in:
lib/hyperion/server/route_table.rb

Overview

2.10-D — sentinel result returned by ‘Server.handle_static`’s internal handler. When ‘Connection#serve` sees it, the writer short-circuits to a single `socket.write(buf)` of the pre-built response buffer — no header build, no body iteration. Wrapping the buffer in a small struct (rather than returning the raw String from `handle`) keeps the `[status, headers, body]` shape contract visible while giving the dispatcher a single `is_a?` branch to engage the one-syscall fast path. 2.10-F adds `headers_len` so the C fast path (`PageCache.serve_request`) can write the headers-only prefix for HEAD requests without reparsing the buffer. Defaults to `buffer.bytesize` for back-compat with callers that constructed StaticEntry the 2.10-D way (3 args, no body split) — those entries fall back to writing the whole buffer on HEAD too, which is RFC-correct (HEAD MAY include the body so long as Content-Length matches; the spec only forbids the SERVER from sending body bytes the client didn’t ask for).

2.17-A (Hot Path Task 2) adds two more fields so the C-loop writer can mem-splice a per-second-cached HTTP ‘Date:` header into a pre-built keep-alive response without rebuilding it from scratch:

* `prebuilt_keepalive_bytes` — frozen ASCII-8BIT String of
  the full HTTP/1.1 wire response (status line + Server +
  Content-Type + Content-Length + Connection: keep-alive +
  Date placeholder + body) with a 29-byte 'X' run reserved
  at `prebuilt_date_offset`.  The placeholder is overwritten
  in a per-write scratch buffer (NEVER in this frozen
  String) by the C splice helper before the syscall fires.
* `prebuilt_date_offset` — Integer byte offset of the first
  placeholder byte within `prebuilt_keepalive_bytes`.  Zero
  means "no Date placeholder; do not splice".  29 bytes is
  the canonical RFC 7231 imf-fixdate length.

Existing callers that construct StaticEntry with 3 or 4 args see nil for these new fields and the C side falls through to the un-spliced fast path it has used since 2.10-F.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bufferObject

Returns the value of attribute buffer

Returns:

  • (Object)

    the current value of buffer



81
82
83
# File 'lib/hyperion/server/route_table.rb', line 81

def buffer
  @buffer
end

#headers_lenObject

Returns the value of attribute headers_len

Returns:

  • (Object)

    the current value of headers_len



81
82
83
# File 'lib/hyperion/server/route_table.rb', line 81

def headers_len
  @headers_len
end

#methodObject

Returns the value of attribute method

Returns:

  • (Object)

    the current value of method



81
82
83
# File 'lib/hyperion/server/route_table.rb', line 81

def method
  @method
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



81
82
83
# File 'lib/hyperion/server/route_table.rb', line 81

def path
  @path
end

#prebuilt_date_offsetObject

Returns the value of attribute prebuilt_date_offset

Returns:

  • (Object)

    the current value of prebuilt_date_offset



81
82
83
# File 'lib/hyperion/server/route_table.rb', line 81

def prebuilt_date_offset
  @prebuilt_date_offset
end

#prebuilt_keepalive_bytesObject

Returns the value of attribute prebuilt_keepalive_bytes

Returns:

  • (Object)

    the current value of prebuilt_keepalive_bytes



81
82
83
# File 'lib/hyperion/server/route_table.rb', line 81

def prebuilt_keepalive_bytes
  @prebuilt_keepalive_bytes
end

Instance Method Details

#call(_request) ⇒ Object

2.10-F — StaticEntry responds to ‘#call` so it can be registered directly in the route table (instead of via a closure wrapping it). Returning `self` keeps the `[status, headers, body]` contract: `dispatch_direct!`’s is_a?(StaticEntry) branch handles the wire write. Pre- 2.10-F callers that registered via ‘Server.handle_static` still work — that registration path now stores the entry directly and the route table’s ‘respond_to?(:call)` invariant is preserved.



99
100
101
# File 'lib/hyperion/server/route_table.rb', line 99

def call(_request)
  self
end

#headers_bytesizeObject

2.10-F — bytes-count of the headers-only prefix. Used by callers that reach the StaticEntry directly (specs, custom writers); the C fast path reads the C-side ‘headers_len` mirror that `PageCache.register_prebuilt` records.



107
108
109
# File 'lib/hyperion/server/route_table.rb', line 107

def headers_bytesize
  headers_len || buffer.bytesize
end

#response_bytesObject

Returns the pre-built response bytes ready for one ‘socket.write` call. Always frozen.



86
87
88
# File 'lib/hyperion/server/route_table.rb', line 86

def response_bytes
  buffer
end