MT#3997 Use JSON in OPTIONS methods.

agranig/rest
Andreas Granig 12 years ago
parent 40ecb1e91d
commit 0fb58d2668

@ -76,14 +76,14 @@ sub HEAD :Allow {
sub OPTIONS :Allow {
my ($self, $c, $id) = @_;
my $allowed_methods = $self->allowed_methods->join(q(, ));
my $allowed_methods = $self->allowed_methods;
$c->response->headers(HTTP::Headers->new(
Allow => $allowed_methods,
Allow => $allowed_methods->join(', '),
Accept_Patch => 'application/json-patch+json',
Content_Language => 'en',
));
$c->response->content_type('application/xhtml+xml');
$c->stash(template => 'api/allowed_methods.tt', allowed_methods => $allowed_methods);
$c->response->content_type('application/json');
$c->response->body(JSON::to_json({ methods => $allowed_methods })."\n");
return;
}

@ -78,14 +78,14 @@ sub HEAD :Allow {
sub OPTIONS :Allow {
my ($self, $c, $id) = @_;
my $allowed_methods = $self->allowed_methods->join(q(, ));
my $allowed_methods = $self->allowed_methods;
$c->response->headers(HTTP::Headers->new(
Allow => $allowed_methods,
Allow => $allowed_methods->join(', '),
Accept_Patch => 'application/json-patch+json',
Content_Language => 'en',
));
$c->response->content_type('application/xhtml+xml');
$c->stash(template => 'api/allowed_methods.tt', allowed_methods => $allowed_methods);
$c->response->content_type('application/json');
$c->response->body(JSON::to_json({ methods => $allowed_methods })."\n");
return;
}

@ -30,7 +30,7 @@ __PACKAGE__->config(
action_roles => [qw(HTTPMethods)],
);
sub GET : Allow {
sub GET :Allow {
my ($self, $c) = @_;
$c->response->status(HTTP_NOT_IMPLEMENTED);
$c->response->headers(HTTP::Headers->new(
@ -41,26 +41,26 @@ sub GET : Allow {
return;
}
sub HEAD : Allow {
sub HEAD :Allow {
my ($self, $c) = @_;
$c->forward(qw(GET));
$c->response->body(q());
return;
}
sub OPTIONS : Allow {
sub OPTIONS :Allow {
my ($self, $c) = @_;
my $allowed_methods = $self->allowed_methods->join(q(, ));
my $allowed_methods = $self->allowed_methods;
$c->response->headers(HTTP::Headers->new(
Allow => $allowed_methods,
Allow => $allowed_methods->join(', '),
Content_Language => 'en',
));
$c->response->content_type('application/xhtml+xml');
$c->stash(template => 'api/allowed_methods.tt', allowed_methods => $allowed_methods);
$c->response->content_type('application/json');
$c->response->body(JSON::to_json({ methods => $allowed_methods })."\n");
return;
}
sub end : Private {
sub end :Private {
my ($self, $c) = @_;
$c->forward(qw(Controller::Root render));
$c->response->content_type('')

@ -1,10 +0,0 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Precondition failed</title>
</head>
<body>
<p>This <tt>[% entity_name | html %]</tt> entity cannot be found, it is either expired or does not exist.
Fetch a fresh one.</p>
</body>
</html>

@ -1,10 +0,0 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Preference required</title>
</head>
<body>
<p>This request is required to express an expectation about the response. Use the <tt>Prefer</tt> header with
either a <tt>return=minimal</tt> or a <tt>return=representation</tt> preference.</p>
</body>
</html>
Loading…
Cancel
Save