Thanks to visit codestin.com
Credit goes to github.com

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
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