如何解决访问Grpc服务器中的HTTP2标头
我正在用C ++构建grpc服务器,并且试图从HTTP标头中获取“主机”,但是我没有找到对其的任何访问。
这是我的服务器实现:
service RemoteService {
rpc ListKeys(google.protobuf.Empty) returns (ListKeysResponse) {
option (google.api.http) = {
get: "/listkeys"
};
}
}
class ServiceImpl final : public GrpcApi::RemoteService::Service {
Status ListKeys(ServerContext* context,const ::google::protobuf::Empty* request,::GrpcApi::ListKeysResponse* response) override {
std::cout << "context->peer()" << context->peer();
std::cout << "context->auth_context()->GetPeerIdentity(): " << context->auth_context()->GetPeerIdentity();
std::cout << "context->auth_context()->GetPeerIdentityPropertyName()" << context->auth_context()->GetPeerIdentityPropertyName();
for(auto i = context->auth_context()->begin(); i != context->auth_context()->end(); i ++) {
std::cout << "key: " << i.operator*().first << " --- val: " << i.operator*().second;
}
for(auto [k,v] : context->client_metadata()) {
std::cout << "k : " << k << " --- v : " << v;
}
return Status::OK;
}
}
在尝试查找所需信息时,我打印了一些ServerContext参数,这是上面代码的输出:
context->peer()ipv6:[::1]:43754
context->auth_context()->GetPeerIdentity(): []
context->auth_context()->GetPeerIdentityPropertyName()
k : user-agent --- v : grpc-c++/1.30.0 grpc-c/10.0.0 (linux; chttp2)
在钢丝绳上,我看到了:
............ @ ..... @ ...... .................?.... ...... PRI * HTTP / 2.0
SM
.. $ ..................... @ ..... @ ...... .......... ........ @ :authority.localhost:50051 @ .: path./GrpcApi.RemoteService/ListKeys@.te.trailers@.content-type.application/grpc@ 用户代理grpc-c ++ / 1.30.0 grpc-c / 10.0.0(Linux; chttp2)@。grpc-accept-encoding.identity,deflate,gzip @ .accept-encoding 身份,gzip ...........................................?...... ....................................
我可以从输出中的请求中看到用户代理,但是我看不到“权限”,它正是我需要的主机名。
因此,如果我能以某种方式获得授权,就如同从http标头访问“主机”一样。 问题是我没有成功访问任何一个。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。