Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes accept header not sent via GET request #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,12 @@ public function sendPostData($url, $postData, $arrayHeader = null, $ip = null, $
*
* @param string $url
* @param array $getData get data array ie. $foo['get_var_name'] = $value (default null)
* @param array $arrayHeader header array of the HTTP request (default null)
* @param string $ip address to bind (default null)
* @param int $timeout in sec for complete curl operation (default 600)
* @return bool|string data
*/
public function fetchUrl($url, $getData = null, $ip = null, $timeout = 600)
public function fetchUrl($url, $getData = null, $arrayHeader = null, $ip = null, $timeout = 600)
{
if ($this->_debug) {
curl_setopt($this->_curlHandler, CURLOPT_VERBOSE, true);
Expand All @@ -224,6 +225,10 @@ public function fetchUrl($url, $getData = null, $ip = null, $timeout = 600)
$get_string = null;
}

// set header
if ($arrayHeader != null)
curl_setopt($this->_curlHandler, CURLOPT_HTTPHEADER, $arrayHeader);

// set url to post to
if (empty($get_string)) {
curl_setopt($this->_curlHandler, CURLOPT_URL, $url);
Expand Down
12 changes: 7 additions & 5 deletions src/SparqlClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -637,13 +637,13 @@ public function queryRead($query, $typeOutput = "application/sparql-results+xml"
$response = $client->sendPostData($sUri, $data,null, null, $timeout);
} else {
//TODO PHP8.0 use named arguments
$response = $client->fetchUrl($sUri, $data, null, $timeout); // fix for wikidata
$response = $client->fetchUrl($sUri, $data, null, null, $timeout); // fix for wikidata
}
} else {
$data = array(
$this->_nameParameterQueryRead => $query,
"output" => Mimetype::getShortNameOfMimetype($typeOutput), // possible fix for 4store/fuseki..
"Accept" => $typeOutput
"format" => Mimetype::getShortNameOfMimetype($typeOutput) // some endpoints use 'format' param
); // fix for sesame
// print_r($data);
if ($this->_methodHTTPRead == "POST") {
Expand All @@ -653,7 +653,9 @@ public function queryRead($query, $typeOutput = "application/sparql-results+xml"
),null, $timeout);
} else {
//TODO PHP8.0 use named arguments
$response = $client->fetchUrl($sUri, $data,null, $timeout); // fix for wikidata
$response = $client->fetchUrl($sUri, $data, array(
'Accept: ' . $typeOutput
), null, $timeout); // fix for wikidata
}
}

Expand Down Expand Up @@ -720,7 +722,7 @@ public function queryUpdate($query, $typeOutput = "application/sparql-results+xm
$response = $client->sendPostData($sUri, $data, null, null, $timeout);
} else {
//TODO PHP8.0 use named arguments
$response = $client->fetchUrl($sUri, $data,null, $timeout); // fix for wikidata
$response = $client->fetchUrl($sUri, $data, null, null, $timeout); // fix for wikidata
}
} else {
$data = array(
Expand All @@ -737,7 +739,7 @@ public function queryUpdate($query, $typeOutput = "application/sparql-results+xm
), null, $timeout);
} else {
//TODO PHP8.0 use named arguments
$response = $client->fetchUrl($sUri, $data, null, $timeout); // fix for wikidata
$response = $client->fetchUrl($sUri, $data, null, null, $timeout); // fix for wikidata
}
}

Expand Down