I am having some trouble when trying to read request headers in my NGINX configuration, there are being sent from my gRPC client. The other parts of my configuration works as expected, and I have data flowing from client to server and back using gRPC. Only this part doesn’t work for me for some reason.
I don’t know if this is related, but I was able to write “headers” back to the client using add_trailer
in NGINX, and the grpc.Trailer
on the client side.
I am using OpenResty docker image.
This is how I write the headers in the client:
import (
"google.golang.org/grpc/metadata"
)
// ...
ctx = metadata.AppendToOutgoingContext(ctx, "custom-header-name", "foobar")
client.MyRpcCall(ctx)
// ...
And this is how I’ve tried to read them in the NGINX lua block:
// 1.
local headers = ngx.req.get_headers()
for k, v in pairs(headers) do
ngx.log(ngx.ERR, "got header: ", k, ":", v)
end
// My header was not logged :(
// 2.
local customHeader = headers["custom-header-name"]
I have also tried to add the grpc_pass_header custom-header-name;
and set $value $http_custom_header_name;
Thanks in advance!
Ben Zini is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.