// New creates a new Cors handler with the provided options.
556794
func NewCors(options Options) *Cors {
	c := &Cors{
		exposedHeaders:    convert(options.ExposedHeaders, http.CanonicalHeaderKey),
		allowOriginFunc:   options.AllowOriginFunc,
		allowCredentials:  options.AllowCredentials,
		maxAge:            options.MaxAge,
		optionPassthrough: options.OptionsPassthrough,
	}
	if options.Debug {
		c.Log = log.New(os.Stdout, "[cors] ", log.LstdFlags)
	}

	// Normalize options
	// Note: for origins and methods matching, the spec requires a case-sensitive matching.
	// As it may error prone, we chose to ignore the spec here.

	// Allowed Origins
	if len(options.AllowedOrigins) == 0 {
		// Default is all origins
		c.allowedOriginsAll = true
	} else {
		c.allowedOrigins = []string{}
		c.allowedWOrigins = []wildcard{}
		for _, origin := range options.AllowedOrigins {
			// Normalize
			origin = strings.ToLower(origin)
			if origin == "*" {
				// If "*" is present in the list, turn the whole list into a match all
				c.allowedOriginsAll = true
				c.allowedOrigins = nil
				c.allowedWOrigins = nil
				break
			} else if i := strings.IndexByte(origin, '*'); i >= 0 {
				// Split the origin in two: start and end string without the *
				w := wildcard{origin[0:i], origin[i+1 : len(origin)]}
				c.allowedWOrigins = append(c.allowedWOrigins, w)
			} else {
				c.allowedOrigins = append(c.allowedOrigins, origin)
			}
		}
	}

	// Allowed Headers
	if len(options.AllowedHeaders) == 0 {
		// Use sensible defaults
		c.allowedHeaders = []string{"Origin", "Accept", "Content-Type"}
	} else {
		// Origin is always appended as some browsers will always request for this header at preflight
		c.allowedHeaders = convert(append(options.AllowedHeaders, "Origin"), http.CanonicalHeaderKey)
		for _, h := range options.AllowedHeaders {
			if h == "*" {
				c.allowedHeadersAll = true
				c.allowedHeaders = nil
				break
			}
		}
	}

	// Allowed Methods
	if len(options.AllowedMethods) == 0 {
		// Default is spec's "simple" methods
		c.allowedMethods = []string{"GET", "POST"}
	} else {
		c.allowedMethods = convert(options.AllowedMethods, strings.ToUpper)
	}

	return c
}
708393
func New(endpoint *url.URL, client *http.Client) *Client {
	if client == nil {
		client = http.DefaultClient
	}

	if len(endpoint.Path) > 0 && !strings.HasSuffix(endpoint.Path, "/") {
		endpoint.Path = endpoint.Path + "/"
	}

	return &Client{client, endpoint, make(http.Header), endpoint.Query(), noOpCacher}
}
311228
func New(u *url.URL, settings []vim.BaseOptionValue) (string, http.Handler) {
	for i := range settings {
		setting := settings[i].GetOptionValue()
		if setting.Key == "config.vpxd.sso.sts.uri" {
			endpoint, _ := url.Parse(setting.Value.(string))
			endpoint.Host = u.Host
			setting.Value = endpoint.String()
			settings[i] = setting
			return endpoint.Path, new(handler)
		}
	}
	return "", nil
}
462973
func New(host string, transport *http.Transport) types.APIClient {
	return &client{
		Client: http.Client{
			Transport: transport,
		},
		host: host,
	}
}
897598
func New(bindAddr string, router http.Handler) *Server {
	middleware := map[string]alice.Constructor{
		RequestIDHandlerKey: requestID.Handler(16),
		LogHandlerKey:       log.Handler,
	}

	return &Server{
		Alice:           nil,
		Middleware:      middleware,
		MiddlewareOrder: []string{RequestIDHandlerKey, LogHandlerKey},
		Server: http.Server{
			Handler:           router,
			Addr:              bindAddr,
			ReadTimeout:       5 * time.Second,
			WriteTimeout:      10 * time.Second,
			ReadHeaderTimeout: 0,
			IdleTimeout:       0,
			MaxHeaderBytes:    0,
		},
		HandleOSSignals:        true,
		DefaultShutdownTimeout: 10 * time.Second,
	}
}
569682
func New(token string, options ...Option) *Client {
	s := &Client{
		token:      token,
		endpoint:   APIURL,
		httpclient: &http.Client{},
		log:        log.New(os.Stderr, "nlopes/slack", log.LstdFlags|log.Lshortfile),
	}

	for _, opt := range options {
		opt(s)
	}

	return s
}
332478
func New(c Config) func(http.Handler) http.Handler {
	if c.Skipper == nil {
		c.Skipper = DefaultConfig.Skipper
	}
	if c.Indexer == nil {
		c.Indexer = DefaultConfig.Indexer
	}
	if c.Invalidator == nil {
		c.Invalidator = DefaultConfig.Invalidator
	}
	if c.SkipHeaders == nil {
		c.SkipHeaders = DefaultConfig.SkipHeaders
	}

	var (
		l     = &sync.RWMutex{}
		cache = make(map[interface{}]*item)
	)

	if c.Invalidator != nil {
		go func() {
			for {
				p := <-c.Invalidator
				l.Lock()
				if _, ok := p.(invalidateAll); ok {
					cache = make(map[interface{}]*item)
				} else {
					delete(cache, p)
				}
				l.Unlock()
			}
		}()
	}

	return func(h http.Handler) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			if c.Skipper(r) {
				h.ServeHTTP(w, r)
				return
			}

			p := c.Indexer(r)
			l.RLock()
			if ci := cache[p]; ci != nil {
				l.RUnlock()
				wh := w.Header()
				for k, vs := range ci.header {
					if !c.SkipHeaders(k) {
						wh[k] = vs
					}
				}

				// check Last-Modified
				if !ci.modTime.IsZero() {
					if ts := r.Header.Get(header.IfModifiedSince); len(ts) > 0 {
						t, _ := http.ParseTime(ts)
						if ci.modTime.Equal(t) {
							wh.Del(header.ContentType)
							wh.Del(header.ContentLength)
							wh.Del(header.AcceptRanges)
							w.WriteHeader(http.StatusNotModified)
							return
						}
					}
				}

				w.Header().Set("X-Cache", "HIT")
				io.Copy(w, bytes.NewReader(ci.data))
				return
			}
			l.RUnlock()
			w.Header().Set("X-Cache", "MISS")
			cw := &responseWriter{
				ResponseWriter: w,
				cache:          &bytes.Buffer{},
			}
			h.ServeHTTP(cw, r)

			// cache only status ok
			if cw.code == http.StatusOK {
				l.Lock()
				cache[p] = createItem(cw)
				l.Unlock()
			}
		})
	}
}
232088
func New(options ...Options) *Render {
	var o Options
	if len(options) > 0 {
		o = options[0]
	}

	r := Render{
		opt: o,
	}

	r.prepareOptions()
	r.compileTemplates()

	return &r
}
294564
func New(impl Interface, opts ...thrift.RegisterOption) []transport.Procedure {
	h := handler{impl}
	service := thrift.Service{
		Name: "SecondService",
		Methods: []thrift.Method{

			thrift.Method{
				Name: "blahBlah",
				HandlerSpec: thrift.HandlerSpec{

					Type:  transport.Unary,
					Unary: thrift.UnaryHandler(h.BlahBlah),
				},
				Signature:    "BlahBlah()",
				ThriftModule: gauntlet.ThriftModule,
			},

			thrift.Method{
				Name: "secondtestString",
				HandlerSpec: thrift.HandlerSpec{

					Type:  transport.Unary,
					Unary: thrift.UnaryHandler(h.SecondtestString),
				},
				Signature:    "SecondtestString(Thing *string) (string)",
				ThriftModule: gauntlet.ThriftModule,
			},
		},
	}

	procedures := make([]transport.Procedure, 0, 2)
	procedures = append(procedures, thrift.BuildProcedures(service, opts...)...)
	return procedures
}
772295
func New(token, environment, codeVersion, serverHost, serverRoot string) *Handler {
	return NewFromClient(rollbar.New(token, environment, codeVersion, serverHost, serverRoot))
}
835915
func New(err error) HandlerError {
	return HandlerError{Err: err, Stack: debug.Stack()}
}
782686
func New(ctx context.Context, next http.Handler, name string) (http.Handler, error) {
	middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")

	return &compress{
		next: next,
		name: name,
	}, nil
}
1304875
func New(ctx context.Context, next http.Handler, config config.ReplacePath, name string) (http.Handler, error) {
	middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")

	return &replacePath{
		next: next,
		path: config.Path,
		name: name,
	}, nil
}
1302736
func New(
	ctx context.Context,
	host, user, pass, group string,
	opts *ClientOptions) (Client, error) {

	if host == "" || user == "" || pass == "" {
		return nil, errNewClient
	}

	c := &client{
		host: host,
		user: user,
		grup: group,
		auth: fmtAuthHeaderVal(user, pass),
		volp: defaultVolumesPath,
	}

	c.http = &http.Client{}

	if opts != nil {
		if opts.VolumesPath != "" {
			c.volp = opts.VolumesPath
		}

		if opts.Timeout != 0 {
			c.http.Timeout = opts.Timeout
		}

		if opts.Insecure {
			c.http.Transport = &http.Transport{
				TLSClientConfig: &tls.Config{
					InsecureSkipVerify: true,
				},
			}
		}
	}

	resp := &apiVerResponse{}
	if err := c.Get(ctx, "/platform/latest", "", nil, nil, resp); err != nil &&
		!strings.HasPrefix(err.Error(), "json: ") {
		return nil, err
	}

	if resp.Latest != nil {
		i, err := strconv.ParseUint(*resp.Latest, 10, 8)
		if err != nil {
			return nil, err
		}
		c.apiv = uint8(i)
	} else {
		c.apiv = 2
	}

	return c, nil
}
548477
func New(client RedisClient, key string, opts *Options) *Locker {
	var o Options
	if opts != nil {
		o = *opts
	}
	o.normalize()

	return &Locker{client: client, key: key, opts: o}
}
687945
func New(opts ...Opt) *Client {
	c := &Client{
		codec:       DefaultCodec,
		do:          With(DefaultConfigOpt...),
		header:      cloneHeaders(DefaultHeaders),
		errorMapper: DefaultErrorMapper,
	}
	c.buildRequestFunc = c.buildRequest
	c.handleResponse = c.HandleResponse
	c.With(opts...)
	return c
}
370435
func New(options ...Options) *Secure {
	var o Options
	if len(options) == 0 {
		o = Options{}
	} else {
		o = options[0]
	}

	o.ContentSecurityPolicy = strings.Replace(o.ContentSecurityPolicy, "$NONCE", "'nonce-%[1]s'", -1)

	o.nonceEnabled = strings.Contains(o.ContentSecurityPolicy, "%[1]s")

	s := &Secure{
		opt:            o,
		badHostHandler: http.HandlerFunc(defaultBadHostHandler),
	}

	if s.opt.AllowedHostsAreRegex {
		// Test for invalid regular expressions in AllowedHosts
		for _, allowedHost := range o.AllowedHosts {
			regex, err := regexp.Compile(fmt.Sprintf("^%s$", allowedHost))
			if err != nil {
				panic(fmt.Sprintf("Error parsing AllowedHost: %s", err))
			}
			s.cRegexAllowedHosts = append(s.cRegexAllowedHosts, regex)
		}
	}

	return s
}