This commit is contained in:
Vladislav Kunetskiy
2026-11-05 20:21:39 +03:00
parent edc2a405ee
commit 71fbb4b321
129 changed files with 10027 additions and 170 deletions
+4 -1
View File
@@ -3,12 +3,15 @@ package rest
import (
"context"
"net/http"
"regexp"
"github.com/google/uuid"
)
const requestIDHeader = "X-Request-ID"
var requestIDPattern = regexp.MustCompile(`^[A-Za-z0-9._:-]{1,64}$`)
type requestIDKey struct{}
func requestIDFromContext(ctx context.Context) string {
@@ -24,7 +27,7 @@ func withRequestID(ctx context.Context, id string) context.Context {
func requestIDMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
id := r.Header.Get(requestIDHeader)
if id == "" {
if !requestIDPattern.MatchString(id) {
id = uuid.NewString()
}