github.com/v2fly/v2ray-core/v5@v5.16.2-0.20240507031116-8191faa6e095/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  }