Skip to content

Add server URL normalization for flexible WithServerURL input#81

Merged
chris-freeman-glean merged 3 commits intomainfrom
cfreeman/server-url-normalization
Mar 4, 2026
Merged

Add server URL normalization for flexible WithServerURL input#81
chris-freeman-glean merged 3 commits intomainfrom
cfreeman/server-url-normalization

Conversation

@chris-freeman-glean
Copy link
Contributor

Summary

Adds server URL normalization so users can pass schemeless URLs (e.g., "mycompany-be.glean.com") to WithServerURL() when constructing the SDK client. This is part of promoting WithServerURL() as the primary configuration option, replacing WithInstance() in all documentation and examples.

Go-specific implementation

Uses Speakeasy's SDKInit hook mechanism (internal/hooks/server_url_normalizer.go). The hook receives the raw server URL string during SDK initialization and normalizes it before it's used for requests. This is the standard approach — the Go SDK passes raw strings to the SDKInit hook.

The hook is registered in registration.go as the first hook to run during initialization.

Normalization rules

  • No scheme → prepend https://
  • http:// preserved (for localhost/dev)
  • https:// preserved
  • Trailing slashes stripped

User-facing API

// All of these now work identically:
client := glean.New(glean.WithServerURL("mycompany-be.glean.com"))
client := glean.New(glean.WithServerURL("https://mycompany-be.glean.com"))
client := glean.New(glean.WithServerURL("https://mycompany-be.glean.com/"))

Backwards compatibility

The WithInstance() option continues to work unchanged. No breaking changes.

Test plan

  • 7 table-driven tests pass covering normalization logic and hook integration

Prepend https:// when no scheme is provided and strip trailing slashes
from the base URL during SDK initialization.
@chris-freeman-glean chris-freeman-glean marked this pull request as ready for review March 3, 2026 22:38
@chris-freeman-glean chris-freeman-glean requested a review from a team as a code owner March 3, 2026 22:38
Update the two code examples in the Experimental Features section
(hand-authored, outside Speakeasy markers) from WithInstance to
WithServerURL. The Speakeasy-managed sections will auto-update on regen.
@chris-freeman-glean chris-freeman-glean merged commit e8e5fdb into main Mar 4, 2026
2 checks passed
@chris-freeman-glean chris-freeman-glean deleted the cfreeman/server-url-normalization branch March 4, 2026 17:15
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.

1 participant