// HTTPToContext moves a JWT from request header to context. Particularly
// useful for servers.
325533
func HTTPToContext() http.RequestFunc {
	return func(ctx context.Context, r *stdhttp.Request) context.Context {
		token, ok := extractTokenFromAuthHeader(r.Header.Get("Authorization"))
		if !ok {
			return ctx
		}

		return context.WithValue(ctx, JWTTokenContextKey, token)
	}
}
790792
func GetContext(w http.ResponseWriter) (map[interface{}]interface{}, bool) {
	ctxw, ok := GetResponseWriter(w, func(tst http.ResponseWriter) bool {
		_, ok := tst.(*contextResponseWriter)
		return ok
	})
	if ok {
		return ctxw.(*contextResponseWriter).m, true
	}
	return nil, false
}
387979
func NewContextWithHeaders(ctx context.Context, header http.Header) context.Context {
	if ctx == nil {
		ctx = context.Background()
	}
	return context.WithValue(ctx, requestHeaderKey, header)
}
917867
func (s *ServicesService) GetWithContext(ctx context.Context, idOrName string) (*Service, *http.Response, error) {
	resource, _ := url.Parse(servicesResourcePath)
	resource.Path = path.Join(resource.Path, idOrName)

	req, err := s.client.NewRequest(ctx, http.MethodGet, resource, nil)

	if err != nil {
		return nil, nil, err
	}

	svc := new(Service)

	res, err := s.client.Do(req, svc)

	if err != nil {
		return nil, res, err
	}

	return svc, res, nil
}
1026621
func contextClient(ctx context.Context) *http.Client {
	if ctx != nil {
		if hc, ok := ctx.Value(oauth2.HTTPClient).(*http.Client); ok {
			return hc
		}
	}
	return http.DefaultClient
}
350943
func HeadersFromContext(headers ...string) Handler {
	return Handler{
		Name: "HeadersFromContext",
		Fn: func(r *Request) {
			for _, header := range headers {
				r.HTTPRequest.Header.Add(header, httpx.Header(r.HTTPRequest.Context(), header))
			}
		},
	}
}
75880
func (r *Router) ServeHTTPContext(ctx context.Context, w http.ResponseWriter, req *http.Request) error {
	route, h, vars := r.Handler(req)
	ctx = WithVars(ctx, vars)
	ctx = WithRoute(ctx, route)
	return h.ServeHTTPContext(ctx, w, req)
}
337113
func (c *Client) WithContext(ctx context.Context) *Client {
	newC := *c
	newC.ctx = ctx
	return &newC
}
1069975
func (o *UpdateOAuth2ClientParams) WithContext(ctx context.Context) *UpdateOAuth2ClientParams {
	o.SetContext(ctx)
	return o
}
694313
func (c *BasicAuth) NewContext(ctx context.Context) context.Context {
	return metadata.NewOutgoingContext(ctx, metadata.Pairs("Authorization", c.GetAuthorization()))
}
517682
func NewContext(res http.ResponseWriter, req *http.Request) *Context {
	return NewContextWith(res, req, nil)
}
890956
func (da *DigestAuth) NewContext(ctx context.Context, r *http.Request) context.Context {
	username, authinfo := da.CheckAuth(r)
	da.mutex.Lock()
	defer da.mutex.Unlock()
	info := &Info{Username: username, ResponseHeaders: make(http.Header)}
	if username != "" {
		info.Authenticated = true
		info.ResponseHeaders.Set(da.Headers.V().AuthInfo, *authinfo)
	} else {
		// return back digest WWW-Authenticate header
		if len(da.clients) > da.ClientCacheSize+da.ClientCacheTolerance {
			da.Purge(da.ClientCacheTolerance * 2)
		}
		nonce := RandomKey()
		da.clients[nonce] = &digestClient{nc: 0, lastSeen: time.Now().UnixNano()}
		info.ResponseHeaders.Set(da.Headers.V().Authenticate,
			fmt.Sprintf(`Digest realm="%s", nonce="%s", opaque="%s", algorithm=MD5, qop="auth"`,
				da.Realm, nonce, da.Opaque))
	}
	return context.WithValue(ctx, infoKey, info)
}
571729
func NewContext(napnap *NapNap, req *http.Request, writer ResponseWriter) *Context {
	return &Context{
		NapNap:  napnap,
		Request: req,
		Writer:  writer,
	}
}
998376
func Context(r *http.Request) *RequestContext {
	contextMutex.RLock()
	defer contextMutex.RUnlock()
	return requestContextMap[r]
}
772435
func (req *Request) Context() (c context.Context) {
	c, _ = req.GetValue(HTTP_REQUEST_CONTEXT).(context.Context)
	return
}
574655
func ToHTTP(ctx context.Context, c ContextHandler) http.Handler {
	return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
		c.ServeHTTPC(ctx, rw, r)
	})
}
841445
func ToContext(ctx context.Context, entry *logrus.Entry) context.Context {
	l := &ctxLogger{
		logger: entry,
		fields: logrus.Fields{},
	}
	return context.WithValue(ctx, ctxLoggerKey, l)
}