func (h *toolsDownloadHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { st, err := h.ctxt.stateForRequestUnauthenticated(r) if err != nil { if err := sendError(w, err); err != nil { logger.Errorf("%v", err) } return } switch r.Method { case "GET": tarball, err := h.processGet(r, st) if err != nil { logger.Errorf("GET(%s) failed: %v", r.URL, err) if err := sendError(w, errors.NewBadRequest(err, "")); err != nil { logger.Errorf("%v", err) } return } if err := h.sendTools(w, http.StatusOK, tarball); err != nil { logger.Errorf("%v", err) } default: if err := sendError(w, errors.MethodNotAllowedf("unsupported method: %q", r.Method)); err != nil { logger.Errorf("%v", err) } } }
func (h *toolsUploadHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // Validate before authenticate because the authentication is dependent // on the state connection that is determined during the validation. st, _, err := h.ctxt.stateForRequestAuthenticatedUser(r) if err != nil { if err := sendError(w, err); err != nil { logger.Errorf("%v", err) } return } switch r.Method { case "POST": // Add tools to storage. agentTools, err := h.processPost(r, st) if err != nil { if err := sendError(w, err); err != nil { logger.Errorf("%v", err) } return } if err := sendStatusAndJSON(w, http.StatusOK, ¶ms.ToolsResult{ ToolsList: tools.List{agentTools}, }); err != nil { logger.Errorf("%v", err) } default: if err := sendError(w, errors.MethodNotAllowedf("unsupported method: %q", r.Method)); err != nil { logger.Errorf("%v", err) } } }
// ServeHTTP implements http.Handler. func (h *LegacyHTTPHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) { st, tag, err := h.Connect(req) if err != nil { api.SendHTTPError(resp, err) return } var username string switch tag := tag.(type) { case *names.UserTag: username = tag.Name() default: // TODO(ericsnow) Fail? username = tag.Id() } // We do this *after* authorization, etc. (in h.Connect) in order // to prioritize errors that may originate there. switch req.Method { case "PUT": logger.Infof("handling resource upload request") response, err := h.HandleUpload(username, st, req) if err != nil { api.SendHTTPError(resp, err) return } api.SendHTTPStatusAndJSON(resp, http.StatusOK, &response) logger.Infof("resource upload request successful") default: api.SendHTTPError(resp, errors.MethodNotAllowedf("unsupported method: %q", req.Method)) } }
func (h *testServiceHandler) _http_TestService_List(ctx golang_org_x_net_context.Context, rw net_http.ResponseWriter, req *net_http.Request) error { if req.Method != "GET" { return github_com_juju_errors.MethodNotAllowedf("expected GET request") } var ( input ListOptions ) ctx = github_com_limbo_services_core_runtime_limbo.AnnotateContext(ctx, req) // populate after=after { var msg0 = &input val := req.URL.Query().Get("after") intVal, _ := strconv.ParseInt(val, 10, 64) msg0.After = int64(intVal) } { // call ss, err := github_com_limbo_services_core_runtime_limbo.NewPagedServerStream(ctx, rw, 0) if err != nil { return github_com_juju_errors.Trace(err) } defer ss.Close() stream := &testServiceListServer{ss} err = h.ss.List(&input, stream) } return nil }
func (h *backupHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) { // Validate before authenticate because the authentication is dependent // on the state connection that is determined during the validation. st, _, err := h.ctxt.stateForRequestAuthenticatedUser(req) if err != nil { h.sendError(resp, err) return } backups, closer := newBackups(st) defer closer.Close() switch req.Method { case "GET": logger.Infof("handling backups download request") id, err := h.download(backups, resp, req) if err != nil { h.sendError(resp, err) return } logger.Infof("backups download request successful for %q", id) case "PUT": logger.Infof("handling backups upload request") id, err := h.upload(backups, resp, req) if err != nil { h.sendError(resp, err) return } logger.Infof("backups upload request successful for %q", id) default: h.sendError(resp, errors.MethodNotAllowedf("unsupported method: %q", req.Method)) } }
func (h *testServiceHandler) _http_TestService_FetchPerson(ctx golang_org_x_net_context.Context, rw net_http.ResponseWriter, req *net_http.Request) error { if req.Method != "GET" { return github_com_juju_errors.MethodNotAllowedf("expected GET request") } var ( input FetchOptions params = github_com_limbo_services_core_runtime_router.P(ctx) ) ctx = github_com_limbo_services_core_runtime_limbo.AnnotateContext(ctx, req) // populate id { var msg0 = &input val := params.Get("id") intVal, _ := strconv.ParseInt(val, 10, 64) msg0.Id = int64(intVal) } { // call output, err := h.ss.FetchPerson(ctx, &input) if err != nil { return github_com_juju_errors.Trace(err) } github_com_limbo_services_core_runtime_limbo.RenderMessageJSON(rw, 200, output) return nil } return nil }
func (h *testServiceHandler) _http_TestService_Greet(ctx golang_org_x_net_context.Context, rw net_http.ResponseWriter, req *net_http.Request) error { if req.Method != "POST" { return github_com_juju_errors.MethodNotAllowedf("expected POST request") } var ( input Person ) ctx = github_com_limbo_services_core_runtime_limbo.AnnotateContext(ctx, req) { // from body err := encoding_json.NewDecoder(req.Body).Decode(&input) if err != nil { return github_com_juju_errors.Trace(err) } } { // call output, err := h.ss.Greet(ctx, &input) if err != nil { return github_com_juju_errors.Trace(err) } github_com_limbo_services_core_runtime_limbo.RenderMessageJSON(rw, 200, output) return nil } return nil }
// ServeHTTP implements the http.Handler interface. func (h *registerUserHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { if req.Method != "POST" { sendError(w, errors.MethodNotAllowedf("unsupported method: %q", req.Method)) return } st, err := h.ctxt.stateForRequestUnauthenticated(req) if err != nil { sendError(w, err) return } userTag, response, err := h.processPost(req, st) if err != nil { sendError(w, err) return } // Set a short-lived macaroon as a cookie on the response, // which the client can use to obtain a discharge macaroon. m, err := h.ctxt.srv.authCtxt.CreateLocalLoginMacaroon(userTag) if err != nil { sendError(w, err) return } cookie, err := httpbakery.NewCookie(macaroon.Slice{m}) if err != nil { sendError(w, err) return } http.SetCookie(w, cookie) sendStatusAndJSON(w, http.StatusOK, response) }
// ServeHTTP implements http.Handler. func (h *guiVersionHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { if req.Method != "PUT" { sendError(w, errors.MethodNotAllowedf("unsupported method: %q", req.Method)) return } if err := h.handlePut(w, req); err != nil { sendError(w, errors.Trace(err)) } }
func (h *charmsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { var err error switch r.Method { case "POST": err = h.servePost(w, r) case "GET": err = h.serveGet(w, r) default: err = errors.MethodNotAllowedf("unsupported method: %q", r.Method) } if err != nil { h.sendError(w, r, err) } }
// ServeHTTP implements http.Handler. func (h *guiArchiveHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { var handler func(http.ResponseWriter, *http.Request) error switch req.Method { case "GET": handler = h.handleGet case "POST": handler = h.handlePost default: sendError(w, errors.MethodNotAllowedf("unsupported method: %q", req.Method)) return } if err := handler(w, req); err != nil { sendError(w, errors.Trace(err)) } }
// ServeHTTP implements the http.Handler interface. func (h *registerUserHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { if req.Method != "POST" { sendError(w, errors.MethodNotAllowedf("unsupported method: %q", req.Method)) return } st, err := h.ctxt.stateForRequestUnauthenticated(req) if err != nil { sendError(w, err) return } response, err := h.processPost(req, st) if err != nil { sendError(w, err) return } sendStatusAndJSON(w, http.StatusOK, response) }
func (h *imagesDownloadHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { st, err := h.ctxt.stateForRequestUnauthenticated(r) if err != nil { sendError(w, err) return } switch r.Method { case "GET": err := h.processGet(r, w, st) if err != nil { logger.Errorf("GET(%s) failed: %v", r.URL, err) sendError(w, err) return } default: sendError(w, errors.MethodNotAllowedf("unsupported method: %q", r.Method)) } }
// ServeHTTP implements http.Handler. func (h *LegacyHTTPHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) { opener, err := h.NewResourceOpener(req) if err != nil { h.SendHTTPError(resp, err) return } // We do this *after* authorization, etc. (in h.Extract...) in order // to prioritize errors that may originate there. switch req.Method { case "GET": logger.Infof("handling resource download request") opened, err := h.HandleDownload(opener, req) if err != nil { logger.Errorf("cannot fetch resource reader: %v", err) h.SendHTTPError(resp, err) return } defer opened.Close() h.UpdateDownloadResponse(resp, opened.Resource) resp.WriteHeader(http.StatusOK) if err := h.Copy(resp, opened); err != nil { // We cannot use api.SendHTTPError here, so we log the error // and move on. logger.Errorf("unable to complete stream for resource: %v", err) return } logger.Infof("resource download request successful") default: h.SendHTTPError(resp, errors.MethodNotAllowedf("unsupported method: %q", req.Method)) } }
err: common.OperationBlockedError("test"), code: params.CodeOperationBlocked, status: http.StatusBadRequest, helperFunc: params.IsCodeOperationBlocked, }, { err: errors.NotSupportedf("needed feature"), code: params.CodeNotSupported, status: http.StatusInternalServerError, helperFunc: params.IsCodeNotSupported, }, { err: errors.BadRequestf("something"), code: params.CodeBadRequest, status: http.StatusBadRequest, helperFunc: params.IsBadRequest, }, { err: errors.MethodNotAllowedf("something"), code: params.CodeMethodNotAllowed, status: http.StatusMethodNotAllowed, helperFunc: params.IsMethodNotAllowed, }, { err: stderrors.New("an error"), status: http.StatusInternalServerError, code: "", }, { err: &common.DischargeRequiredError{ Cause: errors.New("something"), Macaroon: sampleMacaroon, }, status: http.StatusUnauthorized, code: params.CodeDischargeRequired, helperFunc: func(err error) bool {
func emitUnsupportedMethodErr(method string) error { return errors.MethodNotAllowedf("unsupported method: %q", method) }