github.com/hms58/moby@v1.13.1/api/server/middleware/experimental.go (about)

     1  package middleware
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"golang.org/x/net/context"
     7  )
     8  
     9  // ExperimentalMiddleware is a the middleware in charge of adding the
    10  // 'Docker-Experimental' header to every outgoing request
    11  type ExperimentalMiddleware struct {
    12  	experimental string
    13  }
    14  
    15  // NewExperimentalMiddleware creates a new ExperimentalMiddleware
    16  func NewExperimentalMiddleware(experimentalEnabled bool) ExperimentalMiddleware {
    17  	if experimentalEnabled {
    18  		return ExperimentalMiddleware{"true"}
    19  	}
    20  	return ExperimentalMiddleware{"false"}
    21  }
    22  
    23  // WrapHandler returns a new handler function wrapping the previous one in the request chain.
    24  func (e ExperimentalMiddleware) WrapHandler(handler func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error) func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
    25  	return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
    26  		w.Header().Set("Docker-Experimental", e.experimental)
    27  		return handler(ctx, w, r, vars)
    28  	}
    29  }