grpc-gateway icon indicating copy to clipboard operation
grpc-gateway copied to clipboard

Unsupported HEAD call to known URL does not return error response body.

Open maja42 opened this issue 3 years ago • 4 comments

🐛 Bug Report

When performing a HTTP call using an unsupported method, for example when making a POST request to a URL that only supports GET, I get a http-501-error-response from the gateway. The response body contains the grpc error code 12 ("Unimplemented") with the message "Method Not Allowed".

When performing a HEAD-call to the same get-only-URL, I expect the same error response. What happens is that the http request fails with 501 (which is correct), but the response body stays empty. According to the documentation, the HEAD call should not have any special behaviour, so I expect the body to contain the same error details. An error-response-body should never be empty. Docs: https://cloud.google.com/service-infrastructure/docs/service-management/reference/rpc/google.api#special-notes

To Reproduce

  1. Define a gRPC endpoint with only a GET-http-mapping (or any other method).
  2. Generate and start the grpc-gateway
  3. Perform a http HEAD-call to the same URL.
  4. The response (status 501) will have an empty body.

Your Environment

Im using github.com/grpc-ecosystem/grpc-gateway/v2 v2.0.0-beta.4

maja42 avatar Sep 21 '20 09:09 maja42

Hi again Maja, thanks for the bug report! I think the logic for this is here, here and here. I don't see any special handling for POST vs HEAD though, so I'm not sure what's going on here. Would you be interested in contributing a fix for this?

Easiest thing might be to add a test here first.

johanbrandhorst avatar Sep 21 '20 10:09 johanbrandhorst

I can take a look at it, but since I'm pretty busy right now I'm not sure if and when I have spare time for it.

maja42 avatar Sep 21 '20 11:09 maja42

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Nov 21 '20 01:11 stale[bot]

This behaviour might be included deeper (in the HTTP server implementation, for instance) or the client you use discards body. Discarding body in HEAD requests is actually correct:

A response to a HEAD method should not have a body. If it has one anyway, that body must be ignored: any entity headers that might describe the erroneous body are instead assumed to describe the response which a similar GET request would have received.

From MDN.

adambabik avatar Feb 22 '21 23:02 adambabik