// SetParams set params into routes
func (ctx *Context) SetParams(k, v string) {
- chiCtx := chi.RouteContext(ctx.Req.Context())
+ chiCtx := chi.RouteContext(ctx)
chiCtx.URLParams.Add(strings.TrimPrefix(k, ":"), url.PathEscape(v))
}
ctx.Resp.WriteHeader(status)
}
+// Deadline is part of the interface for context.Context and we pass this to the request context
+func (ctx *Context) Deadline() (deadline time.Time, ok bool) {
+ return ctx.Req.Context().Deadline()
+}
+
+// Done is part of the interface for context.Context and we pass this to the request context
+func (ctx *Context) Done() <-chan struct{} {
+ return ctx.Req.Context().Done()
+}
+
+// Err is part of the interface for context.Context and we pass this to the request context
+func (ctx *Context) Err() error {
+ return ctx.Req.Context().Err()
+}
+
+// Value is part of the interface for context.Context and we pass this to the request context
+func (ctx *Context) Value(key interface{}) interface{} {
+ return ctx.Req.Context().Value(key)
+}
+
// Handler represents a custom handler
type Handler func(*Context)
package graceful
import (
+ "context"
"crypto/tls"
+ "net"
"net/http"
)
WriteTimeout: DefaultWriteTimeOut,
MaxHeaderBytes: DefaultMaxHeaderBytes,
Handler: handler,
+ BaseContext: func(net.Listener) context.Context { return GetManager().HammerContext() },
}
server.OnShutdown = func() {
httpServer.SetKeepAlivesEnabled(false)
ctx.RenderWithErr(password.BuildComplexityError(ctx), tplUserNew, &form)
return
}
- pwned, err := password.IsPwned(ctx.Req.Context(), form.Password)
+ pwned, err := password.IsPwned(ctx, form.Password)
if pwned {
ctx.Data["Err_Password"] = true
errMsg := ctx.Tr("auth.password_pwned")
ctx.RenderWithErr(password.BuildComplexityError(ctx), tplUserEdit, &form)
return
}
- pwned, err := password.IsPwned(ctx.Req.Context(), form.Password)
+ pwned, err := password.IsPwned(ctx, form.Password)
if pwned {
ctx.Data["Err_Password"] = true
errMsg := ctx.Tr("auth.password_pwned")
ctx.Error(http.StatusBadRequest, "PasswordComplexity", err)
return
}
- pwned, err := password.IsPwned(ctx.Req.Context(), form.Password)
+ pwned, err := password.IsPwned(ctx, form.Password)
if pwned {
if err != nil {
log.Error(err.Error())
ctx.Error(http.StatusBadRequest, "PasswordComplexity", err)
return
}
- pwned, err := password.IsPwned(ctx.Req.Context(), form.Password)
+ pwned, err := password.IsPwned(ctx, form.Password)
if pwned {
if err != nil {
log.Error(err.Error())
}
// Listen to connection close and un-register messageChan
- notify := ctx.Req.Context().Done()
+ notify := ctx.Done()
ctx.Resp.Flush()
shutdownCtx := graceful.GetManager().ShutdownContext()
}
// Re-read settings
- PostInstallInit(ctx.Req.Context())
+ PostInstallInit(ctx)
// Create admin account
if len(form.AdminName) > 0 {
// Now get the http.Server from this request and shut it down
// NB: This is not our hammerable graceful shutdown this is http.Server.Shutdown
- srv := ctx.Req.Context().Value(http.ServerContextKey).(*http.Server)
+ srv := ctx.Value(http.ServerContextKey).(*http.Server)
go func() {
if err := srv.Shutdown(graceful.GetManager().HammerContext()); err != nil {
log.Error("Unable to shutdown the install server! Error: %v", err)
})
return
}
- err := queue.GetManager().FlushAll(ctx.Req.Context(), opts.Timeout)
+ err := queue.GetManager().FlushAll(ctx, opts.Timeout)
if err != nil {
ctx.JSON(http.StatusRequestTimeout, map[string]interface{}{
"err": fmt.Sprintf("%v", err),
}
if err := migrations.RestoreRepository(
- ctx.Req.Context(),
+ ctx,
params.RepoDir,
params.OwnerName,
params.RepoName,
return
}
- blameReader, err := git.CreateBlameReader(ctx.Req.Context(), models.RepoPath(userName, repoName), commitID, fileName)
+ blameReader, err := git.CreateBlameReader(ctx, models.RepoPath(userName, repoName), commitID, fileName)
if err != nil {
ctx.NotFound("CreateBlameReader", err)
return
err = func() error {
pointerChan := make(chan lfs.PointerBlob)
errChan := make(chan error, 1)
- go lfs.SearchPointerBlobs(ctx.Req.Context(), ctx.Repo.GitRepo, pointerChan, errChan)
+ go lfs.SearchPointerBlobs(ctx, ctx.Repo.GitRepo, pointerChan, errChan)
numPointers := 0
var numAssociated, numNoExist, numAssociatable int
case setting.ImageCaptcha:
valid = context.GetImageCaptcha().VerifyReq(ctx.Req)
case setting.ReCaptcha:
- valid, err = recaptcha.Verify(ctx.Req.Context(), form.GRecaptchaResponse)
+ valid, err = recaptcha.Verify(ctx, form.GRecaptchaResponse)
case setting.HCaptcha:
- valid, err = hcaptcha.Verify(ctx.Req.Context(), form.HcaptchaResponse)
+ valid, err = hcaptcha.Verify(ctx, form.HcaptchaResponse)
default:
ctx.ServerError("Unknown Captcha Type", fmt.Errorf("Unknown Captcha Type: %s", setting.Service.CaptchaType))
return
case setting.ImageCaptcha:
valid = context.GetImageCaptcha().VerifyReq(ctx.Req)
case setting.ReCaptcha:
- valid, err = recaptcha.Verify(ctx.Req.Context(), form.GRecaptchaResponse)
+ valid, err = recaptcha.Verify(ctx, form.GRecaptchaResponse)
case setting.HCaptcha:
- valid, err = hcaptcha.Verify(ctx.Req.Context(), form.HcaptchaResponse)
+ valid, err = hcaptcha.Verify(ctx, form.HcaptchaResponse)
default:
ctx.ServerError("Unknown Captcha Type", fmt.Errorf("Unknown Captcha Type: %s", setting.Service.CaptchaType))
return
ctx.RenderWithErr(password.BuildComplexityError(ctx), tplSignUp, &form)
return
}
- pwned, err := password.IsPwned(ctx.Req.Context(), form.Password)
+ pwned, err := password.IsPwned(ctx, form.Password)
if pwned {
errMsg := ctx.Tr("auth.password_pwned")
if err != nil {
ctx.Data["Err_Password"] = true
ctx.RenderWithErr(password.BuildComplexityError(ctx), tplResetPassword, nil)
return
- } else if pwned, err := password.IsPwned(ctx.Req.Context(), passwd); pwned || err != nil {
+ } else if pwned, err := password.IsPwned(ctx, passwd); pwned || err != nil {
errMsg := ctx.Tr("auth.password_pwned")
if err != nil {
log.Error(err.Error())
ctx.ServerError("", err)
return
}
- valid, err = recaptcha.Verify(ctx.Req.Context(), form.GRecaptchaResponse)
+ valid, err = recaptcha.Verify(ctx, form.GRecaptchaResponse)
case setting.HCaptcha:
if err := ctx.Req.ParseForm(); err != nil {
ctx.ServerError("", err)
return
}
- valid, err = hcaptcha.Verify(ctx.Req.Context(), form.HcaptchaResponse)
+ valid, err = hcaptcha.Verify(ctx, form.HcaptchaResponse)
default:
ctx.ServerError("Unknown Captcha Type", fmt.Errorf("Unknown Captcha Type: %s", setting.Service.CaptchaType))
return
ctx.Flash.Error(ctx.Tr("form.password_not_match"))
} else if !password.IsComplexEnough(form.Password) {
ctx.Flash.Error(password.BuildComplexityError(ctx))
- } else if pwned, err := password.IsPwned(ctx.Req.Context(), form.Password); pwned || err != nil {
+ } else if pwned, err := password.IsPwned(ctx, form.Password); pwned || err != nil {
errMsg := ctx.Tr("auth.password_pwned")
if err != nil {
log.Error(err.Error())
func (aReq *ArchiveRequest) WaitForCompletion(ctx *context.Context) bool {
select {
case <-aReq.cchan:
- case <-ctx.Req.Context().Done():
+ case <-ctx.Done():
}
return aReq.IsComplete()
case <-time.After(dur):
timeout = true
case <-aReq.cchan:
- case <-ctx.Req.Context().Done():
+ case <-ctx.Done():
}
return aReq.IsComplete(), timeout