|
|
@ -198,27 +198,39 @@ sub forbid_link_header {
|
|
|
|
sub valid_media_type {
|
|
|
|
sub valid_media_type {
|
|
|
|
my ($self, $c, $media_type) = @_;
|
|
|
|
my ($self, $c, $media_type) = @_;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
my $ctype = $c->request->header('Content-Type');
|
|
|
|
|
|
|
|
$ctype =~ s/;\s+boundary.+$//;
|
|
|
|
my $type;
|
|
|
|
my $type;
|
|
|
|
if(ref $media_type eq "ARRAY") {
|
|
|
|
if(ref $media_type eq "ARRAY") {
|
|
|
|
$type = join ' or ', @{ $media_type };
|
|
|
|
$type = join ' or ', @{ $media_type };
|
|
|
|
return 1 if $c->request->header('Content-Type') &&
|
|
|
|
return 1 if $ctype && $ctype ~~ $media_type;
|
|
|
|
$c->request->header('Content-Type') ~~ $media_type;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$type = $media_type;
|
|
|
|
$type = $media_type;
|
|
|
|
return 1 if($c->request->header('Content-Type') &&
|
|
|
|
return 1 if($ctype && index($ctype, $media_type) == 0);
|
|
|
|
index($c->request->header('Content-Type'), $media_type) == 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$self->error($c, HTTP_UNSUPPORTED_MEDIA_TYPE, "Unsupported media type, accepting $type only.");
|
|
|
|
$self->error($c, HTTP_UNSUPPORTED_MEDIA_TYPE, "Unsupported media type '" . ($ctype // 'undefined') . "', accepting $type only.");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub require_body {
|
|
|
|
sub require_body {
|
|
|
|
my ($self, $c) = @_;
|
|
|
|
my ($self, $c) = @_;
|
|
|
|
return 1 if length $c->stash->{body};
|
|
|
|
return 1 if length $c->stash->{body};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$self->error($c, HTTP_BAD_REQUEST, "This request is missing a message body.");
|
|
|
|
$self->error($c, HTTP_BAD_REQUEST, "This request is missing a message body.");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# returns Catalyst::Request::Upload
|
|
|
|
|
|
|
|
sub get_upload {
|
|
|
|
|
|
|
|
my ($self, $c, $field) = @_;
|
|
|
|
|
|
|
|
my $upload = $c->req->upload($field);
|
|
|
|
|
|
|
|
return $upload if $upload;
|
|
|
|
|
|
|
|
$self->error($c, HTTP_BAD_REQUEST, "This request is missing the upload part '$field' in body.");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub require_precondition {
|
|
|
|
sub require_precondition {
|
|
|
|
my ($self, $c, $header_name) = @_;
|
|
|
|
my ($self, $c, $header_name) = @_;
|
|
|
|
return 1 if $c->request->header($header_name);
|
|
|
|
return 1 if $c->request->header($header_name);
|
|
|
@ -252,6 +264,7 @@ sub require_wellformed_json {
|
|
|
|
NGCP::Panel::Utils::ValidateJSON->new($patch);
|
|
|
|
NGCP::Panel::Utils::ValidateJSON->new($patch);
|
|
|
|
$ret = 1;
|
|
|
|
$ret = 1;
|
|
|
|
} catch($e) {
|
|
|
|
} catch($e) {
|
|
|
|
|
|
|
|
chomp $e;
|
|
|
|
$self->error($c, HTTP_BAD_REQUEST, "The entity is not a well-formed '$media_type' document. $e");
|
|
|
|
$self->error($c, HTTP_BAD_REQUEST, "The entity is not a well-formed '$media_type' document. $e");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
return $ret;
|
|
|
|