How to use normalized_headers method of Excon Package

Best Vcr_ruby code snippet using Excon.normalized_headers

excon.rb

Source:excon.rb Github

copy

Full Screen

...21 def on_stubbed_request22 @vcr_response = stubbed_response23 {24 :body => stubbed_response.body,25 :headers => normalized_headers(stubbed_response.headers || {}),26 :status => stubbed_response.status.code27 }28 end29 def on_ignored_request30 perform_real_request31 end32 def response_from_excon_error(error)33 if error.respond_to?(:response)34 error.response35 elsif error.respond_to?(:socket_error)36 response_from_excon_error(error.socket_error)37 else38 warn "WARNING: VCR could not extract a response from Excon error (#{error.inspect})"39 end40 end41 def real_request_params42 # Excon supports a variety of options that affect how it handles failure43 # and retry; we don't want to use any options here--we just want to get44 # a raw response, and then the main request (with :mock => true) can45 # handle failure/retry on its own with its set options.46 params.merge(:mock => false, :retry_limit => 0).tap do |p|47 [:expects, :idempotent, :instrumentor_name, :instrumentor].each do |key|48 p.delete(key)49 end50 end51 end52 def perform_real_request53 begin54 response = ::Excon.new(uri).request(real_request_params)55 rescue ::Excon::Errors::Error => excon_error56 response = response_from_excon_error(excon_error)57 end58 @vcr_response = vcr_response_from(response)59 yield response if block_given?60 raise excon_error if excon_error61 response.attributes62 end63 def on_recordable_request64 perform_real_request do |response|65 http_interaction = http_interaction_for(response)66 VCR.record_http_interaction(http_interaction)67 end68 end69 def uri70 @uri ||= "#{params[:scheme]}://#{params[:host]}:#{params[:port]}#{params[:path]}#{query}"71 end72 # based on:73 # https://github.com/geemus/excon/blob/v0.7.8/lib/excon/connection.rb#L117-13274 def query75 @query ||= case params[:query]76 when String77 "?#{params[:query]}"78 when Hash79 qry = '?'80 for key, values in params[:query]81 if values.nil?82 qry << key.to_s << '&'83 else84 for value in [*values]85 qry << key.to_s << '=' << CGI.escape(value.to_s) << '&'86 end87 end88 end89 qry.chop! # remove trailing '&'90 else91 ''92 end93 end94 def http_interaction_for(response)95 VCR::HTTPInteraction.new \96 vcr_request,97 vcr_response_from(response)98 end99 def vcr_request100 @vcr_request ||= begin101 headers = params[:headers].dup102 headers.delete("Host")103 VCR::Request.new \104 params[:method],105 uri,106 params[:body],107 headers108 end109 end110 def vcr_response_from(response)111 VCR::Response.new \112 VCR::ResponseStatus.new(response.status, nil),113 response.headers,114 response.body,115 nil116 end117 def normalized_headers(headers)118 normalized = {}119 headers.each do |k, v|120 v = v.join(', ') if v.respond_to?(:join)121 normalized[k] = v122 end123 normalized124 end125 ::Excon.stub({}) do |params|126 self.new(params).handle127 end128 end129 end130 end131end...

Full Screen

Full Screen

excon_wrappers.rb

Source:excon_wrappers.rb Github

copy

Full Screen

...6 def initialize(response)7 @response = response8 # Since HTTP headers are case-insensitive, we normalize all of them to9 # upper case here, and then also in our [](key) implementation.10 @normalized_headers = {}11 headers = response.respond_to?(:headers) ? response.headers : response[:headers]12 (headers || {}).each do |key, val|13 @normalized_headers[key.upcase] = val14 end15 end16 def [](key)17 @normalized_headers[key.upcase]18 end19 def to_hash20 @normalized_headers.dup21 end22 end23 class ExconHTTPRequest < AbstractRequest24 attr_reader :method25 EXCON = "Excon".freeze26 LHOST = 'host'.freeze27 UHOST = 'Host'.freeze28 COLON = ':'.freeze29 def initialize(datum)30 @datum = datum31 @method = @datum[:method].to_s.upcase32 @scheme = @datum[:scheme]33 @port = @datum[:port]34 @path = @datum[:path]...

Full Screen

Full Screen

normalized_headers

Using AI Code Generation

copy

Full Screen

