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

Headers passthru #64

Merged
merged 3 commits into from
Apr 12, 2017
Merged
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
37 changes: 25 additions & 12 deletions src/Chullo.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,17 @@ public function getResource(
* Gets a Fedora resource's headers.
*
* @param string $uri Resource URI
* @param array $headers HTTP Headers
*
* @return array Headers of a resource, null on failure
*/
public function getResourceHeaders(
$uri = ""
$uri = "",
$headers = []
) {
$response = $this->api->getResourceHeaders(
$uri
$uri,
$headers
);

if ($response->getStatusCode() != 200) {
Expand All @@ -101,13 +104,17 @@ public function getResourceHeaders(
* Gets information about the supported HTTP methods, etc., for a Fedora resource.
*
* @param string $uri Resource URI
* @param array $headers HTTP Headers
*
* @return string Options of a resource.
*/
public function getResourceOptions($uri = "")
{
public function getResourceOptions(
$uri = "",
$headers = []
) {
$response = $this->api->getResourceOptions(
$uri
$uri,
$headers
);

return $response->getHeaders();
Expand Down Expand Up @@ -193,27 +200,30 @@ public function saveResource(
*
* @param string $uri Resource URI
* @param EasyRdf_Resource $graph Graph to save
* @param array $headers HTTP Headers
*
* @return boolean True if successful
*/
public function saveGraph(
$uri,
\EasyRdf_Graph $graph
\EasyRdf_Graph $graph,
$headers = []
) {
// Serialze the rdf.
$turtle = $graph->serialise('turtle');

// Checksum it.
$checksum_value = sha1($turtle);

// Set headers.
$headers['Content-Type'] = 'text/turtle';
$headers['digest'] = 'sha1=' . $checksum_value;

// Save it.
return $this->saveResource(
$uri,
$turtle,
[
'Content-Type' => 'text/turtle',
'digest' => 'sha1='.$checksum_value
]
$headers
);
}

Expand Down Expand Up @@ -244,14 +254,17 @@ public function modifyResource(
* Issues a DELETE request to Fedora.
*
* @param string $uri Resource URI
* @param array $headers HTTP Headers
*
* @return boolean True if successful
*/
public function deleteResource(
$uri
$uri = '',
$headers = []
) {
$response = $this->api->deleteResource(
$uri
$uri,
$headers
);

return $response->getStatusCode() == 204;
Expand Down
27 changes: 18 additions & 9 deletions src/FedoraApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public function __construct(Client $client)
*/
public static function create($fedora_rest_url)
{
$guzzle = new Client(['base_uri' => $fedora_rest_url]);
$normalized = rtrim($fedora_rest_url);
$normalized = rtrim($normalized, '/') . '/';
$guzzle = new Client(['base_uri' => $normalized]);
return new static($guzzle);
}

Expand Down Expand Up @@ -86,34 +88,39 @@ public function getResource(
* Gets a Fedora resoure's headers.
*
* @param string $uri Resource URI
* @param array $headers HTTP Headers
*
* @return ResponseInterface
*/
public function getResourceHeaders(
$uri = ""
$uri = "",
$headers = []
) {

// Send the request.
return $this->client->request(
'HEAD',
$uri,
['http_errors' => false]
['http_errors' => false, 'headers' => $headers]
);
}

/**
* Gets information about the supported HTTP methods, etc., for a Fedora resource.
*
* @param string $uri Resource URI
* @param array $headers HTTP Headers
*
* @return ResponseInterface
*/
public function getResourceOptions($uri = "")
{
public function getResourceOptions(
$uri = "",
$headers = []
) {
return $this->client->request(
'OPTIONS',
$uri,
['http_errors' => false]
['http_errors' => false, 'headers' => $headers]
);
}

Expand All @@ -138,7 +145,7 @@ public function createResource(

// Set headers.
$options['headers'] = $headers;

return $this->client->request(
'POST',
$uri,
Expand Down Expand Up @@ -209,13 +216,15 @@ public function modifyResource(
* Issues a DELETE request to Fedora.
*
* @param string $uri Resource URI
* @param array $headers HTTP Headers
*
* @return ResponseInterface
*/
public function deleteResource(
$uri
$uri = '',
$headers = []
) {
$options = ['http_errors' => false];
$options = ['http_errors' => false, 'headers' => $headers];

return $this->client->request(
'DELETE',
Expand Down
18 changes: 14 additions & 4 deletions src/IFedoraApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

/**
* Interface for Fedora interaction. All functions return a PSR-7 response.
*/
*/
interface IFedoraApi
{
/**
Expand All @@ -43,20 +43,28 @@ public function getResource(
$uri = "",
$headers = []
);

/**
* Gets a Fedora resoure's headers.
*
* @param string $uri Resource URI
* @param array $headers HTTP Headers
*/
public function getResourceHeaders(
$uri = ""
$uri = "",
$headers = []
);

/**
* Gets information about the supported HTTP methods, etc., for a Fedora resource.
*
* @param string $uri Resource URI
* @param array $headers HTTP Headers
*/
public function getResourceOptions($uri = "");
public function getResourceOptions(
$uri = "",
$headers = []
);

/**
* Creates a new resource in Fedora.
Expand Down Expand Up @@ -101,8 +109,10 @@ public function modifyResource(
* Issues a DELETE request to Fedora.
*
* @param string $uri Resource URI
* @param array $headers HTTP Headers
*/
public function deleteResource(
$uri
$uri = "",
$headers = []
);
}
4 changes: 3 additions & 1 deletion src/IFedoraClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ public function getGraph(
*
* @param string $uri Resource URI
* @param EasyRdf_Resource $rdf RDF to save
* @param array $headers HTTP Headers
*
* @return null
*/
public function saveGraph(
$uri,
\EasyRdf_Graph $graph
\EasyRdf_Graph $graph,
$headers = []
);
}