Skip to content

Commit

Permalink
Fix HEAD requests
Browse files Browse the repository at this point in the history
With newer version of Mojolicious::Plugin::OpenAPI HEAD requests are broken as no spec
can be found. Hence the default_spec is used - which requires the 'errors' property.
But usually a HEAD request is successful, hence no 'errors' property. This leads to a
'500 Internal Server Error' response.

A HEAD request is some kind of a GET request (it requests the headers that would be
returned if the resource was requested with a GET request. See
https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD).

So the HEAD request should be treated as a special case.
  • Loading branch information
reneeb committed Jan 30, 2019
1 parent 5729e1b commit affb451
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/Mojolicious/Plugin/OpenAPI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ sub _helper_get_spec {
$jp ||= [paths => $s->{'openapi.path'}];
}

push @$jp, lc $c->req->method if $jp and $path ne 'for_path'; # Internal for now
my $method = lc $c->req->method;
push @$jp, ( $method eq 'head' ? 'get' : $method ) if $jp and $path ne 'for_path'; # Internal for now
return $jp ? $self->validator->get($jp) : undef;
}

Expand Down

0 comments on commit affb451

Please sign in to comment.