Skip to content

Commit 19a1769

Browse files
Tom Johnsongkellogg
authored andcommitted
Handle empty response body on update queries
Update responses are implementation defined; some servers return an empty body and no content type. This handles that case. (cherry picked from commit 6a7ebef)
1 parent 3a231e0 commit 19a1769

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

lib/sparql/client.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,8 @@ def response(query, options = {})
360360
# @return [Object]
361361
def parse_response(response, options = {})
362362
case options[:content_type] || response.content_type
363+
when NilClass
364+
response.body
363365
when RESULT_BOOL # Sesame-specific
364366
response.body == 'true'
365367
when RESULT_JSON

spec/client_spec.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
def response(header)
2727
response = Net::HTTPSuccess.new '1.1', 200, 'body'
28-
response.content_type = header
28+
response.content_type = header if header
2929
allow(response).to receive(:body).and_return('body')
3030
response
3131
end
@@ -95,10 +95,9 @@ def response(header)
9595
subject.query(query, :content_type => SPARQL::Client::RESULT_JSON)
9696
end
9797

98-
it "should handle successful response with overridden JSON header" do
99-
expect(subject).to receive(:request).and_yield response(SPARQL::Client::RESULT_JSON)
100-
expect(subject.class).to receive(:parse_xml_bindings)
101-
subject.query(query, :content_type => SPARQL::Client::RESULT_XML)
98+
it "should handle successful response with no content type" do
99+
expect(subject).to receive(:request).and_yield response(nil)
100+
expect { subject.query(query) }.not_to raise_error
102101
end
103102

104103
it "should handle successful response with overridden plain header" do

0 commit comments

Comments
 (0)