mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-07 00:05:02 -04:00
The reference for a request verb is now the string which is used everywhere else, instead of the symbol corresponding to it. This was an artifact from the import from httprb, and there is no advantage in it, since these strings are frozen in most use cases, and the transformations from symbol to strings being performed everywhere are prooof that keeping the atom isn't really bringing any benefit.
68 lines
2.4 KiB
Ruby
68 lines
2.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require_relative "test_helper"
|
|
|
|
class AltSvcTest < Minitest::Test
|
|
include HTTPX
|
|
|
|
def test_altsvc_cache
|
|
assert AltSvc.cached_altsvc("http://www.example-altsvc-cache.com").empty?
|
|
AltSvc.cached_altsvc_set("http://www.example-altsvc-cache.com", { "origin" => "http://alt.example-altsvc-cache.com", "ma" => 2 })
|
|
entries = AltSvc.cached_altsvc("http://www.example-altsvc-cache.com")
|
|
assert !entries.empty?
|
|
entry = entries.first
|
|
assert entry["origin"] == "http://alt.example-altsvc-cache.com"
|
|
sleep 3
|
|
assert AltSvc.cached_altsvc("http://www.example-altsvc-cache.com").empty?
|
|
end
|
|
|
|
def test_altsvc_parse_svc
|
|
assert [["h2=alt.example.com", {}]], AltSvc.parse("h2=alt.example.com").to_a
|
|
end
|
|
|
|
def test_altsvc_parse_svc_with_port
|
|
assert [["h2=alt.example.com:8000", {}]], AltSvc.parse("h2=\"alt.example.com:8000\"").to_a
|
|
end
|
|
|
|
def test_altsvc_parse_svcs
|
|
assert [["h2=alt.example.com:8000", {}], ["h2=:8000", {}]],
|
|
AltSvc.parse("h2=\"alt.example.com:8000\", h2=\":443\"").to_a
|
|
end
|
|
|
|
def test_altsvc_parse_svc_prop
|
|
assert [["h2=alt.example.com:8000'", { "ma" => "60" }]],
|
|
AltSvc.parse("h2=\"alt.example.com:8000\"; ma=60").to_a
|
|
end
|
|
|
|
def test_altsvc_parse_svc_props
|
|
assert [["h2=alt.example.com:8000", { "persist" => "1" }]],
|
|
AltSvc.parse("h2=\"alt.example.com:8000\"; ma=60; persist=1").to_a
|
|
end
|
|
|
|
def test_altsvc_parse_svc_with_versions
|
|
assert [["quic=:443", { "ma" => "2592000", "v" => "46,43,39" }]],
|
|
AltSvc.parse("quic=\":443\"; ma=2592000; v=\"46,43,39\"").to_a
|
|
end
|
|
|
|
def test_altsvc_parse_svcs_with_props
|
|
assert [["quic=:443", { "ma" => "2592000", "v" => "46,43" }],
|
|
["h3-Q046=:443", { "ma" => "2592000" }],
|
|
["h3-Q043=:443", { "ma" => "2592000" }]],
|
|
AltSvc.parse("quic=\":443\"; ma=2592000; v=\"46,43\",h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000").to_a
|
|
end
|
|
|
|
def test_altsvc_clear_cache
|
|
AltSvc.cached_altsvc_set("http://www.example-clear-cache.com", { "origin" => "http://alt.example-clear-cache.com", "ma" => 2 })
|
|
entries = AltSvc.cached_altsvc("http://www.example-clear-cache.com")
|
|
assert !entries.empty?
|
|
|
|
req = Request.new("GET", "http://www.example-clear-cache.com/")
|
|
res = Response.new(req, 200, "2.0", { "alt-svc" => "clear" })
|
|
|
|
AltSvc.emit(req, res)
|
|
|
|
entries = AltSvc.cached_altsvc("http://www.example-clear-cache.com")
|
|
assert entries.empty?
|
|
end
|
|
end
|