diff --git a/lib/sparql/server.rb b/lib/sparql/server.rb index 15e7517..9e45e01 100644 --- a/lib/sparql/server.rb +++ b/lib/sparql/server.rb @@ -43,7 +43,7 @@ def application(dataset: RDF::Repository.new, **options) rescue SPARQL::Grammar::Parser::Error => e halt 400, "Error parsing query: #{e.message}" end - res = query.execute(repo, + res = query.execute(repo, logger: request.logger, **options.merge(opts)) res.is_a?(RDF::Literal::Boolean) ? [res] : res @@ -61,8 +61,12 @@ def application(dataset: RDF::Repository.new, **options) end post '/' do - opts = params.inject({}) {|memo, (k,v)| memo.merge(k.to_sym => v)} - # Note, this depends on the Rack::SPARQL::ContentNegotiation middleware to rewrite application/x-www-form-urlencoded to be conformat with either application/sparql-query or application/sparql-update. + request_body = request.body.read + opts = params.inject({}) { |memo, (k,v)| memo.merge(k.to_sym => v) } + # Note, this depends on the Rack::SPARQL::ContentNegotiation + # middleware to rewrite application/x-www-form-urlencoded to be + # conformant with either application/sparql-query or + # application/sparql-update. query = begin update = case request.content_type when %r(application/sparql-query) then false @@ -70,12 +74,11 @@ def application(dataset: RDF::Repository.new, **options) else halt 406, "No query found for #{request.content_type}" end - # XXX Rack always sets input to ASCII-8BIT #unless request.body.external_encoding == Encoding::UTF_8 # halt 400, "improper body encoding: #{request.body.external_encoding}" #end - SPARQL.parse(request.body, base_uri: url, update: update) + SPARQL.parse(request_body, base_uri: url, update: update) rescue SPARQL::Grammar::Parser::Error => e halt 400, "Error parsing #{update ? 'update' : 'query'}: #{e.message}" end @@ -90,4 +93,4 @@ def application(dataset: RDF::Repository.new, **options) end module_function :application end -end \ No newline at end of file +end