Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
Support OPTIONS method for all endpoints.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeqq committed Feb 25, 2016
1 parent 733ffb0 commit 2653252
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 16 deletions.
66 changes: 66 additions & 0 deletions config/install/relaxed.settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ resources:
supported_auth:
- cookie
- basic_auth
OPTIONS:
supported_formats:
- json
supported_auth:
- cookie
- basic_auth
POST:
supported_formats:
- json
Expand Down Expand Up @@ -45,6 +51,12 @@ resources:
supported_auth:
- cookie
- basic_auth
OPTIONS:
supported_formats:
- json
supported_auth:
- cookie
- basic_auth
PUT:
supported_formats:
- json
Expand All @@ -64,6 +76,12 @@ resources:
supported_auth:
- cookie
- basic_auth
OPTIONS:
supported_formats:
- json
supported_auth:
- cookie
- basic_auth
relaxed:changes:
GET:
supported_formats:
Expand Down Expand Up @@ -91,6 +109,12 @@ resources:
supported_auth:
- cookie
- basic_auth
OPTIONS:
supported_formats:
- json
supported_auth:
- cookie
- basic_auth
PUT:
supported_formats:
- json
Expand All @@ -111,6 +135,12 @@ resources:
supported_auth:
- cookie
- basic_auth
OPTIONS:
supported_formats:
- json
supported_auth:
- cookie
- basic_auth
relaxed:local:doc:
HEAD:
supported_formats:
Expand All @@ -124,6 +154,12 @@ resources:
supported_auth:
- cookie
- basic_auth
OPTIONS:
supported_formats:
- json
supported_auth:
- cookie
- basic_auth
PUT:
supported_formats:
- json
Expand All @@ -137,31 +173,61 @@ resources:
supported_auth:
- cookie
- basic_auth
OPTIONS:
supported_formats:
- json
supported_auth:
- cookie
- basic_auth
relaxed:session:
GET:
supported_formats:
- json
supported_auth:
- cookie
- basic_auth
OPTIONS:
supported_formats:
- json
supported_auth:
- cookie
- basic_auth
relaxed:ensure_full_commit:
POST:
supported_formats:
- json
supported_auth:
- cookie
- basic_auth
OPTIONS:
supported_formats:
- json
supported_auth:
- cookie
- basic_auth
relaxed:all_dbs:
GET:
supported_formats:
- json
supported_auth:
- cookie
- basic_auth
OPTIONS:
supported_formats:
- json
supported_auth:
- cookie
- basic_auth
relaxed:all_docs:
GET:
supported_formats:
- json
supported_auth:
- cookie
- basic_auth
OPTIONS:
supported_formats:
- json
supported_auth:
- cookie
- basic_auth
16 changes: 0 additions & 16 deletions src/Plugin/rest/resource/ChangesResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,6 @@
*/
class ChangesResource extends ResourceBase {

/**
* @param $workspace
*
* @return ResourceResponse
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
public function options($workspace) {
if (!$workspace instanceof WorkspaceInterface) {
throw new NotFoundHttpException();
}
$response = new ResourceResponse(NULL, 204);
$response->addCacheableDependency($workspace);

return $response;
}

/**
* @param $workspace
*
Expand Down
24 changes: 24 additions & 0 deletions src/Plugin/rest/resource/ResourceBase.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,39 @@
<?php

/**
* @file
* Contains \Drupal\relaxed\Plugin\rest\resource\ResourceBase.
*/

namespace Drupal\relaxed\Plugin\rest\resource;

use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\multiversion\Entity\WorkspaceInterface;
use Drupal\rest\Plugin\ResourceBase as CoreResourceBase;
use Drupal\rest\ResourceResponse;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;

abstract class ResourceBase extends CoreResourceBase implements RelaxedResourceInterface {

/**
* @param $workspace
*
* @return ResourceResponse
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
public function options($workspace) {
if (!$workspace instanceof WorkspaceInterface) {
throw new NotFoundHttpException();
}
$response = new ResourceResponse(NULL, 204);
$response->addCacheableDependency($workspace);

return $response;
}

/**
* {@inheritdoc}
*/
Expand Down

0 comments on commit 2653252

Please sign in to comment.