Skip to content

Commit ea457b1

Browse files
committed
use digest auth method in the append request
1 parent 04680ed commit ea457b1

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

lib/goo/sparql/client.rb

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,13 @@ def params_for_backend(graph, data_file, mime_type_in, method = :post)
234234
# for some reason \\\\ breaks parsing
235235
params[:payload][:data] = params[:payload][:data].split("\n").map { |x| x.sub("\\\\", "") }.join("\n")
236236
elsif Goo.backend_vo?
237-
params[:url] = "#{url.parent}/sparql-graph-crud?graph=#{CGI.escape(graph.to_s)}"
237+
if ENV["USE_DIGEST_AUTH"]
238+
# Use digest-specific endpoint
239+
params[:url] = "#{url.parent}sparql-graph-crud-auth?graph=#{CGI.escape(graph.to_s)}"
240+
else
241+
# Fallback for non-digest
242+
params[:url] = "#{url.parent}/sparql-graph-crud?graph=#{CGI.escape(graph.to_s)}"
243+
end
238244
params[:payload] = data_file
239245
else
240246
params[:url] << "?context=#{CGI.escape("<#{graph.to_s}>")}"
@@ -244,7 +250,26 @@ def params_for_backend(graph, data_file, mime_type_in, method = :post)
244250
end
245251

246252
def execute_append_request(graph, data_file, mime_type_in)
247-
RestClient::Request.execute(params_for_backend(graph, data_file, mime_type_in))
253+
params = params_for_backend(graph, data_file, mime_type_in)
254+
if ENV["USE_DIGEST_AUTH"]
255+
uri = URI(params[:url])
256+
http = Net::HTTP.new(uri.host, uri.port)
257+
http.use_ssl = (uri.scheme == 'https')
258+
challenge_res = http.request_head(uri.request_uri)
259+
www_auth = challenge_res['www-authenticate']
260+
digest_auth = Net::HTTP::DigestAuth.new
261+
auth_header = digest_auth.auth_header(uri, www_auth, params[:method].to_s.upcase)
262+
263+
post_req = Net::HTTP::Post.new(uri.request_uri)
264+
post_req['Authorization'] = auth_header
265+
post_req['content-type'] = params[:headers]["content-type"]
266+
post_req['mime-type'] = params[:headers]["mime-type"]
267+
post_req.body = params[:payload]
268+
http.request(post_req)
269+
else
270+
RestClient::Request.execute(params_for_backend(graph, data_file, mime_type_in))
271+
end
272+
248273
end
249274
end
250275
end

0 commit comments

Comments
 (0)