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

feat: add support for custom user agent #410

Merged
merged 4 commits into from
Jan 6, 2025
Merged

Conversation

jackwotherspoon
Copy link
Collaborator

@jackwotherspoon jackwotherspoon commented Jan 3, 2025

Add support for custom user agent via user agent comments.

HTTP user agent's take the form of <product> / <product-version> <comment>

Previously, we did not allow support for the comment field, leaving no way
to customize a user agent:

userAgentDirectives: [
{
product: 'cloud-sql-nodejs-connector',
version: 'LIBRARY_SEMVER_VERSION',
},

This PR changes that by adding userAgent as a supported ConnectorOptions
which will be passed and used to set the comment field, allowing customizations
to the user agent.

const connector = new Connector({ userAgent: 'custom-agent'})

Closes: #401
Ref: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent

@jackwotherspoon jackwotherspoon self-assigned this Jan 3, 2025
@jackwotherspoon jackwotherspoon requested a review from a team as a code owner January 3, 2025 19:33
@jackwotherspoon
Copy link
Collaborator Author

Manually tested and works:

const connector = new Connector({ userAgent: 'custom-agent'})

Results in follow user agent:

cloud-sql-nodejs-connector/1.5.0 (custom-agent)

@enocom enocom self-requested a review January 6, 2025 19:18
Copy link
Member

@enocom enocom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a perfect adherence to the spec:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent#comment

@jackwotherspoon jackwotherspoon merged commit 25f5ccd into main Jan 6, 2025
26 checks passed
@jackwotherspoon jackwotherspoon deleted the custom-user-agent branch January 6, 2025 19:47
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.

Allow for custom user agents
3 participants