Public Instance methods
fetch_response(request, selector, options)
[show source]
# File lib/httpx/plugins/upgrade.rb 31 def fetch_response(request, selector, options) 32 response = super 33 34 if response 35 return response unless response.is_a?(Response) 36 37 return response unless response.headers.key?("upgrade") 38 39 upgrade_protocol = response.headers["upgrade"].split(/ *, */).first 40 41 return response unless upgrade_protocol && options.upgrade_handlers.key?(upgrade_protocol) 42 43 protocol_handler = options.upgrade_handlers[upgrade_protocol] 44 45 return response unless protocol_handler 46 47 log { "upgrading to #{upgrade_protocol}..." } 48 connection = find_connection(request.uri, selector, options) 49 50 # do not upgrade already upgraded connections 51 return if connection.upgrade_protocol == upgrade_protocol 52 53 protocol_handler.call(connection, request, response) 54 55 # keep in the loop if the server is switching, unless 56 # the connection has been hijacked, in which case you want 57 # to terminante immediately 58 return if response.status == 101 && !connection.hijacked 59 end 60 61 response 62 end