Ruby 1.9.0 compability

23 views
Skip to first unread message

Sho Fukamachi

unread,
Jun 7, 2008, 6:28:45 AM6/7/08
to Rack Development
Hi all,

I've been playing around trying to get Rack to work under Ruby 1.9.0,
without much success. Is it supported (which would mean I'm doing
something horribly wrong) or is it not in there yet?

The gem installs into 1.9.0 fine, but when I try to run anything it
blows up in multiple places, same with trunk. Any advice? Anyone else
been testing on 1.9?

thanks very much!

Sho

Michael Fellinger

unread,
Jun 7, 2008, 7:14:31 AM6/7/08
to rack-...@googlegroups.com

This is strange, I've been using (and adapting) Rack for 1.9 and it
runs fine under just about all other ruby implementations as well. Can
you give us more specifics on the errors you encounter?
Some sample code and the backtraces, also the exact ruby version.

^ manveru

> thanks very much!
>
> Sho

Sho Fukamachi

unread,
Jun 7, 2008, 7:54:35 AM6/7/08
to Rack Development
Hm, I'm glad to know it's something I'm doing wrong. Well, kind of!

The Ruby I'm using is straight from trunk, 06-06-2008, rev 16866. On a
fresh clone of Rack from http://github.com/chneukirchen/rack/tree/master
I'm simply going to the Rack directory and executing

ruby9 -Ilib lib/rack/lobster.rb (ruby9 is an alias to my Ruby 1.9
install)

It looks like it's working fine:

2008-06-07 21:49:22] INFO WEBrick 1.3.1
[2008-06-07 21:49:22] INFO ruby 1.9.0 (2008-06-06) [i686-darwin9.3.0]
[2008-06-07 21:49:22] INFO WEBrick::HTTPServer#start: pid=24904
port=9292

But then as soon as I try to load, boom. I've pasted the output after
this mail.

The output in the browser is:

Internal Server Error

