Skip to content

Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.

466 B
Raw Blame
package app

import (
	"net/http"
	"regexp"

	"github.com/gin-gonic/gin"
)

var idempotencyKeyPattern = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9._:-]{7,127}$`)

func (a *App) requireIdempotencyKey(c *gin.Context) (string, bool) {
	key := c.GetHeader("Idempotency-Key")
	if !idempotencyKeyPattern.MatchString(key) {
		a.writeError(c, http.StatusBadRequest, "INVALID_IDEMPOTENCY_KEY", "a valid Idempotency-Key is required")
		return "", false
	}
	return key, true
}