Skip to content

Updated transport layer#58

Merged
djthorpe merged 8 commits intomainfrom
djt/0303/transport
Mar 3, 2026
Merged

Updated transport layer#58
djthorpe merged 8 commits intomainfrom
djt/0303/transport

Conversation

@djthorpe
Copy link
Member

@djthorpe djthorpe commented Mar 3, 2026

This pull request makes significant improvements to the go-client library, especially around transport middleware, streaming support, and documentation. The changes introduce new options for plugging in HTTP middleware, improve rate limiting, enhance streaming event handling, and update the documentation to reflect these features.

The most important changes are:

Transport Middleware and Client Options:

  • Added support for composable HTTP transport middleware via the new OptTransport (client-wide) and OptReqTransport (per-request) options, allowing users to easily add logging, tracing, and custom middleware. The documentation now highlights these options and provides usage examples. The deprecated OptTrace is now documented as such and points users to the new middleware approach. [1] [2] [3] [4]
  • Updated the OpenTelemetry integration to prefer explicit middleware composition using OptTransport and transport.NewTransport, and improved the related documentation and examples. [1] [2] [3]

Streaming and SSE Improvements:

  • Enhanced support for Server-Sent Events (SSE) and NDJSON streams: the client now sets appropriate headers to prevent proxy buffering, and the documentation explains how to handle reconnects and event IDs. [1] [2]
  • Improved the TextStreamEvent documentation, detailing its fields and usage patterns for robust SSE handling.

Rate Limiting and Request Handling:

  • Refactored rate limiting logic into a new waitRateLimit method that is context-aware, allowing cancellation via context and improving code clarity. [1] [2] [3]
  • Improved per-request option handling by making shallow copies of the HTTP client to safely support per-request timeout and transport changes without mutexes or side effects. [1] [2]

Content-Type Handling and Decoding:

  • Improved content-type parsing and decoding logic by using shared type constants and a helper for parsing content types. Added explicit handling for decoding text/plain responses into string, []byte, or io.Writer types. [1] [2] [3] [4]

Documentation Updates:

  • Updated the README with detailed explanations and examples for new features, including transport middleware, streaming, and OpenTelemetry integration. Improved clarity and accuracy for OAuth usage and other client options. [1] [2] [3]

These changes make the library more flexible, robust, and easier to use, especially for advanced HTTP client scenarios.

@djthorpe djthorpe self-assigned this Mar 3, 2026
Copilot AI review requested due to automatic review settings March 3, 2026 15:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR modernizes the go-client transport layer by introducing composable http.RoundTripper middleware, improving streaming (SSE/NDJSON) handling, and updating docs/examples to match the new patterns.

Changes:

  • Introduces pkg/transport middleware (logging, recorder, OTel transport) and hooks to apply middleware client-wide (OptTransport) or per-request (OptReqTransport).
  • Improves streaming/SSE ergonomics (reconnect state in TextStream) and adds anti-buffering headers for SSE/NDJSON requests.
  • Refactors rate limiting to be context-aware and adjusts decoding/content-type utilities and documentation.

Reviewed changes

Copilot reviewed 21 out of 22 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
transport.go Removes old in-package logging transport implementation (replaced by pkg/transport).
clientopts.go Adds OptTransport; updates OptTrace to use transport.NewLogging; switches option errors to httpresponse.
requestopts.go Adds per-request transport middleware option (OptReqTransport); switches option errors to httpresponse.
client.go Adds context-aware rate limiting helper, anti-buffering headers for streams, per-request shallow client copy + per-request transport wrapping, and text/plain decoding support.
textstream.go Enhances SSE parsing and adds reconnect state (LastEventID, RetryDuration).
token.go Changes Token.String() behavior for empty values.
payload.go Adds MethodHead.
oauthflow.go Refactors OAuth flow to accept context per method (instead of storing it).
pkg/transport/logging.go New logging RoundTripper middleware (including streaming SSE logging).
pkg/transport/recorder.go New recorder RoundTripper middleware for status/header capture.
pkg/transport/otel.go Moves HTTP client tracing RoundTripper into pkg/transport.
pkg/transport/*.go tests Adds tests for new middleware.
pkg/otel/span.go Adjusts OpenTelemetry imports (aliases).
README.md Updates docs for middleware, streaming, OAuth flow, and OTel usage patterns.
go.mod / go.sum Removes github.com/gogo/protobuf dependency entry.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 22 out of 23 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@djthorpe djthorpe merged commit 530edb3 into main Mar 3, 2026
3 checks passed
@djthorpe djthorpe deleted the djt/0303/transport branch March 3, 2026 17:29
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.

2 participants