8000 Fix HTTP/0.9 requests in WEBrick · Pull Request #33 · ruby/ruby · GitHub
[go: up one dir, main page]

Skip to content

Fix HTTP/0.9 requests in WEBrick #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix HTTP/0.9 requests in WEBrick
Fixes HTTP/0.9 requests in WEBrick's httprequest. Calling meta_vars woul
d raise an exception where the @Header variable is not set (as would be
the case for an HTTP/0.9 simple request), but meta_vars should be availa
ble for any request. This is my patch from the thread at http://redmine.
ruby-lang.org/issues/5022 .
  • Loading branch information
Felix committed Jul 17, 2011
commit 14134dc8b9ffd6ab048ad1f99b4e6e94400b14ab
10 changes: 6 additions & 4 deletions lib/webrick/httprequest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,12 @@ def [](header_name)
# Iterates over the request headers

def each
@header.each{|k, v|
value = @header[k]
yield(k, value.empty? ? nil : value.join(", "))
}
unless @header.nil? then
@header.each{|k, v|
value = @header[k]
yield(k, value.empty? ? nil : value.join(", "))
}
end
end

##
Expand Down
12 changes: 12 additions & 0 deletions test/webrick/test_httprequest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
require "test/unit"

class TestWEBrickHTTPRequest < Test::Unit::TestCase
def test_simple_request
msg = <<-_end_of_message_
GET /
_end_of_message_

req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
req.parse(StringIO.new(msg.gsub(/^ {6}/, '')))

# assertion fails if @header was not initialized and iteration is attempted on the nil reference
assert_nothing_raised('req.meta_vars should be available with HTTP/0.9 simple request') { req.meta_vars }
end

def test_parse_09
msg = <<-_end_of_message_
GET /
Expand Down
0