mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/uri] Feat: Support WSS
There was a file for WSS so I added one line of `require_relative` to make it work. Now `URI.parse('wss://example.com')` returns `URI::WS`. https://github.com/ruby/uri/commit/ff8a103564
This commit is contained in:
parent
d1b9609cba
commit
c94f964e3f
3 changed files with 75 additions and 3 deletions
|
@ -101,3 +101,4 @@ require_relative 'uri/ldap'
|
|||
require_relative 'uri/ldaps'
|
||||
require_relative 'uri/mailto'
|
||||
require_relative 'uri/ws'
|
||||
require_relative 'uri/wss'
|
||||
|
|
|
@ -42,17 +42,17 @@ class TestCommon < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_register_scheme
|
||||
assert_equal(["FILE", "FTP", "HTTP", "HTTPS", "LDAP", "LDAPS", "MAILTO", "WS"].sort, URI.scheme_list.keys.sort)
|
||||
assert_equal(["FILE", "FTP", "HTTP", "HTTPS", "LDAP", "LDAPS", "MAILTO", "WS", "WSS"].sort, URI.scheme_list.keys.sort)
|
||||
|
||||
foobar = Class.new(URI::Generic)
|
||||
URI.register_scheme 'FOOBAR', foobar
|
||||
begin
|
||||
assert_equal(["FILE", "FTP", "HTTP", "HTTPS", "LDAP", "LDAPS", "MAILTO", "WS", "FOOBAR"].sort, URI.scheme_list.keys.sort)
|
||||
assert_equal(["FILE", "FTP", "HTTP", "HTTPS", "LDAP", "LDAPS", "MAILTO", "WS", "WSS", "FOOBAR"].sort, URI.scheme_list.keys.sort)
|
||||
ensure
|
||||
URI.const_get(:Schemes).send(:remove_const, :FOOBAR)
|
||||
end
|
||||
|
||||
assert_equal(["FILE", "FTP", "HTTP", "HTTPS", "LDAP", "LDAPS", "MAILTO", "WS"].sort, URI.scheme_list.keys.sort)
|
||||
assert_equal(["FILE", "FTP", "HTTP", "HTTPS", "LDAP", "LDAPS", "MAILTO", "WS", "WSS"].sort, URI.scheme_list.keys.sort)
|
||||
end
|
||||
|
||||
def test_regexp
|
||||
|
|
71
test/uri/test_wss.rb
Normal file
71
test/uri/test_wss.rb
Normal file
|
@ -0,0 +1,71 @@
|
|||
# frozen_string_literal: false
|
||||
require 'test/unit'
|
||||
require 'uri/http'
|
||||
require 'uri/wss'
|
||||
|
||||
module URI
|
||||
|
||||
|
||||
class TestWSS < Test::Unit::TestCase
|
||||
def setup
|
||||
end
|
||||
|
||||
def teardown
|
||||
end
|
||||
|
||||
def uri_to_ary(uri)
|
||||
uri.class.component.collect {|c| uri.send(c)}
|
||||
end
|
||||
|
||||
def test_build
|
||||
u = URI::WSS.build(host: 'www.example.com', path: '/foo/bar')
|
||||
assert_kind_of(URI::WSS, u)
|
||||
end
|
||||
|
||||
def test_parse
|
||||
u = URI.parse('wss://a')
|
||||
assert_kind_of(URI::WSS, u)
|
||||
assert_equal(['wss',
|
||||
nil, 'a', URI::HTTPS.default_port,
|
||||
'', nil], uri_to_ary(u))
|
||||
end
|
||||
|
||||
def test_normalize
|
||||
host = 'aBcD'
|
||||
u1 = URI.parse('wss://' + host + '/eFg?HiJ')
|
||||
u2 = URI.parse('wss://' + host.downcase + '/eFg?HiJ')
|
||||
assert(u1.normalize.host == 'abcd')
|
||||
assert(u1.normalize.path == u1.path)
|
||||
assert(u1.normalize == u2.normalize)
|
||||
assert(!u1.normalize.host.equal?(u1.host))
|
||||
assert( u2.normalize.host.equal?(u2.host))
|
||||
|
||||
assert_equal('wss://abc/', URI.parse('wss://abc').normalize.to_s)
|
||||
end
|
||||
|
||||
def test_equal
|
||||
assert(URI.parse('wss://abc') == URI.parse('wss://ABC'))
|
||||
assert(URI.parse('wss://abc/def') == URI.parse('wss://ABC/def'))
|
||||
assert(URI.parse('wss://abc/def') != URI.parse('wss://ABC/DEF'))
|
||||
end
|
||||
|
||||
def test_request_uri
|
||||
assert_equal('/', URI.parse('wss://a.b.c/').request_uri)
|
||||
assert_equal('/?abc=def', URI.parse('wss://a.b.c/?abc=def').request_uri)
|
||||
assert_equal('/', URI.parse('wss://a.b.c').request_uri)
|
||||
assert_equal('/?abc=def', URI.parse('wss://a.b.c?abc=def').request_uri)
|
||||
assert_equal(nil, URI.parse('wss:foo').request_uri)
|
||||
end
|
||||
|
||||
def test_select
|
||||
assert_equal(['wss', 'a.b.c', 443], URI.parse('wss://a.b.c/').select(:scheme, :host, :port))
|
||||
u = URI.parse('wss://a.b.c/')
|
||||
assert_equal(uri_to_ary(u), u.select(*u.component))
|
||||
assert_raise(ArgumentError) do
|
||||
u.select(:scheme, :host, :not_exist, :port)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
Loading…
Add table
Reference in a new issue