From f9611d22f2e5537e6fac68f8a1ccbda99fbf1806 Mon Sep 17 00:00:00 2001 From: Holden Omans Date: Mon, 2 Sep 2019 11:02:41 -0400 Subject: [PATCH] fix for 'Content-Encoding: gzip' errors --- shard.yml | 2 +- spec/spec_helper.cr | 3 +++ src/ext/http_client.cr | 11 +++++++++-- src/vcr/version.cr | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/shard.yml b/shard.yml index 41ab93d..51caa2d 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: vcr -version: 0.2.1 +version: 0.2.2 authors: - Holden Omans diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr index bc98fc4..1033d34 100644 --- a/spec/spec_helper.cr +++ b/spec/spec_helper.cr @@ -2,3 +2,6 @@ require "spec" require "../src/vcr" require "halite" +require "file_utils" + +FileUtils.rm_rf("./spec/fixtures/vcr/cassette-one") diff --git a/src/ext/http_client.cr b/src/ext/http_client.cr index f7ae8ec..079c877 100644 --- a/src/ext/http_client.cr +++ b/src/ext/http_client.cr @@ -38,9 +38,16 @@ class HTTP::Client else response = orig_exec_internal_single(request) unless response.nil? + io = IO::Memory.new cassette_file = File.open(cassette_path, "w+") - response.to_io(cassette_file) - cassette_file.flush + response.to_io(io) + io.rewind + + cassette_file = File.open(cassette_path, "w+") + io.each_line do |line| + cassette_file.puts(line) unless line =~ /Content-Encoding: gzip/ + end + cassette_file.close return response end diff --git a/src/vcr/version.cr b/src/vcr/version.cr index 3f3a774..574bf88 100644 --- a/src/vcr/version.cr +++ b/src/vcr/version.cr @@ -1,3 +1,3 @@ module VCR - VERSION = "0.2.1" + VERSION = "0.2.2" end