diff --git a/packages/forest_admin_datasource_rpc/lib/forest_admin_datasource_rpc/Utils/rpc_client.rb b/packages/forest_admin_datasource_rpc/lib/forest_admin_datasource_rpc/Utils/rpc_client.rb index 3775eb7db..06396bcd3 100644 --- a/packages/forest_admin_datasource_rpc/lib/forest_admin_datasource_rpc/Utils/rpc_client.rb +++ b/packages/forest_admin_datasource_rpc/lib/forest_admin_datasource_rpc/Utils/rpc_client.rb @@ -95,7 +95,7 @@ def build_request_headers(caller, if_none_match) } headers['forest_caller'] = caller.to_json if caller - headers['If-None-Match'] = %("#{if_none_match}") if if_none_match + headers['If-None-Match'] = if_none_match if if_none_match headers end diff --git a/packages/forest_admin_datasource_rpc/spec/lib/forest_admin_datasource_rpc/utils/rpc_client_spec.rb b/packages/forest_admin_datasource_rpc/spec/lib/forest_admin_datasource_rpc/utils/rpc_client_spec.rb index 50b4c5ef9..9e86d2dfa 100644 --- a/packages/forest_admin_datasource_rpc/spec/lib/forest_admin_datasource_rpc/utils/rpc_client_spec.rb +++ b/packages/forest_admin_datasource_rpc/spec/lib/forest_admin_datasource_rpc/utils/rpc_client_spec.rb @@ -122,7 +122,7 @@ module Utils rpc_client.fetch_schema('/rpc/schema', if_none_match: 'abc123') expect(faraday_connection).to have_received(:send) do |_method, _endpoint, _payload, headers| - expect(headers['If-None-Match']).to eq('"abc123"') + expect(headers['If-None-Match']).to eq('abc123') end end @@ -136,9 +136,9 @@ module Utils end context 'with ETag in response' do - let(:response_headers) { { 'ETag' => '"etag123"' } } + let(:response_headers) { { 'ETag' => 'etag123' } } - it 'extracts ETag from response headers and strips quotes' do + it 'extracts ETag from response headers' do result = rpc_client.fetch_schema('/rpc/schema') expect(result.etag).to eq('etag123') @@ -146,7 +146,7 @@ module Utils end context 'with lowercase etag header' do - let(:response_headers) { { 'etag' => '"lowercase-etag"' } } + let(:response_headers) { { 'etag' => 'lowercase-etag' } } it 'extracts etag from lowercase header' do result = rpc_client.fetch_schema('/rpc/schema') diff --git a/packages/forest_admin_rpc_agent/lib/forest_admin_rpc_agent/routes/schema.rb b/packages/forest_admin_rpc_agent/lib/forest_admin_rpc_agent/routes/schema.rb index 1bf4a7141..e2ee99c24 100644 --- a/packages/forest_admin_rpc_agent/lib/forest_admin_rpc_agent/routes/schema.rb +++ b/packages/forest_admin_rpc_agent/lib/forest_admin_rpc_agent/routes/schema.rb @@ -23,7 +23,7 @@ def handle_request(args) 'ETag matches, returning 304 Not Modified' ) return { status: HTTP_NOT_MODIFIED, content: nil, - headers: { 'ETag' => quote_etag(agent.cached_schema_hash) } } + headers: { 'ETag' => agent.cached_schema_hash } } end # Get schema from cache (or build from datasource if not cached) @@ -34,7 +34,7 @@ def handle_request(args) { status: HTTP_OK, content: schema, - headers: { 'ETag' => quote_etag(etag) } + headers: { 'ETag' => etag } } end @@ -45,26 +45,11 @@ def extract_if_none_match(args) return nil unless request # Get If-None-Match header (works for both Rails and Sinatra) - etag = if request.respond_to?(:get_header) - request.get_header('HTTP_IF_NONE_MATCH') - elsif request.respond_to?(:env) - request.env['HTTP_IF_NONE_MATCH'] - end - - # Strip quotes from ETag value if present - unquote_etag(etag) - end - - def quote_etag(etag) - return nil unless etag - - %("#{etag}") - end - - def unquote_etag(etag) - return nil unless etag - - etag.gsub(/\A"?|"?\z/, '') + if request.respond_to?(:get_header) + request.get_header('HTTP_IF_NONE_MATCH') + elsif request.respond_to?(:env) + request.env['HTTP_IF_NONE_MATCH'] + end end end end diff --git a/packages/forest_admin_rpc_agent/spec/lib/forest_admin_rpc_agent/routes/schema_spec.rb b/packages/forest_admin_rpc_agent/spec/lib/forest_admin_rpc_agent/routes/schema_spec.rb index eddd125e5..639777a5c 100644 --- a/packages/forest_admin_rpc_agent/spec/lib/forest_admin_rpc_agent/routes/schema_spec.rb +++ b/packages/forest_admin_rpc_agent/spec/lib/forest_admin_rpc_agent/routes/schema_spec.rb @@ -38,12 +38,12 @@ module Routes expect(result[:status]).to eq(200) expect(result[:content]).to eq(cached_schema) - expect(result[:headers]['ETag']).to eq(%("#{cached_hash}")) + expect(result[:headers]['ETag']).to eq(cached_hash) end context 'when client provides matching If-None-Match header' do let(:mock_request) do - instance_double(::Rack::Request, get_header: %("#{cached_hash}")) + instance_double(::Rack::Request, get_header: cached_hash) end before do @@ -55,7 +55,7 @@ module Routes expect(result[:status]).to eq(304) expect(result[:content]).to be_nil - expect(result[:headers]['ETag']).to eq(%("#{cached_hash}")) + expect(result[:headers]['ETag']).to eq(cached_hash) end it 'logs debug message' do @@ -67,7 +67,7 @@ module Routes context 'when client provides non-matching If-None-Match header' do let(:mock_request) do - instance_double(::Rack::Request, get_header: '"different_hash"') + instance_double(::Rack::Request, get_header: 'different_hash') end it 'returns the full schema with ETag header' do @@ -75,7 +75,7 @@ module Routes expect(result[:status]).to eq(200) expect(result[:content]).to eq(cached_schema) - expect(result[:headers]['ETag']).to eq(%("#{cached_hash}")) + expect(result[:headers]['ETag']).to eq(cached_hash) end end @@ -97,7 +97,7 @@ module Routes # Sinatra-style: responds to env but not get_header # Using a Struct to simulate Sinatra request behavior hash_value = cached_hash - Struct.new(:env).new({ 'HTTP_IF_NONE_MATCH' => %("#{hash_value}") }) + Struct.new(:env).new({ 'HTTP_IF_NONE_MATCH' => hash_value }) end it 'extracts If-None-Match from env and returns 304 when hash matches' do