Skip to content

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