boazsegev / iodine

iodine - HTTP / WebSockets Server for Ruby with Pub/Sub support
MIT License
908 stars 51 forks source link

Rack 3 compatibility #153

Open waltjones opened 9 months ago

waltjones commented 9 months ago

Rack 3 now has Rackup as a separate gem: https://github.com/rack/rack/pull/1937

This PR detects whether the Rackup namespace is present, and supports both Rack 2 and Rack 3.

The conditional logic for this PR follows the pattern and rationale used here. https://github.com/puma/puma/pull/3061

waltjones commented 8 months ago

@boazsegev thank you for looking, and thank you for iodine.

There are two relevant changes in Rack 3 that I'm aware of.

ENV['RACK_HANDLER'] no longer works, for me at least, and ENV['RACKUP_HANDLER'] is needed. This can go outside the conditional, but in that case, both need to be added.

ENV['RACK_HANDLER'] ||= 'iodine'
ENV['RACKUP_HANDLER'] ||= 'iodine'

::Rack::Handler.register did still work for me, but not with string arguments.

::Rack::Handler.register(:iodine, Iodine::Rack) works, but in the Rack 3 case I used ::Rackup::Handler.register because I don't expect the ::Rack::Handler version of this to be available much longer.

The raise is present for the case where:

For me, that fails in an unexpected way (I don't remember now quite what the exception was), and it took the effort that led to this PR to get to the bottom of it. Providing the raise will save people some time if they find themselves using Rack 3 without Rackup, and hit this code path.

I am quite certain that the iodine CLI can be called without rackup installed.

I didn't test the CLI, but if it is using Rack 3 and executes ::Rack::Handler.register, I think it will need Rackup.

waltjones commented 7 months ago

Apologies, late follow up.

I did some additional testing, and see the case for this file loading, with rack 3, without rackup.