Class: Cloudflare::DurableObjectRequest
- Inherits:
-
Object
- Object
- Cloudflare::DurableObjectRequest
- Defined in:
- lib/homura/runtime/durable_object.rb
Overview
The incoming ‘request` argument passed to DO handlers. `body_text` is pre-awaited by the JS dispatcher because Ruby runs synchronously under Opal (same pattern as `Rack::Handler::Homura.call`).
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#js_request ⇒ Object
readonly
Returns the value of attribute js_request.
Instance Method Summary collapse
- #[](name) ⇒ Object
-
#headers ⇒ Object
Shallow header Hash with lowercased keys.
-
#initialize(js_request, body_text = "") ⇒ DurableObjectRequest
constructor
A new instance of DurableObjectRequest.
- #json ⇒ Object
- #method ⇒ Object
- #path ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(js_request, body_text = "") ⇒ DurableObjectRequest
Returns a new instance of DurableObjectRequest.
587 588 589 590 |
# File 'lib/homura/runtime/durable_object.rb', line 587 def initialize(js_request, body_text = "") @js_request = js_request @body = body_text.to_s end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
585 586 587 |
# File 'lib/homura/runtime/durable_object.rb', line 585 def body @body end |
#js_request ⇒ Object (readonly)
Returns the value of attribute js_request.
585 586 587 |
# File 'lib/homura/runtime/durable_object.rb', line 585 def js_request @js_request end |
Instance Method Details
#[](name) ⇒ Object
625 626 627 |
# File 'lib/homura/runtime/durable_object.rb', line 625 def [](name) headers[name.to_s.downcase] end |
#headers ⇒ Object
Shallow header Hash with lowercased keys.
617 618 619 620 621 622 623 |
# File 'lib/homura/runtime/durable_object.rb', line 617 def headers return @headers if @headers h = {} js = @js_request `(#{js} && #{js}.headers && typeof #{js}.headers.forEach === 'function') && #{js}.headers.forEach(function(v, k) { #{h}.$store(String(k).toLowerCase(), String(v)); })` @headers = h end |
#json ⇒ Object
629 630 631 632 633 |
# File 'lib/homura/runtime/durable_object.rb', line 629 def json JSON.parse(body) rescue JSON::ParserError {} end |
#method ⇒ Object
592 593 594 595 |
# File 'lib/homura/runtime/durable_object.rb', line 592 def method js = @js_request `(#{js} ? String(#{js}.method || 'GET') : 'GET')` end |
#path ⇒ Object
602 603 604 605 606 607 608 609 610 611 612 613 614 |
# File 'lib/homura/runtime/durable_object.rb', line 602 def path u = url return "" if u.nil? || u.empty? begin # Extract pathname via URL() so relative paths aren't mangled. u_str = u `new URL(#{u_str}).pathname` rescue StandardError # Fallback regex — strip scheme+host, keep everything up to ?/#. m = u.match(%r{\Ahttps?://[^/]+([^?#]*)}) m ? m[1] : u end end |
#url ⇒ Object
597 598 599 600 |
# File 'lib/homura/runtime/durable_object.rb', line 597 def url js = @js_request `(#{js} ? String(#{js}.url || '') : '')` end |