Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get UserAgent on server side #1100

Closed
dtjm opened this issue Mar 2, 2017 · 2 comments
Closed

How to get UserAgent on server side #1100

dtjm opened this issue Mar 2, 2017 · 2 comments

Comments

@dtjm
Copy link

dtjm commented Mar 2, 2017

How would I access the UserAgent of the client stream in my GRPC server? I can't seem to find any examples or interfaces that would allow this.

@MakMukhi
Copy link
Contributor

MakMukhi commented Mar 2, 2017 via email

@MakMukhi MakMukhi closed this as completed Mar 3, 2017
@bharatnc
Copy link

bharatnc commented Mar 11, 2018

Usually, the user-agent can be included on the client side and extracted from the server side. You can add a user-agent using the WithUserAgent("user-agent") function that grpc provides when making the dial connection.

server := grpc.Dial(grpc_server, WithUserAgent("user-agent",))

On the server side, you can extract it out from the incoming context meta-data:

mD, _ := metadata.FromIncomingContext(ctx)

where mD consists of key,val pairs and the way you would want to get hold of the user-agent is using its's key.

mD["user-agent"]

@lock lock bot locked as resolved and limited conversation to collaborators Sep 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants