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 return unless response 37 38 return response unless response.is_a?(Response) 39 40 return response unless response.headers.key?("upgrade") 41 42 upgrade_protocol = response.headers["upgrade"].split(/ *, */).first 43 44 return response unless upgrade_protocol && options.upgrade_handlers.key?(upgrade_protocol) 45 46 protocol_handler = options.upgrade_handlers[upgrade_protocol] 47 48 return response unless protocol_handler 49 50 log { "upgrading to #{upgrade_protocol}..." } 51 connection = find_connection(request.uri, selector, options) 52 53 # do not upgrade already upgraded connections 54 return if connection.upgrade_protocol == upgrade_protocol 55 56 protocol_handler.call(connection, request, response) 57 58 # keep in the loop if the server is switching, unless 59 # the connection has been hijacked, in which case you want 60 # to terminante immediately 61 return fetch_response(request, selector, options) if response.status == 101 && !connection.hijacked 62 63 response 64 end