Skip to content

Add 'te: trailers' header as required per gRPC spec and needed for the python server impl #2

@SergejKasper

Description

@SergejKasper

I had an issue to connect to a python grpc server as the te: trailers header was missing.
The TE request header specifies the transfer encodings the user agent is willing to accept
As gRPC uses trailers, this needs to be set by the proxy to trailers

The following fixed the issue for me:

  const app = connect();
  const corsOptions = {
    exposedHeaders: 'grpc-status,grpc-message',
    methods: 'POST',
    credentials: true,
  };;
  app.use((req, res, next) => {
    req.headers['te'] = 'trailers';     // <--- pass necessary header 
    next();
  })
  app.use(cors(corsOptions));
  app.use(grpcWeb(`http://0.0.0.0:${sourcePort}`));
  return app.listen(destPort);

essentially you could either add this middleware or provide users an ability to add preceding middleware by adjusting the proxy function:

const proxy = ({ target, origin, headers, middlewares } = {}) => {
  const app = connect();
  const corsOptions = getCorsOptions({ origin, headers });
  (middlewares || []).forEach(middleware => {
    app.use(middleware)
  });
  app.use(cors(corsOptions));
  app.use(grpcWeb(target));
  return app;
};

I am willing to provide a PR for either

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions