Closed allsilaevex closed 2 years ago
I have the following web client code (ts)
import { Request, UnaryResponse, UnaryInterceptor } from 'grpc-web'; type MyInterceptorRequest = Request<MyRequest, MyResponse>; type MyInterceptorUnaryResponse = UnaryResponse<MyRequest, MyResponse>; class MyInterceptor implements UnaryInterceptor<MyRequest, MyResponse> { intercept(request: MyInterceptorRequest, invoker: (request: MyInterceptorRequest) => Promise<MyInterceptorUnaryResponse>) { console.log('[interceptor] before', request.getRequestMessage()); return invoker(request).then((response: MyInterceptorUnaryResponse) => { console.log('[interceptor] after', response.getMetadata(), response.getStatus() ? response.getStatus().metadata : null); return response; }); }; } const myAPIPromiseClient = new MyAPIPromiseClient(String(process.env.API_HOST), null, { unaryInterceptors: [new MyInterceptor()] }); (async () => { try { const response = await myAPIPromiseClient.myProcedure(new MyRequest(), undefined); console.log(response); } catch (err) { console.error(err); } })();
and the following response from the server (php swoole) with my custom header
But I can't get that header, only two standard ones are returned
What am I doing wrong?
I found the problem. It is necessary to add an Access-Control-Expose-Headers header with a list of header names that must appeared in the metadata.
Access-Control-Expose-Headers
I have the following web client code (ts)
and the following response from the server (php swoole) with my custom header
But I can't get that header, only two standard ones are returned
What am I doing wrong?