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