Skip to content

Commit

Permalink
Remove url normalization from our HTTP calls to the imageserver
Browse files Browse the repository at this point in the history
We are removing the default HTTP gem URL normalization because there is
an upstream error which causes issues for `+` characters.

sporkmonger/addressable#386
  • Loading branch information
mejackreed committed Oct 1, 2020
1 parent 59a2adf commit ae3b2a9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 5 additions & 1 deletion app/services/iiif_metadata_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 8 additions & 2 deletions spec/services/iiif_metadata_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ae3b2a9

Please sign in to comment.