Class: WrapItRuby::Middleware::WebSocketProxy
- Inherits:
-
Protocol::HTTP::Middleware
- Object
- Protocol::HTTP::Middleware
- WrapItRuby::Middleware::WebSocketProxy
- Defined in:
- lib/wrap_it_ruby/middleware/websocket_proxy.rb
Overview
Protocol::HTTP middleware that intercepts WebSocket upgrade requests BEFORE the Rack adapter, proxying them directly at the HTTP protocol level. This preserves the Upgrade/Connection headers that Rack strips.
Must be inserted as Falcon middleware, not as Rack middleware. For non-WebSocket requests, passes through to the Rack app.
Constant Summary collapse
- PROXY_PATTERN =
%r{\A/_proxy/(?<host>[^/]+)(?<path>/.*)?\z}- HOP_HEADERS =
%w[ connection keep-alive proxy-authenticate proxy-authorization te trailers transfer-encoding upgrade ].freeze
Instance Method Summary collapse
- #call(request) ⇒ Object
-
#initialize(app) ⇒ WebSocketProxy
constructor
A new instance of WebSocketProxy.
Constructor Details
#initialize(app) ⇒ WebSocketProxy
23 24 25 26 |
# File 'lib/wrap_it_ruby/middleware/websocket_proxy.rb', line 23 def initialize(app) super(app) @clients = {} end |
Instance Method Details
#call(request) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/wrap_it_ruby/middleware/websocket_proxy.rb', line 28 def call(request) if websocket?(request) && (match = PROXY_PATTERN.match(request.path)) host = match[:host].delete_suffix(".") proxy_websocket(request, host) else super(request) end end |