Class: AnyCable::Rack::BroadcastSubscribers::HTTPSubscriber
- Inherits:
-
BaseSubscriber
- Object
- BaseSubscriber
- AnyCable::Rack::BroadcastSubscribers::HTTPSubscriber
- Defined in:
- lib/anycable/rack/broadcast_subscribers/http_subscriber.rb
Overview
HTTP Pub/Sub subscriber
Constant Summary
Constants included from Logging
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Attributes inherited from BaseSubscriber
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(**options) ⇒ HTTPSubscriber
constructor
A new instance of HTTPSubscriber.
- #start ⇒ Object
Methods inherited from BaseSubscriber
Constructor Details
#initialize(**options) ⇒ HTTPSubscriber
Returns a new instance of HTTPSubscriber.
12 13 14 15 16 |
# File 'lib/anycable/rack/broadcast_subscribers/http_subscriber.rb', line 12 def initialize(**) super @token = [:token] @path = [:path] end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/anycable/rack/broadcast_subscribers/http_subscriber.rb', line 10 def path @path end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
10 11 12 |
# File 'lib/anycable/rack/broadcast_subscribers/http_subscriber.rb', line 10 def token @token end |
Instance Method Details
#call(env) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/anycable/rack/broadcast_subscribers/http_subscriber.rb', line 22 def call(env) req = ::Rack::Request.new(env) return invalid_request unless req.post? if token && req.get_header("HTTP_AUTHORIZATION") != "Bearer #{token}" return invalid_request(401) end req.body.read [201, {"Content-Type" => "text/plain"}, ["OK"]] end |
#start ⇒ Object
18 19 20 |
# File 'lib/anycable/rack/broadcast_subscribers/http_subscriber.rb', line 18 def start log(:info) { "Accepting pub/sub request at #{path}" } end |