Class: App
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- App
- Defined in:
- lib/vcr/proxy/app.rb
Overview
Sinatra App which proxy calls caching the response with VCR
Instance Method Summary collapse
- #relay_response(response) ⇒ Object
- #request_headers ⇒ Object
- #request_uri ⇒ Object
- #vcr_wrapper(verb) ⇒ Object
Instance Method Details
#relay_response(response) ⇒ Object
49 50 51 52 |
# File 'lib/vcr/proxy/app.rb', line 49 def relay_response(response) status response.status response.body end |
#request_headers ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/vcr/proxy/app.rb', line 60 def request_headers selected_headers = env.select { |k, _v| k.start_with? 'HTTP_' }.each_with_object({}) do |item, object| object[item[0].sub(/^HTTP_/, '').split('_').map(&:capitalize).join('-')] = item[1] end selected_headers.delete('Host') selected_headers.delete('Accept-Encoding') selected_headers end |
#request_uri ⇒ Object
54 55 56 57 58 |
# File 'lib/vcr/proxy/app.rb', line 54 def request_uri uri = URI("#{VCR::Proxy.config.endpoint}#{request.path}") uri.query = URI.encode_www_form(request.params) uri end |
#vcr_wrapper(verb) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/vcr/proxy/app.rb', line 71 def vcr_wrapper(verb) key = "#{request.path}/#{verb}/#{request.params.to_json}" match_requests_on = VCR::Proxy.config.match_requests_on record_mode = VCR::Proxy.config.record_mode VCR.use_cassette(key, match_requests_on: match_requests_on, decode_compressed_response: true, record: record_mode) do yield end end |