undefined method `each' for "text/html":String
WEBrick/1.3.1 (Ruby/1.9.0/2008-06-06) at 0.0.0.0:9292

I've tried other things too, but this is the simplest one. And it
works perfectly in 1.8.6. Any ideas? I am probably doing something
really dumb...

Thanks for your help,

Sho

(Error output)

Rack::Lint::LintError: header values must respond to #each
/Users/sho/projects/sources/rack/lib/rack/lint.rb:16:in `assert'
/Users/sho/projects/sources/rack/lib/rack/lint.rb:328:in `block in
check_headers'
/Users/sho/projects/sources/rack/lib/rack/lint.rb:312:in `each'
/Users/sho/projects/sources/rack/lib/rack/lint.rb:312:in
`check_headers'
/Users/sho/projects/sources/rack/lib/rack/lint.rb:45:in `call'
/Users/sho/projects/sources/rack/lib/rack/showexceptions.rb:23:in
`call'
/Users/sho/projects/sources/rack/lib/rack/handler/webrick.rb:40:in
`service'
/usr/local/ruby1.9/lib/ruby/1.9.0/webrick/httpserver.rb:111:in
`service'
/usr/local/ruby1.9/lib/ruby/1.9.0/webrick/httpserver.rb:70:in `run'
/usr/local/ruby1.9/lib/ruby/1.9.0/webrick/server.rb:175:in `block in
start_thread'
[2008-06-07 21:51:17] ERROR NoMethodError: undefined method `each' for
"text/html":String
/Users/sho/projects/sources/rack/lib/rack/handler/webrick.rb:44:in
`block in service'
/Users/sho/projects/sources/rack/lib/rack/handler/webrick.rb:43:in
`each'
/Users/sho/projects/sources/rack/lib/rack/handler/webrick.rb:43:in
`service'
/usr/local/ruby1.9/lib/ruby/1.9.0/webrick/httpserver.rb:111:in
`service'
/usr/local/ruby1.9/lib/ruby/1.9.0/webrick/httpserver.rb:70:in `run'
/usr/local/ruby1.9/lib/ruby/1.9.0/webrick/server.rb:175:in `block in
start_thread'
localhost - - [07/Jun/2008:21:51:17 EST] "GET / HTTP/1.1" 500 334
- -> /
Rack::Lint::LintError: header values must respond to #each
/Users/sho/projects/sources/rack/lib/rack/lint.rb:16:in `assert'
/Users/sho/projects/sources/rack/lib/rack/lint.rb:328:in `block in
check_headers'
/Users/sho/projects/sources/rack/lib/rack/lint.rb:312:in `each'
/Users/sho/projects/sources/rack/lib/rack/lint.rb:312:in
`check_headers'
/Users/sho/projects/sources/rack/lib/rack/lint.rb:45:in `call'
/Users/sho/projects/sources/rack/lib/rack/showexceptions.rb:23:in
`call'
/Users/sho/projects/sources/rack/lib/rack/handler/webrick.rb:40:in
`service'
/usr/local/ruby1.9/lib/ruby/1.9.0/webrick/httpserver.rb:111:in
`service'
/usr/local/ruby1.9/lib/ruby/1.9.0/webrick/httpserver.rb:70:in `run'
/usr/local/ruby1.9/lib/ruby/1.9.0/webrick/server.rb:175:in `block in
start_thread'
[2008-06-07 21:51:17] ERROR NoMethodError: undefined method `each' for
"text/html":String
/Users/sho/projects/sources/rack/lib/rack/handler/webrick.rb:44:in
`block in service'
/Users/sho/projects/sources/rack/lib/rack/handler/webrick.rb:43:in
`each'
/Users/sho/projects/sources/rack/lib/rack/handler/webrick.rb:43:in
`service'
/usr/local/ruby1.9/lib/ruby/1.9.0/webrick/httpserver.rb:111:in
`service'
/usr/local/ruby1.9/lib/ruby/1.9.0/webrick/httpserver.rb:70:in `run'
/usr/local/ruby1.9/lib/ruby/1.9.0/webrick/server.rb:175:in `block in
start_thread'
localhost - - [07/Jun/2008:21:51:17 EST] "GET /favicon.ico HTTP/1.1"
500 334
http://0.0.0.0:9292/ -> /favicon.ico




On Jun 7, 9:14 pm, "Michael Fellinger" <m.fellin...@gmail.com> wrote:

Christian Neukirchen

unread,
Jun 7, 2008, 12:25:28 PM6/7/08
to rack-...@googlegroups.com
Sho Fukamachi <sho.fu...@gmail.com> writes:

> Rack::Lint::LintError: header values must respond to #each

There is no String#each in 1.9 anymore. This affects Rack in two cases:

1) Header values were iterated for multiple headers (usually only
required for cookies)
I propose require them to be strings and split them on newline.

2) The body could be a String.
Instead, use [string] as a body.

Please comment, this is a backwards incompatible Rack specification change
(which should not break any sane application, though).
--
Christian Neukirchen <chneuk...@gmail.com> http://chneukirchen.org

Sho Fukamachi

unread,
Jun 7, 2008, 1:04:07 PM6/7/08
to Rack Development
Hi Christian,

those changes sound good!

My quick and dirty fix for the problem I was having above is attached,
although I didn't touch anything in Body, and I don't expect it to be
up to standard - but it gets the lobster example running in 1.9.0 :)

Sho

$ git diff
diff --git a/lib/rack/handler/webrick.rb b/lib/rack/handler/webrick.rb
index c3222fd..7b4a6b8 100644
--- a/lib/rack/handler/webrick.rb
+++ b/lib/rack/handler/webrick.rb
@@ -40,8 +40,8 @@ module Rack
status, headers, body = @app.call(env)
begin
res.status = status.to_i
- headers.each { |k, vs|
- vs.each { |v|
+ headers.each_pair { |k, vs|
+ vs.each_line { |v|
res[k] = v
}
}
diff --git a/lib/rack/lint.rb b/lib/rack/lint.rb
index b5232e0..c7d9ddd 100644
--- a/lib/rack/lint.rb
+++ b/lib/rack/lint.rb
@@ -325,8 +325,8 @@ module Rack
assert("invalid header name: #{key}") { key =~ /\A[a-zA-Z][a-
zA-Z0-9_-]*\z/ }
##
## The values of the header must respond to #each_line.
- assert("header values must respond to #each")
{ value.respond_to? :each }
- value.each { |item|
+ assert("header values must respond to #each_line")
{ value.respond_to? :each_line }
+ value.each_line { |item|
## The values passed on #each must be Strings
assert("header values must consist of Strings") {
item.instance_of?(String)


On Jun 8, 2:25 am, Christian Neukirchen <chneukirc...@gmail.com>
wrote:
> Christian Neukirchen  <chneukirc...@gmail.com>  http://chneukirchen.org

Christian Neukirchen

unread,
Jun 7, 2008, 1:51:57 PM6/7/08
to rack-...@googlegroups.com
Sho Fukamachi <sho.fu...@gmail.com> writes:

> Hi Christian,
>
> those changes sound good!
>
> My quick and dirty fix for the problem I was having above is attached,
> although I didn't touch anything in Body, and I don't expect it to be
> up to standard - but it gets the lobster example running in 1.9.0 :)
>
> Sho

each_line is good, but I'll keep the #each for the fields themselves.

Reply all
Reply to author
Forward
0 new messages