github.com/xraypb/xray-core@v1.6.6/common/protocol/context.go (about)

     1  package protocol
     2  
     3  import (
     4  	"context"
     5  )
     6  
     7  type key int
     8  
     9  const (
    10  	requestKey key = iota
    11  )
    12  
    13  func ContextWithRequestHeader(ctx context.Context, request *RequestHeader) context.Context {
    14  	return context.WithValue(ctx, requestKey, request)
    15  }
    16  
    17  func RequestHeaderFromContext(ctx context.Context) *RequestHeader {
    18  	request := ctx.Value(requestKey)
    19  	if request == nil {
    20  		return nil
    21  	}
    22  	return request.(*RequestHeader)
    23  }