Last modified: 2012-02-11 16:28:29 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T34280, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 32280 - SMW_SparqlDatabase sends incorrect Accept header with SPARQL query requests
SMW_SparqlDatabase sends incorrect Accept header with SPARQL query requests
Status: RESOLVED FIXED
Product: MediaWiki extensions
Classification: Unclassified
Semantic MediaWiki (Other open bugs)
unspecified
All All
: Unprioritized major (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-11-08 20:30 UTC by Jeen
Modified: 2012-02-11 16:28 UTC (History)
2 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments
patched version of SMW_SparqlDatabase.php (20.68 KB, application/x-httpd-php)
2011-11-08 20:33 UTC, Jeen
Details

Description Jeen 2011-11-08 20:30:17 UTC
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.
Comment 1 Jeen 2011-11-08 20:33:17 UTC
Created attachment 9386 [details]
patched version of SMW_SparqlDatabase.php

patched version of SMW_SparqlDatabase.php. The patch is a single line (line 407).
Comment 2 Markus Krötzsch 2012-02-11 16:28:29 UTC
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.)

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links