0

I have this code to disable client caching for a GET API:

headers := metadata.Pairs(
    "Cache-Control", "no-cache, no-store, must-revalidate",
    "Pragma", "no-cache",
    "Expires", "0",
)
err := grpc.SetHeader(ctx, headers)

When I curl -i the API, the response shows Cache-Control: no-cache, no-store, must-revalidate, but not the Pragma or Expires. I think I'm using the right way to set these. Does GRPC not support certain headers?

onepiece
  • 3,279
  • 8
  • 44
  • 63

1 Answers1

0

I don't think there are any headers limitations (even though maybe problem can be with Pragma, which is HTTP 1.0, see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Pragma). Maybe it's one of these reasons:

  1. you only setHeader, but don't send it, see https://pkg.go.dev/google.golang.org/grpc?tab=doc#SetHeader

All the metadata will be sent out when one of the following happens:

  • grpc.SendHeader() is called;
  • The first response is sent out;
  • An RPC status is sent out (error or success).
  1. maybe curl is missused here, you don't seem to specify --http2 option (see Will I be able to use CURL to get HTTP/2 headers?), maybe you could leverage grpcurl: https://github.com/fullstorydev/grpcurl
dmaixner
  • 808
  • 1
  • 7
  • 16