lib/httpx/altsvc.rb in httpx-0.7.0 vs lib/httpx/altsvc.rb in httpx-0.8.0
- old
+ new
@@ -40,11 +40,27 @@
# Alt-Svc
return unless response.headers.key?("alt-svc")
origin = request.origin
host = request.uri.host
- parse(response.headers["alt-svc"]) do |alt_origin, alt_params|
+
+ altsvc = response.headers["alt-svc"]
+
+ # https://tools.ietf.org/html/rfc7838#section-3
+ # A field value containing the special value "clear" indicates that the
+ # origin requests all alternatives for that origin to be invalidated
+ # (including those specified in the same response, in case of an
+ # invalid reply containing both "clear" and alternative services).
+ if altsvc == "clear"
+ @altsvc_mutex.synchronize do
+ @altsvcs[origin].clear
+ end
+
+ return
+ end
+
+ parse(altsvc) do |alt_origin, alt_params|
alt_origin.host ||= host
yield(alt_origin, origin, alt_params)
end
end
@@ -71,10 +87,10 @@
if RUBY_VERSION < "2.2"
def parse_altsvc_origin(alt_origin)
alt_proto, alt_origin = alt_origin.split("=")
alt_origin = alt_origin[1..-2] if alt_origin.start_with?("\"") && alt_origin.end_with?("\"")
if alt_origin.start_with?(":")
- alt_origin = "dummy#{alt_origin}"
+ alt_origin = "#{alt_proto}://dummy#{alt_origin}"
uri = URI.parse(alt_origin)
uri.host = nil
uri
else
URI.parse("#{alt_proto}://#{alt_origin}")