31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/httpx/plugins/upgrade.rb', line 31
def fetch_response(request, selector, options)
response = super
if response
return response unless response.is_a?(Response)
return response unless response..key?("upgrade")
upgrade_protocol = response.["upgrade"].split(/ *, */).first
return response unless upgrade_protocol && options.upgrade_handlers.key?(upgrade_protocol)
protocol_handler = options.upgrade_handlers[upgrade_protocol]
return response unless protocol_handler
log { "upgrading to #{upgrade_protocol}..." }
connection = find_connection(request.uri, selector, options)
return if connection.upgrade_protocol == upgrade_protocol
protocol_handler.call(connection, request, response)
return if response.status == 101 && !connection.hijacked
end
response
end
|