mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-08-10 00:01:27 -04:00
added parsing and handling of the alt-svc header/frame, and emitting it as a parser event
This commit is contained in:
parent
bcd4cd5e5c
commit
a1f9f97b2d
@ -126,6 +126,20 @@ module HTTPX
|
||||
response << @parser.upgrade_data
|
||||
throw(:called)
|
||||
end
|
||||
|
||||
# Alt-Svc
|
||||
if response.headers.key?("alt-svc")
|
||||
origin = request.authority
|
||||
alt_uri, *params = response.headers["alt-svc"].split(/ *; */)
|
||||
alt_proto, alt_uri = alt_uri.split("=")
|
||||
alt_uri = alt_uri[1..-2] if alt_uri.start_with?("\"") && alt_uri.end_with?("\"")
|
||||
alt_uri = URI.parse("#{alt_proto}://#{alt_uri}")
|
||||
alt_uri.host ||= request.authority
|
||||
params = Hash[params.split(/ *, */).map { |field| field.split("=") }]
|
||||
log(level: 1) { "#{origin} alt-svc: #{alt_uri}" }
|
||||
emit(:alternative_service, alt_uri, origin, params)
|
||||
end
|
||||
|
||||
reset
|
||||
send(@pending.shift) unless @pending.empty?
|
||||
return unless response.headers["connection"] == "close"
|
||||
|
@ -105,7 +105,7 @@ module HTTPX
|
||||
stream.on(:half_close) do
|
||||
log(level: 2, label: "#{stream.id}: ") { "waiting for response..." }
|
||||
end
|
||||
# stream.on(:altsvc)
|
||||
stream.on(:altsvc, &method(:on_altsvc).curry[request.authority])
|
||||
stream.on(:headers, &method(:on_stream_headers).curry[stream, request])
|
||||
stream.on(:data, &method(:on_stream_data).curry[stream, request])
|
||||
end
|
||||
@ -225,9 +225,17 @@ module HTTPX
|
||||
end
|
||||
end
|
||||
|
||||
def on_altsvc(frame)
|
||||
def on_altsvc(origin, frame)
|
||||
log(level: 2, label: "#{frame[:stream]}: ") { "altsvc frame was received" }
|
||||
log(level: 2, label: "#{frame[:stream]}: ") { frame.inspect }
|
||||
origin ||= frame[:origin]
|
||||
alt_proto = frame[:proto]
|
||||
alt_host = frame[:host]
|
||||
alt_port = frame[:port]
|
||||
alt_uri = URI.parse("#{alt_proto}://#{alt_host}:#{alt_port}")
|
||||
log(level: 1, label: "#{frame[:stream]} ") { "#{origin} alt-svc: #{alt_uri}" }
|
||||
params = { "ma" => frame[:max_age] }
|
||||
emit(:alternate_service, alt_uri, origin, params)
|
||||
end
|
||||
|
||||
def on_promise(stream)
|
||||
|
Loading…
x
Reference in New Issue
Block a user