mirror of
https://github.com/luxfi/sdk.git
synced 2026-10-30 15:19:23 +00:00
40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package connectclient
|
|
|
|
import (
|
|
"context"
|
|
|
|
"connectrpc.com/connect"
|
|
|
|
apitypes "github.com/luxfi/api/types"
|
|
)
|
|
|
|
var _ connect.Interceptor = (*SetRouteHeaderInterceptor)(nil)
|
|
|
|
// SetRouteHeaderInterceptor sets the api routing header for connect-rpc
|
|
// requests
|
|
type SetRouteHeaderInterceptor struct {
|
|
Route string
|
|
}
|
|
|
|
func (s SetRouteHeaderInterceptor) WrapUnary(next connect.UnaryFunc) connect.UnaryFunc {
|
|
return func(ctx context.Context, request connect.AnyRequest) (connect.AnyResponse, error) {
|
|
request.Header().Set(apitypes.HTTPHeaderRoute, s.Route)
|
|
return next(ctx, request)
|
|
}
|
|
}
|
|
|
|
func (s SetRouteHeaderInterceptor) WrapStreamingClient(next connect.StreamingClientFunc) connect.StreamingClientFunc {
|
|
return func(ctx context.Context, spec connect.Spec) connect.StreamingClientConn {
|
|
conn := next(ctx, spec)
|
|
conn.RequestHeader().Set(apitypes.HTTPHeaderRoute, s.Route)
|
|
return conn
|
|
}
|
|
}
|
|
|
|
func (SetRouteHeaderInterceptor) WrapStreamingHandler(next connect.StreamingHandlerFunc) connect.StreamingHandlerFunc {
|
|
return next
|
|
}
|