Module: TingYun::Agent::HTTPClients::URIUtil
- Defined in:
- lib/ting_yun/support/http_clients/uri_util.rb
Constant Summary collapse
- QUESTION_MARK =
"?".freeze
Class Method Summary collapse
- .filter_uri(original) ⇒ Object
-
.parse_and_normalize_url(url) ⇒ Object
There are valid URI strings that some HTTP client libraries will accept that the stdlib URI module doesn’t handle.
- .strip_query_string(fragment) ⇒ Object
Class Method Details
.filter_uri(original) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/ting_yun/support/http_clients/uri_util.rb', line 15 def self.filter_uri(original) filtered = original.dup filtered.user = nil filtered.password = nil filtered.query = nil filtered.fragment = nil filtered.to_s end |
.parse_and_normalize_url(url) ⇒ Object
There are valid URI strings that some HTTP client libraries will accept that the stdlib URI module doesn’t handle. If we find that Addressable is around, use that to normalize out our URL’s.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ting_yun/support/http_clients/uri_util.rb', line 27 def self.parse_and_normalize_url(url) uri = url unless ::URI === uri if defined?(::Addressable::URI) address = ::Addressable::URI.parse(url) address.normalize! uri = ::URI.parse(address.to_s) else uri = ::URI.parse(url) end end uri.host.downcase! unless uri.host.nil? uri end |
.strip_query_string(fragment) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/ting_yun/support/http_clients/uri_util.rb', line 44 def self.strip_query_string(fragment) if(fragment.include?(QUESTION_MARK)) fragment.split(QUESTION_MARK).first else fragment end end |