@@ -28,6 +28,7 @@ import (
2828 "fmt"
2929 "reflect"
3030 "strconv"
31+ "strings"
3132 "time"
3233
3334 "github.com/arangodb/go-driver/util"
@@ -66,6 +67,7 @@ const (
6667 keyOverwrite ContextKey = "arangodb-overwrite"
6768 keyUseQueueTimeout ContextKey = "arangodb-use-queue-timeout"
6869 keyMaxQueueTime ContextKey = "arangodb-max-queue-time-seconds"
70+ keyDriverFlags ContextKey = "arangodb-driver-flags"
6971)
7072
7173type OverwriteMode string
@@ -274,6 +276,11 @@ func WithOverwrite(parent context.Context) context.Context {
274276 return context .WithValue (contextOrBackground (parent ), keyOverwrite , true )
275277}
276278
279+ // WithDriverFlags is used to configure additional flags for the `x-arango-driver` header.
280+ func WithDriverFlags (parent context.Context , value []string ) context.Context {
281+ return context .WithValue (contextOrBackground (parent ), keyDriverFlags , value )
282+ }
283+
277284type contextSettings struct {
278285 Silent bool
279286 WaitForSync bool
@@ -322,6 +329,19 @@ func setDirtyReadFlagIfRequired(ctx context.Context, wasDirty bool) {
322329 }
323330}
324331
332+ // ApplyVersionHeader adds the driver version to the request.
333+ func ApplyVersionHeader (ctx context.Context , req Request ) {
334+ val := fmt .Sprintf ("go-driver-v1/%s" , driverVersion )
335+ if ctx != nil {
336+ if v := ctx .Value (keyDriverFlags ); v != nil {
337+ if flags , ok := v .([]string ); ok {
338+ val = fmt .Sprintf ("%s (%s)" , val , strings .Join (flags , "," ))
339+ }
340+ }
341+ }
342+ req .SetHeader ("x-arango-driver" , val )
343+ }
344+
325345// applyContextSettings returns the settings configured in the context in the given request.
326346// It then returns information about the applied settings that may be needed later in API implementation functions.
327347func applyContextSettings (ctx context.Context , req Request ) contextSettings {
0 commit comments