Skip to content

Add server URL normalization for flexible server_url input#122

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

Add server URL normalization for flexible server_url input#122
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") as server_url when constructing the SDK client. This is part of promoting server_url as the primary configuration option, replacing instance in all documentation and examples.

Python-specific implementation

Uses Speakeasy's SDKInit hook mechanism (src/glean/api_client/_hooks/server_url_normalizer.py). 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 Python SDK passes raw strings to the SDKInit hook (unlike TypeScript which passes parsed URL objects).

The hook is registered in registration.py 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:
glean = Glean(server_url="mycompany-be.glean.com")
glean = Glean(server_url="https://mycompany-be.glean.com")
glean = Glean(server_url="https://mycompany-be.glean.com/")

Backwards compatibility

The instance parameter continues to work unchanged. No breaking changes.

Test plan

  • 13 unit tests pass covering normalization logic and hook integration

Prepends https:// to server URLs when no scheme is provided and strips
trailing slashes, improving developer experience for 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