Skip to content
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

Move the host request parsing to a separate method. #85

Merged
merged 2 commits into from
Jan 26, 2023
Merged
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
8 changes: 6 additions & 2 deletions lib/webrick/httprequest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,7 @@ def parse_uri(str, scheme="http")
if @forwarded_host
host, port = @forwarded_host, @forwarded_port
elsif self["host"]
pattern = /\A(#{URI::REGEXP::PATTERN::HOST})(?::(\d+))?\z/n
host, port = *self['host'].scan(pattern)[0]
host, port = parse_host_request_line(self["host"])
elsif @addr.size > 0
host, port = @addr[2], @addr[1]
else
Expand All @@ -504,6 +503,11 @@ def parse_uri(str, scheme="http")
return URI::parse(uri.to_s)
end

def parse_host_request_line(host)
pattern = /\A(#{URI::REGEXP::PATTERN::HOST})(?::(\d+))?\z/no
host.scan(pattern)[0]
end

def read_body(socket, block)
return unless socket
if tc = self['transfer-encoding']
Expand Down