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

Conversation

wishdev
Copy link
Contributor

@wishdev wishdev commented Jan 16, 2022

Allows for someone to override the parsing to accommodate "alternatives".
One could write the following to allow underscores in host names.

require 'webrick/httprequest'

module WEBrick
  class HTTPRequest
    private

    def parse_host_request_line(host)
      uri = URI.parse("scheme://#{host}")
      [uri.host, uri.port]
    end
  end
end

Also adding the "o" option to the regex so the regex is only built once.``

Allows for someone to override the parsing to accommodate "alternatives".
One could write the following to allow underscores in host names.

require 'webrick/httprequest'

module WEBrick
  class HTTPRequest
    private

    def parse_host_request_line(host, scheme)
      uri = URI.parse("#{scheme}://#{host}")
      [uri.host, uri.port]
    end
  end
end

Also adding the "o" option to the regex so the regex is only built once.
Copy link
Contributor

@jeremyevans jeremyevans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, other than one line being moved (maybe there is a reason for that?).

@@ -488,22 +488,26 @@ def parse_uri(str, scheme="http")
str.sub!(%r{\A/+}o, '/')
uri = URI::parse(str)
return uri if uri.absolute?
uri.scheme = @forwarded_proto || scheme
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this line was moved?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need the scheme to use URI.parse in my universe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore that - not needed - will fix

@ioquatix ioquatix merged commit e457003 into ruby:master Jan 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants