// handle client API
541527
func (a *ApiManager) HandleRequest(w http.ResponseWriter, r *http.Request) {

	w.Header().Set("Content-Type", "application/json")

	var returnValue interface{}

	verifyApiKeyReq, err := validateRequest(r.Body, w)
	if err != nil {
		errorResponse, jsonErr := json.Marshal(errorResponse("Bad_REQUEST", err.Error(), http.StatusBadRequest))
		if jsonErr != nil {
			w.WriteHeader(http.StatusInternalServerError)
			w.Write([]byte(jsonErr.Error()))
		}
		w.WriteHeader(http.StatusBadRequest)
		w.Write(errorResponse)
		return
	}

	verifyApiKeyResponse, errorResponse := a.verifyAPIKey(verifyApiKeyReq)

	if errorResponse != nil {
		setResponseHeader(errorResponse, w)
		returnValue = errorResponse
	} else {
		returnValue = verifyApiKeyResponse
	}
	b, _ := json.Marshal(returnValue)
	log.Debugf("handleVerifyAPIKey result %s", b)
	w.Write(b)

}
1034839
func Handle(req *http.Request, h http.HandlerFunc, t *testing.T) {

	rr := httptest.NewRecorder()

	handler := http.HandlerFunc(h)

	handler.ServeHTTP(rr, req)

	if status := rr.Code; status != http.StatusOK {
		t.Errorf("handler returned wrong status code: got %v want %v",
			status, http.StatusOK)
	}
}
1190437
func (h *instanceIDHandler) Handle(
	ctx types.Context,
	w http.ResponseWriter,
	req *http.Request,
	store types.Store) error {

	headers := req.Header[types.InstanceIDHeader]
	ctx.WithField(types.InstanceIDHeader, headers).Debug("http header")

	// this function has been updated to account for
	// https://github.com/codedellemc/libstorage/pull/420 and
	// https://github.com/codedellemc/rexray/issues/685.
	//
	// this handler now inspects each instance ID header and stores the
	// unmarshaled object in one of two maps -- a map keyed by the
	// service name and a map keyed by the driver name. the service
	// name-keyed map is only used if the instance ID has a service
	// name present.
	//
	// after the two maps are populated, all of the server's configured
	// services are iterated. first we check the service name-keyed map
	// for a service's instance ID, and only then if not present we
	// check the driver name-keyed map for the service's instance ID.

	valMap := types.InstanceIDMap{}
	d2i := map[string]*types.InstanceID{}
	s2i := map[string]*types.InstanceID{}

	for _, h := range headers {
		val := &types.InstanceID{}
		if err := val.UnmarshalText([]byte(h)); err != nil {
			return err
		}
		if len(val.Service) > 0 {
			s2i[strings.ToLower(val.Service)] = val
		} else {
			d2i[strings.ToLower(val.Driver)] = val
		}
	}

	for s, d := range h.s2d {
		if iid, ok := s2i[s]; ok {
			valMap[s] = iid
		} else if iid, ok := d2i[d]; ok {
			valMap[s] = iid
		}
	}

	ctx = ctx.WithValue(context.AllInstanceIDsKey, valMap)
	return h.handler(ctx, w, req, store)
}
644731
func (h *basicHandler) Handle(c context.Context, conn net.Conn) {
	h.handlerFunc(c, conn)
}
425739
func (h HandlerFunc) Handle(event json.RawMessage, ctx *Context) (interface{}, error) {
	return h(event, ctx)
}
520858
func HandleGetRequests(client *http.Client, URLPath string) ([]byte, error) {
	if client == nil {
		return nil, fmt.Errorf("invalid http client was passed")
	}

	if URLPath == "" {
		return nil, fmt.Errorf("empty API URL is not supported")
	}

	response, err := client.Get(URLPath)
	if err != nil || response == nil {
		return nil, fmt.Errorf("request failed: %v", err)
	}

	// Check if valid status code (200 Ok) was returned.
	if response.StatusCode != http.StatusOK {
		return nil, fmt.Errorf("request (%s) failed with status code: %s",
			URLPath, response.Status)
	}

	defer response.Body.Close()

	return ioutil.ReadAll(response.Body)
}
365428
func (cniApp *cniAppInfo) handleHTTP(url string, jsonReq *bytes.Buffer) int {

	cniLog.Infof("http POST url: %s data: %v", url, jsonReq)
	httpResp, err := cniApp.httpClient.Post(url, "application/json", jsonReq)
	if err != nil {
		return cniApp.sendCniErrorResp("failed to get response from netplugin :" + err.Error())
	}
	defer httpResp.Body.Close()

	switch httpResp.StatusCode {

	case http.StatusOK:
		cniLog.Infof("received http OK response from netplugin")
		info, err := ioutil.ReadAll(httpResp.Body)
		if err != nil {
			return cniApp.sendCniErrorResp("failed to read success response from netplugin :" + err.Error())
		}
		return cniApp.sendCniResp(info, cniapi.CniStatusSuccess)

	case http.StatusInternalServerError:
		cniLog.Infof("received http error response from netplugin")
		info, err := ioutil.ReadAll(httpResp.Body)
		if err != nil {
			return cniApp.sendCniErrorResp("failed to read error response from netplugin :" + err.Error())
		}
		return cniApp.sendCniResp(info, cniapi.CniStatusErrorUnsupportedField)

	default:
		cniLog.Infof("received unknown error from netplugin")
		return cniApp.sendCniErrorResp("error response from netplugin: " + http.StatusText(httpResp.StatusCode))
	}
}
1327020
func (h *getStatusCache) Handle(params GetStatusParams) middleware.Responder {
	log.Debug("Handling request for /status")

	return NewGetStatusOK().WithPayload(h.GetStatusResponse())
}
897869
func (s Server) Handle(data []byte) ([]byte, error) {
	request, err := s.p.DecodeEnveloped(bytes.NewReader(data))
	if err != nil {
		return nil, err
	}

	response := wire.Envelope{
		Name:  request.Name,
		SeqID: request.SeqID,
		Type:  wire.Reply,
	}

	response.Value, err = s.h.Handle(request.Name, request.Value)
	if err != nil {
		response.Type = wire.Exception
		switch err.(type) {
		case ErrUnknownMethod:
			response.Value, err = tappExc(err, exception.ExceptionTypeUnknownMethod)
		default:
			response.Value, err = tappExc(err, exception.ExceptionTypeInternalError)
		}

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

	var buff bytes.Buffer
	if err := s.p.EncodeEnveloped(response, &buff); err != nil {
		return nil, err
	}

	return buff.Bytes(), nil
}
1292447
func (s *Server) Handle(addr string, handler HandlerFunc) error {
	if s.Dispatcher == nil {
		s.Dispatcher = NewOscDispatcher()
	}
	return s.Dispatcher.AddMsgHandler(addr, handler)
}
7271
func (om *ClientIDMiddleware) Handler(next http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		var clientID string

		accessToken := om.GetAccessToken(r)

		token, err := oauth2.GetValidJWT(r, security.JWTPublicKey)
		if err != nil {
			log.Error("Failed to get valid JWT: ", err)
			http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
			return
		}
		if token != nil {
			clientID = token.Claims["azp"].(string)

		} else if accessToken != "" {
			oauthMgr := oauthservice.NewManager(r)
			at, err := oauthMgr.GetAccessToken(accessToken)
			if err != nil {
				log.Error("Failed to get access token: ", err)
				http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
				return
			}
			if at == nil {
				http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
				return
			}
			clientID = at.ClientID
		} else {
			if webuser, ok := context.GetOk(r, "webuser"); ok {
				if parsedusername, ok := webuser.(string); ok && parsedusername != "" {
					clientID = "itsyouonline"
				}
			}
		}
		if clientID == "" {
			http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
			return
		}

		context.Set(r, "client_id", clientID)

		next.ServeHTTP(w, r)
	})
}
651990
func (h *LangHandler) handle(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) {
	return h.Handle(ctx, conn, req)
}
197396
func (hdr *Handler) Handle(im *imageserver.Image, params imageserver.Params) (*imageserver.Image, error) {
	enc, format, err := getEncoderFormat(im.Format, params)
	if err != nil {
		if _, ok := err.(*imageserver.ParamError); !ok {
			err = &imageserver.ImageError{Message: err.Error()}
		}
		return nil, err
	}
	if !hdr.change(im, format, enc, params) {
		return im, nil
	}
	nim, err := Decode(im)
	if err != nil {
		return nil, err
	}
	if hdr.Processor != nil {
		nim, err = hdr.Processor.Process(nim, params)
		if err != nil {
			return nil, err
		}
	}
	im, err = encode(nim, format, enc, params)
	if err != nil {
		return nil, err
	}
	return im, nil
}
125762
func (fn PetUpdateHandlerFunc) Handle(params PetUpdateParams, principal interface{}) middleware.Responder {
	return fn(params, principal)
}
64999
func (s *Server) Handle(typ string, f protocolHandler) {
	s.handlers[typ] = f
}
331542
func (fn AddOneHandlerFunc) Handle(params AddOneParams, principal interface{}) middleware.Responder {
	return fn(params, principal)
}
708958
func (fn UpdatePetHandlerFunc) Handle(params UpdatePetParams, principal interface{}) middleware.Responder {
	return fn(params, principal)
}