boazsegev / iodine

iodine - HTTP / WebSockets Server for Ruby with Pub/Sub support

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`Rack::Lint::LintError: env[SERVER_PORT] is not an Integer` when using `rackup` with `--env development`

adam12 opened this issue · comments

System Information

  • OS: Linux bb13cf4bee22 5.10.47-linuxkit #1 SMP PREEMPT Sat Jul 3 21:50:16 UTC 2021 aarch64 GNU/Linux
  • Ruby: ruby 2.7.3p183 (2021-04-05 revision 6847ee089d) [aarch64-linux]
  • Version: 0.7.44

Description

When using rackup to start Iodine, providing the --env development option (which sets up default Rack middleware), all requests raise Rack::Lint::LintError with an error concerning the SERVER_PORT value. I've confirmed that it is an empty String ("") in the env Hash object.

This seems to be dependent on the Host header sent by the client/loadbalancer. Some will include the port, which in case everything is fine, but if the port is excluded, Iodine sets the env variable to an empty string, which fails Rack::Lint. It should leave it nil or set it to a default for the scheme.

Rack App to Reproduce

APP = {|env| [200, {}, ["Hello World"]] }
run APP

Testing code

# Run rackup in background
rackup example.ru --env development --server iodine &

# Send curl with host header excluding port (will be broken)
curl http://localhost:9292 -H "Host: example.com"

# Send curl with Host header including port (will work)
curl http://localhost:9292 -H "Host: example.com:9292"

Expected behavior

curl http://localhost:9292 -H "Host: example.com"
Hello World

Actual behavior

curl http://localhost:9292 -H "Host: example.com"
Rack::Lint::LintError: env[SERVER_PORT] is not an Integer

I can reproduce without using rackup and just use iodine directly.

# example.ru
use Rack::Lint
run ->(env) { [200, {}, ["Hello World"]] }
bundle exec exe/iodine -w 1 -t 1 -p 2222 example.ru

I've tried debugging this, but I can't get lldb to not crash.

commented

Thanks for opening this issue and for the PR!

Is there any progress here or any kind of workaround here?

commented

Hi @yildizsc ,

You're welcome.

Sorry for not having this fixed earlier... I was sure I merged Adam's PR, but it seems I fell asleep on the watch. I just released the fix.

Thanks! and Cheers!