From b7586811a9cf0be4d91c270442700d2e2b8e2fe5 Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Sun, 19 Jan 2025 23:31:21 +0100 Subject: [PATCH] Use `HEAD` instead of `GET` to ping Colore Reduces the amount of data received and the stress on the server --- lib/colore/client.rb | 2 +- .../cassettes/Colore_Client/_ping/runs.yml | 63 +++++-------------- spec/lib/colore/client_spec.rb | 2 +- 3 files changed, 16 insertions(+), 51 deletions(-) diff --git a/lib/colore/client.rb b/lib/colore/client.rb index 9ecf4fe..91943ad 100644 --- a/lib/colore/client.rb +++ b/lib/colore/client.rb @@ -65,7 +65,7 @@ def generate_doc_id # Tests the connection with Colore. Will raise an error if the connection cannot be # established. def ping - send_request :get, '/' + send_request :head, '/' true end diff --git a/spec/fixtures/cassettes/Colore_Client/_ping/runs.yml b/spec/fixtures/cassettes/Colore_Client/_ping/runs.yml index 8528319..7866eb7 100644 --- a/spec/fixtures/cassettes/Colore_Client/_ping/runs.yml +++ b/spec/fixtures/cassettes/Colore_Client/_ping/runs.yml @@ -1,74 +1,39 @@ --- http_interactions: - request: - method: get + method: head uri: http://localhost:9240/ body: encoding: US-ASCII string: '' headers: - Accept: - - "*/*; q=0.5, application/xml" - Accept-Encoding: - - gzip, deflate User-Agent: - - Ruby + - Colore Client + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" response: status: code: 200 message: OK headers: + Date: + - Sun, 19 Jan 2025 22:28:16 GMT + Connection: + - close Content-Type: - text/html;charset=utf-8 Content-Length: - - '977' + - '262' X-Xss-Protection: - 1; mode=block X-Content-Type-Options: - nosniff X-Frame-Options: - SAMEORIGIN - Connection: - - keep-alive - Server: - - thin body: encoding: UTF-8 - string: | - - - - - - - - - - - - -
- - - - Colore - - -

Colore

-

- Welcome to the Colore application. This is an API service to store and convert - documents. -

- - -
- - - http_version: - recorded_at: Tue, 10 Feb 2015 12:11:21 GMT -recorded_with: VCR 2.9.3 + string: '' + recorded_at: Sun, 19 Jan 2025 22:28:16 GMT +recorded_with: VCR 6.3.1 diff --git a/spec/lib/colore/client_spec.rb b/spec/lib/colore/client_spec.rb index e1920fb..1c113bf 100644 --- a/spec/lib/colore/client_spec.rb +++ b/spec/lib/colore/client_spec.rb @@ -29,7 +29,7 @@ end it 'raises ColoreUnavailable on ECONNREFUSED' do - allow(client.send(:connection)).to receive(:get) { raise Faraday::ConnectionFailed } + allow(client.send(:connection)).to receive(:head) { raise Faraday::ConnectionFailed } expect { client.ping }.to raise_error(Colore::Errors::ColoreUnavailable) end end