Skip to content

Commit aea18c5

Browse files
committed
Read the query from the request body properly.
1 parent 08791bc commit aea18c5

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lib/sparql/server.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def application(dataset: RDF::Repository.new, **options)
4343
rescue SPARQL::Grammar::Parser::Error => e
4444
halt 400, "Error parsing query: #{e.message}"
4545
end
46-
res = query.execute(repo,
46+
res = query.execute(repo,
4747
logger: request.logger,
4848
**options.merge(opts))
4949
res.is_a?(RDF::Literal::Boolean) ? [res] : res
@@ -61,21 +61,24 @@ def application(dataset: RDF::Repository.new, **options)
6161
end
6262

6363
post '/' do
64-
opts = params.inject({}) {|memo, (k,v)| memo.merge(k.to_sym => v)}
65-
# 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.
64+
request_body = request.body.read
65+
opts = params.inject({}) { |memo, (k,v)| memo.merge(k.to_sym => v) }
66+
# Note, this depends on the Rack::SPARQL::ContentNegotiation
67+
# middleware to rewrite application/x-www-form-urlencoded to be
68+
# conformant with either application/sparql-query or
69+
# application/sparql-update.
6670
query = begin
6771
update = case request.content_type
6872
when %r(application/sparql-query) then false
6973
when %r(application/sparql-update) then true
7074
else
7175
halt 406, "No query found for #{request.content_type}"
7276
end
73-
7477
# XXX Rack always sets input to ASCII-8BIT
7578
#unless request.body.external_encoding == Encoding::UTF_8
7679
# halt 400, "improper body encoding: #{request.body.external_encoding}"
7780
#end
78-
SPARQL.parse(request.body, base_uri: url, update: update)
81+
SPARQL.parse(request_body, base_uri: url, update: update)
7982
rescue SPARQL::Grammar::Parser::Error => e
8083
halt 400, "Error parsing #{update ? 'update' : 'query'}: #{e.message}"
8184
end
@@ -90,4 +93,4 @@ def application(dataset: RDF::Repository.new, **options)
9093
end
9194
module_function :application
9295
end
93-
end
96+
end

0 commit comments

Comments
 (0)