Class: Cybertrain::Context

Inherits:
Object
  • Object
show all
Defined in:
cybertrain/context.rb

Overview

Everything one request carries through the middleware stack, the router and the controller. The Response is created here and written back to the socket by the Server once the stack returns.

Instance Method Summary collapse

Instance Method Details

#csp_nonce ⇒ String

This request’s CSP nonce: 16 bytes from SecureRandom, strict Base64, made on first use and the same for the rest of the request (the header and every csp_meta_tag / javascript_tag(nonce: true) of the page). A Context is one request: never shared or reused.

Returns:

  • (String)


54
55
56
57
58
59
60
61
# File 'cybertrain/context.rb', line 54

def csp_nonce
  nonce = @csp_nonce
  if nonce.empty?
    nonce = Base64.strict_encode64(SecureRandom.random_bytes(16))
    @csp_nonce = nonce
  end
  nonce
end