Allow injecting a custom HTTP transport into the SSE client - #105
Conversation
|
| transportToUse := o.transport | ||
| if transportToUse == nil { | ||
| t := http.DefaultTransport.(*http.Transport).Clone() | ||
| t.Proxy = http.ProxyFromEnvironment |
There was a problem hiding this comment.
Are we sure this line needs to go in here?
There was a problem hiding this comment.
Yes, it has to. That if builds the default transport, and Proxy = ProxyFromEnvironment is part of it
There was a problem hiding this comment.
i think it's ok to be able to configure it, but you'll have to make sure you set it whenever passing a custom transport layer from one of our apps, since all of them are expected to honor that env var.
There was a problem hiding this comment.
Agreed. Our only custom transport caller (go-split-commons NewStreamingClient) already sets transport.Proxy = http.ProxyFromEnvironment, so the env var is honored there too. I'll keep that as the rule for any future app-side transport
| transportToUse := o.transport | ||
| if transportToUse == nil { | ||
| t := http.DefaultTransport.(*http.Transport).Clone() | ||
| t.Proxy = http.ProxyFromEnvironment |
There was a problem hiding this comment.
i think it's ok to be able to configure it, but you'll have to make sure you set it whenever passing a custom transport layer from one of our apps, since all of them are expected to honor that env var.





What
Adds a functional-options parameter to sse.NewClient and a WithCustomTransport(http.RoundTripper) option, letting callers supply the HTTP transport used for the SSE connection. When no option is passed, behavior is unchanged (a cloned http.DefaultTransport with ProxyFromEnvironment).
Why
Consumers (e.g. go-split-commons) need to control the streaming connection's transport — specifically to pin the SSE connection to HTTP/1.1 and avoid Go's http2 client stack, which emits noisy protocol error: received DATA after END_STREAM logs on the long-lived stream. Rather than baking that policy into the toolkit, this exposes a generic hook so callers decide the transport.
Changes
Compatibility
Non-breaking: NewClient's new parameter is variadic, so existing call sites compile and behave unchanged. No go.mod changes.
Testing
go build ./... and go test ./sse/... pass.