Skip to content

Commit ac03646

Browse files
committed
using head requests for alma and wowza okcomputer
1 parent 87c4787 commit ac03646

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

config/initializers/okcomputer.rb

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,29 @@ def check
2626
end
2727
end
2828

29+
class HeadCheck < OkComputer::HttpCheck
30+
def perform_request
31+
Timeout.timeout(request_timeout) do
32+
options = { read_timeout: request_timeout }
33+
34+
if basic_auth_options.any?
35+
options[:http_basic_authentication] = basic_auth_options
36+
end
37+
38+
RestClient.head(url.to_s, options)
39+
end
40+
rescue => e
41+
raise ConnectionFailed, e
42+
end
43+
end
44+
2945
# Ensure Alma API is working.
30-
OkComputer::Registry.register 'alma-metadata', OkComputer::HttpCheck.new(ALMA_TEST_URL)
46+
OkComputer::Registry.register 'alma-metadata', HeadCheck.new(ALMA_TEST_URL)
3147

3248
# Ensure TIND API is working. This cannot use `OkComputer::HttpCheck`
3349
# out of the box as we can't yet inject headers into the request without
3450
# subclassing the whole thing.
3551
OkComputer::Registry.register 'tind-metadata', TindCheck.new
3652

3753
# Ensure Wowza is working
38-
OkComputer::Registry.register 'wowza-streaming', OkComputer::HttpCheck.new(WOWZA_TEST_URL)
54+
OkComputer::Registry.register 'wowza-streaming', HeadCheck.new(WOWZA_TEST_URL)

spec/request/okcomputer_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
RSpec.describe 'OKComputer', type: :request do
44
before do
5-
stub_sru_request('b23305522')
5+
stub_sru_head_request('b23305522')
66

77
hls_manifest = File.read('spec/data/playlist.m3u8')
88
manifest_url = 'https://wowza.lib.berkeley.edu/Pacifica/mp3:PRA_NHPRC1_AZ1084_00_000_00.mp3/playlist.m3u8'
9-
stub_request(:get, manifest_url).to_return(status: 200, body: hls_manifest)
9+
stub_request(:head, manifest_url).to_return(status: 200)
1010

1111
record_id = '(pacradio)01469'
1212
tind_url = BerkeleyLibrary::AV::Metadata::Source::TIND.marc_uri_for(record_id)

spec/spec_helper.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ def stub_sru_request(record_id, body: nil)
7272
stub_request(:get, sru_url).to_return(status: 200, body: body || File.new(alma_sru_data_path_for(record_id)))
7373
end
7474

75+
def stub_sru_head_request(record_id, body: nil)
76+
sru_url = alma_sru_url_for(record_id)
77+
stub_request(:head, sru_url).to_return(status: 200)
78+
end
79+
7580
def alma_marc_record_for(record_id)
7681
marc_xml_path = alma_sru_data_path_for(record_id)
7782
MARC::XMLReader.new(marc_xml_path).first

0 commit comments

Comments
 (0)