1Excon::Connection.new('http://www.google.com').request(:method => :get)2Excon::Response.new(:headers => { 'content-type' => 'text/html' })3Excon::Response.new(:headers => { 'content-type' => 'text/html' }).normalized_headers4Excon::Response.new(:headers => { 'content-type' => 'text/html' }).normalized_headers['Content-Type']5Excon::Response.new(:headers => { 'content-type' => 'text/html' }).normalized_headers['content-type']6Excon::Response.new(:headers => { 'content-type' => 'text/html' }).normalized_headers['CONTENT-TYPE']7Excon::Response.new(:headers => { 'content-type' => 'text/html' }).normalized_headers['CONTENT-type']8Excon::Response.new(:headers => { 'content-type' => 'text/html' }).normalized_headers['CONTENT']9Excon::Response.new(:headers => { 'content-type' => 'text/html' }).normalized_headers['content']10Excon::Response.new(:headers => { 'content-type' => 'text/html' }).normalized_headers['Content']

Full Screen

Full Screen

normalized_headers

Using AI Code Generation

copy

Full Screen

1Excon.defaults[:headers] = { 'X-Test' => 'test' }2connection = Excon.new('http://localhost:3000')3connection.request(:method => :get, :path => '/')4Excon.defaults[:headers] = { 'X-Test' => 'test' }5connection = Excon.new('http://localhost:3000')6connection.normalize_headers(connection.headers)

Full Screen

Full Screen

normalized_headers

Using AI Code Generation

copy

Full Screen

1Excon::Connection.new('http://example.com').request(:method => :get)2Excon.new('http://example.com').request(:method => :get)3Excon::Connection.new('http://example.com').request(:method => :get)4Excon.new('http://example.com').request(:method => :get)5Excon::Connection.new('http://example.com').request(:method => :get)6Excon.new('http://example.com').request(:method => :get)7Excon::Connection.new('http://example.com').request(:method => :get)8Excon.new('http://example.com').request(:method => :get)9Excon::Connection.new('http://example.com').request(:method => :get)10Excon.new('http://example.com').request(:method => :get)11Excon::Connection.new('http://example.com').request(:method => :get)12Excon.new('http://example.com').request(:method => :get)13Excon::Connection.new('http://example.com').request(:method => :get)

Full Screen

Full Screen

normalized_headers

Using AI Code Generation

copy

Full Screen

1puts Excon.normalized_headers('content-type' => 'text/plain')2response = Excon.get('http://google.com', :response_block => Proc.new {})3response = Excon.get('http://google.com', :response_block => Proc.new {})4response = Excon.get('http://google.com', :response_block => Proc.new {})5response = Excon.get('http://google.com', :response_block => Proc.new {})6response = Excon.get('http://google.com', :response_block => Proc.new {})7response = Excon.get('http://google.com', :response_block => Proc.new {})8puts response.data[:headers].each { |key, value| puts key, value }9response = Excon.get('http://google.com', :response_block => Proc.new {})10puts response.data[:headers].each { |key, value| puts key, value }11response = Excon.get('http://google.com', :response_block => Proc.new {})

Full Screen

Full Screen

normalized_headers

Using AI Code Generation

copy

Full Screen

1headers = Excon.normalize_headers({'Content-Type' => 'application/json'})2Excon::Utils.normalize_headers({'Content-Type' => 'application/json'})3Excon::Utils.normalize_headers({'content-type' => 'application/json'})4Excon::Utils.normalize_headers({'content-type' => 'application/json', 'content-length' => 10})5Excon::Utils.normalize_headers({'content-type' => 'application/json', 'content-length' => 10, 'Content-Length' => 20})6Excon::Utils.normalize_headers({'content-type' => 'application/json', 'content-length' => 10, 'Content-Length' => 20, 'connection' => 'close'})7Excon::Utils.normalize_headers({'content-type' => 'application/json', 'content-length' => 10, 'Content-Length' => 20, 'connection' => 'close', 'Connection' => 'keep-alive'})8Excon::Utils.normalize_headers({'content-type' => 'application/json', 'content-length' => 10, 'Content-Length' => 20, 'connection' => 'close', 'Connection' => 'keep-alive', 'transfer-encoding' => 'chunked'})9Excon::Utils.normalize_headers({'content-type' => 'application/json', 'content-length' => 10, 'Content-Length' => 20, 'connection' => 'close', 'Connection' => 'keep-alive', 'transfer-encoding' => 'chunked', 'Transfer-Encoding' => 'gzip'})

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful