diff --git a/app/services/iiif_metadata_service.rb b/app/services/iiif_metadata_service.rb index e50614bc..64b701cf 100644 --- a/app/services/iiif_metadata_service.rb +++ b/app/services/iiif_metadata_service.rb @@ -44,7 +44,11 @@ def image_height # @return [String] the IIIF info response def retrieve with_retries max_tries: 3, rescue: [HTTP::ConnectionError] do - handle_response(HTTP.get(@url)) + handle_response( + # Disable url normalization as an upstream bug in addressable causes issues for `+` + # https://github.com/sporkmonger/addressable/issues/386 + HTTP.use({ normalize_uri: { normalizer: lambda(&:itself) } }).get(@url) + ) end end diff --git a/spec/services/iiif_metadata_service_spec.rb b/spec/services/iiif_metadata_service_spec.rb index 4aa1d1f6..e9f64bd3 100644 --- a/spec/services/iiif_metadata_service_spec.rb +++ b/spec/services/iiif_metadata_service_spec.rb @@ -8,6 +8,7 @@ end let(:base_uri) { 'https://sul-imageserver-uat.stanford.edu/cantaloupe/iiif/2/' } # 'image-server-path' let(:service) { described_class.new(image_id: identifier, canonical_url: 'foo', base_uri: base_uri) } + let(:http_client) { instance_double(HTTP::Client) } context "When a valid JSON response is received" do let(:json) do @@ -19,8 +20,11 @@ '"sizes":[{"width":1916,"height":1276}]}' end let(:response) { instance_double(HTTP::Response, code: 200, body: json) } + before do - allow(HTTP).to receive(:get) + allow(HTTP).to receive(:use) + .and_return(http_client) + allow(http_client).to receive(:get) .with('https://sul-imageserver-uat.stanford.edu/cantaloupe/iiif/2/nr%2F349%2Fct%2F7889%2Fnr349ct7889_00_0001.jp2/info.json') .and_return(response) end @@ -54,7 +58,9 @@ let(:empty_json) { '' } let(:bad_response) { instance_double(HTTP::Response, code: 200, body: empty_json) } before do - allow(HTTP).to receive(:get) + allow(HTTP).to receive(:use) + .and_return(http_client) + allow(http_client).to receive(:get) .with('https://sul-imageserver-uat.stanford.edu/cantaloupe/iiif/2/nr%2F349%2Fct%2F7889%2Fnr349ct7889_00_0001.jp2/info.json') .and_return(bad_response) end