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

add user-agent header in register sip msg. #163

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

daimon99
Copy link

With this patch, you now can add User-Agent header in register sip message.

ua, _ := sipgo.NewUA(
sipgo.WithUserAgent(username),
sipgo.WithUserAgentHeader(useragent),
sipgo.WithUserAgentHostname("localhost"),
)

@emiago
Copy link
Owner

emiago commented Dec 13, 2024

Hi @daimon99 . Thanks for taking you time and effort on making this.

Still I see here breaking change WithUserAgent(username, uaHeader string) UserAgentOption

On other hand this is not per RFC required header, although sometimes I see mostly provided.
I would like to avoid polluting SIP lib with optional things, but I understand this.

I need to think about this is it worth merging. Still consider to fix that break change, as it does not match your comment?
There is also no need to create special header type, or do you see different? There is GenericHeader type for all this string.

Fast reference is also thing we need to avoid adding (memory allocs -> GC)

@daimon99
Copy link
Author

daimon99 commented Dec 14, 2024

Sorry, I accidentally left out a part of the code in my previous submission. Additionally, I did not notice the existence of the NewHeader method. The background for this PR is as follows:

  1. The current withUserAgent(name) method can be misleading, as it suggests that it constructs a header with the User-Agent information, but in fact, it does not. This can cause confusion. I only realized after reading the source code that this refers to the user's authentication username, not the value of the User-Agent.

  2. I need to submit a User-Agent header in the register method, but I couldn't find a corresponding method in the existing framework, so I ended up reinventing the wheel. Following your advice, I'll check again to see if the current framework can meet my needs. If necessary, I will submit another PR.

I agree with your performance-first approach; it should always have a purpose.

@emiago
Copy link
Owner

emiago commented Dec 14, 2024

Hi @daimon99 ,

Just to be clear this is your user to identify on From. Could be called just User, but it is not Username for auth.
On digest you can have different username. This is just your some ID.
So I agree naming could be better, probably as UserID, UserHostname.

I may see like need to provide this kind of additional headers on each request, so I would like to think this feature more from client perspective. In short anyone can wrap client Do, TransactionRequest but could be worth a while to have it in a lib.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants