how to specific a particular header is required

361 views
Skip to first unread message

David Lei

unread,
Jan 19, 2023, 8:27:45 PM1/19/23
to Protocol Buffers
Hi all!

I'm learning how to use proto buffers to define an RPC how can I specify in my.proto file a HTTP header is required e.g.

// This needs the Auth header to be present to do something sensible https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization
rpc DoThing(DoThingReq) returns (DoThingRes) {
}

Thanks!
David 

Claude Robitaille

unread,
Jan 20, 2023, 9:17:40 AM1/20/23
to Protocol Buffers
protobuf has nothing to do with http. It is just a message modelling system where the library will build and validate messages. And provide access to the data.

So, in your case, without actually rely understanding what you are doing, thre could be different approach

1 - You could define/model a message type that includes all the http header you fell are mandatory. And then include that message into some request message this passed to your RPC code. he header sub-message is then analysed by your code.
2 - Or you could lists all the headers, by name, into a repeat filed of the request message. Again, your RPC code would verify that the headers are present in the HTTP object is processes.

I am sure many other way of handling this are possible.
Reply all
Reply to author
Forward
0 new messages