Skip to content

Commit

Permalink
Rack 3 compatibility + bump
Browse files Browse the repository at this point in the history
  • Loading branch information
boazsegev committed Oct 29, 2022
1 parent 045f21e commit 35e1a61
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ Please notice that this change log contains changes for upcoming releases as wel

#### Change log v.0.7.50

**Fix**: Fixes compilation on Ruby 3.x - deprecation of `rc_cData`. Credit to Mohammad A. Ali (@oldmoe) for opening issue @128.
**Fix**: Fixes some compatibility issues with Rack 3.0. Credit to @taku0 for opening issue #131.

**Fix**: Fixes compilation on Ruby 3.x - deprecation of `rc_cData`. Credit to Mohammad A. Ali (@oldmoe) for opening issue #128.

#### Change log v.0.7.49

Expand Down
12 changes: 12 additions & 0 deletions examples/rack3.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
# adjusted from the code suggested by @taku0 (GitHub issue #131)
require 'rack'
require 'iodine'

run { |env|
response = Rack::Response.new(nil, 204)
response.set_cookie('aaa', 'aaa')
response.set_cookie('bbb', 'bbb')
response.finish
}
25 changes: 14 additions & 11 deletions exe/iodine
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ begin
end
end
rescue LoadError
puts "WARNING: The gam `rack` wasn't loaded before iodine started loading the rack app, using custom loader."
module Iodine
module Base
module Rack
Expand Down Expand Up @@ -133,8 +134,9 @@ rescue LoadError
# end
#
# run Heartbeat
def run(app)
@run = app
def run(app = nil, &block)
raise ArgumentError, "Both app and block given!" if app && block_given?
@run = app || block
end

# Takes a lambda or block that is used to warm-up the application.
Expand Down Expand Up @@ -214,28 +216,29 @@ module Iodine

def self.try_file filename
return nil unless File.exist? filename
return Iodine::Base::Rack::Builder.parse_file filename
result = Iodine::Base::Rack::Builder.parse_file filename
return result[0] if(result.is_a?(Array))
return result
end

def self.get_app_opts
app, opt = nil, nil
app, opt = nil, Hash.new
filename = Iodine::DEFAULT_SETTINGS[:filename_]
if filename
app, opt = try_file filename
app, opt = try_file "#{filename}.ru" unless opt
unless opt
app = try_file(filename)
app = try_file("#{filename}.ru") unless app
unless app
puts "* Couldn't find #{filename}\n testing for config.ru\n"
app, opt = try_file "config.ru"
app = try_file "config.ru"
end
else
app, opt = try_file "config.ru";
app = try_file "config.ru";
end

unless opt
unless app
puts "WARNING: Ruby application not found#{ filename ? " - missing both #{filename} and config.ru" : " - missing config.ru"}."
if Iodine::DEFAULT_SETTINGS[:public]
puts " Running only static file service."
opt = Hash.new
app = Proc.new { [404, {}, "Not Found!"] }
else
puts "\nERROR: Couldn't run Ruby application, check command line arguments."
Expand Down
4 changes: 2 additions & 2 deletions ext/iodine/iodine_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ static int for_each_header_data(VALUE key, VALUE val, VALUE h_) {
if (TYPE(val) == T_NIL)
return ST_CONTINUE;
if (TYPE(val) == T_ARRAY)
goto rack3_style_multi_value;
goto array_style_multi_value;
if (TYPE(key) != T_STRING)
key = IodineCaller.call(key, iodine_to_s_id);
if (TYPE(key) != T_STRING)
Expand Down Expand Up @@ -520,7 +520,7 @@ static int for_each_header_data(VALUE key, VALUE val, VALUE h_) {
// no errors, return 0
return ST_CONTINUE;

rack3_style_multi_value:
array_style_multi_value:
for (size_t i = 0, end = RARRAY_LEN(val); i < end; ++i) {
if (for_each_header_data(key, RARRAY_AREF(val, i), h_) == ST_CONTINUE)
continue;
Expand Down
2 changes: 1 addition & 1 deletion lib/rack/handler/iodine.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'iodine' unless defined?(::Iodine::VERSION)

module Iodine
# Iodine's {Iodine::Rack} module provides a Rack complient interface (connecting Iodine to Rack) for an HTTP and Websocket Server.
# Iodine's {Iodine::Rack} module provides a Rack compliant interface (connecting Iodine to Rack) for an HTTP and Websocket Server.
module Rack

# Runs a Rack app, as par the Rack handler requirements.
Expand Down

0 comments on commit 35e1a61

Please sign in to comment.