Add projects
This commit is contained in:
parent
2d3a9ad623
commit
8b607dd700
1802 changed files with 503346 additions and 2 deletions
42
backend/sdk/cliproxy/executor/context.go
Normal file
42
backend/sdk/cliproxy/executor/context.go
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
package executor
|
||||
|
||||
import "context"
|
||||
|
||||
type downstreamWebsocketContextKey struct{}
|
||||
type requireUpstreamWebsocketContextKey struct{}
|
||||
|
||||
// WithDownstreamWebsocket marks the current request as coming from a downstream websocket connection.
|
||||
func WithDownstreamWebsocket(ctx context.Context) context.Context {
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
return context.WithValue(ctx, downstreamWebsocketContextKey{}, true)
|
||||
}
|
||||
|
||||
// DownstreamWebsocket reports whether the current request originates from a downstream websocket connection.
|
||||
func DownstreamWebsocket(ctx context.Context) bool {
|
||||
if ctx == nil {
|
||||
return false
|
||||
}
|
||||
raw := ctx.Value(downstreamWebsocketContextKey{})
|
||||
enabled, ok := raw.(bool)
|
||||
return ok && enabled
|
||||
}
|
||||
|
||||
// WithRequiredUpstreamWebsocket marks a request whose incremental context is valid only on the current upstream websocket.
|
||||
func WithRequiredUpstreamWebsocket(ctx context.Context) context.Context {
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
return context.WithValue(ctx, requireUpstreamWebsocketContextKey{}, true)
|
||||
}
|
||||
|
||||
// RequiredUpstreamWebsocket reports whether falling back to an HTTP upstream would lose request context.
|
||||
func RequiredUpstreamWebsocket(ctx context.Context) bool {
|
||||
if ctx == nil {
|
||||
return false
|
||||
}
|
||||
raw := ctx.Value(requireUpstreamWebsocketContextKey{})
|
||||
enabled, ok := raw.(bool)
|
||||
return ok && enabled
|
||||
}
|
||||
Loading…
Reference in a new issue