Skip to content

Add server URL normalization for flexible WithServerURL input#81

Draft
chris-freeman-glean wants to merge 1 commit intomainfrom
cfreeman/server-url-normalization
Draft

Add server URL normalization for flexible WithServerURL input#81
chris-freeman-glean wants to merge 1 commit 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.
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