$grpc_internal_trailers

The variable $grpc_internal_trailers contains the internal trailer fields of a gRPC response. — NGINX Core (HTTP)

$grpc_internal_trailers NGINX Core (HTTP)

Description

The $grpc_internal_trailers variable is utilized within the context of gRPC protocols to provide access to the trailer fields of a gRPC response. Trailers in gRPC are key-value pairs that can be sent at the end of a response, similar to HTTP headers, allowing additional metadata to be communicated alongside the response body. This variable is only populated when the server processes a gRPC request and is capable of handling trailer fields. When processing a gRPC response, if the relevant trailer information is set to be included, it becomes accessible through $grpc_internal_trailers. Therefore, this variable will typically contain a string representation of the trailer fields formatted similarly to HTTP headers, separated by commas or newlines. If the request does not return any trailers, this variable will remain empty. The use of trailers can enhance the efficiency of the communication by allowing the server to send significant information along with the response without adding additional overhead to the body.

Config Example

location /example {
    grpc_pass grpc://backend;
    add_header Trailer 'grpc-status';
    set $status $grpc_internal_trailers;
}

Subsystem

http

Cacheable

No

Contexts

http, server, location

Ensure that your upstream gRPC server actually sets the trailers, otherwise the variable will be empty.

Avoid using $grpc_internal_trailers in contexts where gRPC is not being used, as it will not be populated.