Page MenuHomePhabricator

SMW_SparqlDatabase sends incorrect Accept header with SPARQL query requests
Closed, ResolvedPublic

Description

Author: jeen.broekstra

Description:
The method doQuery in SMW_SparqlDatabase.php executes a HTTP request to perform a SPARQL query at a remote endpoint. However, it currently does not set a correct Accept-header in the HTTP request, which means that the server receives:

Accept: */*

Which means that it is left up to the server to pick a response format.

This is a bug, because doQuery, when processing the result, assumes that the response format will always be in SPARQL XML Results format. If that is the assumption, this should be made clear in the Accept header, because otherwise a servers implementing several kinds of query result formats may send back a format that SMW does not know how to parse.

As a case in point, when using the Sesame framework as an endpoint, this is precisely what happens: Sesame, upon receiving the request from SMW, sends back the query result in a binary format that SMW is unable to parse.

To fix, the following should be added to doQuery:

curl_setopt( $this->m_curlhandle, CURLOPT_HTTPHEADER,
array('Accept: application/sparql-results+xml,application/xml;q=0.8' ));

This sets the Accept header to indicate that the only acceptable format for SMW is SPARQL XML Results format (and adds some flexibility in case an endpoint does not use the correct mime type but instead uses application/xml).

I have personally tested this fix against a Sesame-based endpoint and it solves the issue.


Version: unspecified
Severity: major

Details

Reference
bz32280
ReferenceSource BranchDest BranchAuthorTitle
repos/abstract-wiki/wikifunctions/function-orchestrator!61sync-function-schematamainjforresterUpdate function-schemata sub-module to HEAD (0c37460)
repos/abstract-wiki/wikifunctions/function-evaluator!54sync-function-schematamainjforresterUpdate function-schemata sub-module to HEAD (0c37460)
repos/abstract-wiki/wikifunctions/wikilambda-cli!14sync-function-schematamainjforresterUpdate function-schemata sub-module to HEAD (0c37460)
toolforge-repos/ifttt!21work/bd808/T342803mainbd808Guard against serialization errors + other fixes
repos/abstract-wiki/wikifunctions/function-schemata!30T342808mainjforresterdefinitions: Fix Z1909/bug-latn code (-latn not -lant)
Customize query in GitLab

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 12:06 AM
bzimport set Reference to bz32280.
bzimport added a subscriber: Unknown Object (MLST).

jeen.broekstra wrote:

patched version of SMW_SparqlDatabase.php

patched version of SMW_SparqlDatabase.php. The patch is a single line (line 407).

Attached:

Good point, thanks for the report. Fixed in r111245 by using your patch. (I am surprised though, that any SPARQL database, upon receiving a request that does not specify the result format, would choose to return anything else than the standard W3C format. But it is good to know that it works with Sesame with this modification.)