diff options
Diffstat (limited to 'weed/util')
| -rw-r--r-- | weed/util/http/http_global_client_util.go | 5 | ||||
| -rw-r--r-- | weed/util/request_id.go | 27 | ||||
| -rw-r--r-- | weed/util/request_id/request_id.go | 26 |
3 files changed, 30 insertions, 28 deletions
diff --git a/weed/util/http/http_global_client_util.go b/weed/util/http/http_global_client_util.go index 3cc819a47..5cfd93a2c 100644 --- a/weed/util/http/http_global_client_util.go +++ b/weed/util/http/http_global_client_util.go @@ -6,8 +6,11 @@ import ( "encoding/json" "errors" "fmt" + "github.com/seaweedfs/seaweedfs/weed/util" "github.com/seaweedfs/seaweedfs/weed/util/mem" + "github.com/seaweedfs/seaweedfs/weed/util/request_id" + "io" "net/http" "net/url" @@ -307,7 +310,7 @@ func ReadUrlAsStreamAuthenticated(ctx context.Context, fileUrl, jwt string, ciph } else { req.Header.Add("Range", fmt.Sprintf("bytes=%d-%d", offset, offset+int64(size)-1)) } - util.ReqWithRequestId(req, ctx) + request_id.InjectToRequest(ctx, req) r, err := GetGlobalHttpClient().Do(req) if err != nil { diff --git a/weed/util/request_id.go b/weed/util/request_id.go deleted file mode 100644 index 7945e7cc4..000000000 --- a/weed/util/request_id.go +++ /dev/null @@ -1,27 +0,0 @@ -package util - -import ( - "context" - "net/http" -) - -const ( - RequestIdHttpHeader = "X-Request-ID" - RequestIDKey = "x-request-id" -) - -func GetRequestID(ctx context.Context) string { - if ctx == nil { - return "" - } - id, _ := ctx.Value(RequestIDKey).(string) - return id -} - -func WithRequestID(ctx context.Context, id string) context.Context { - return context.WithValue(ctx, RequestIDKey, id) -} - -func ReqWithRequestId(req *http.Request, ctx context.Context) { - req.Header.Set(RequestIdHttpHeader, GetRequestID(ctx)) -} diff --git a/weed/util/request_id/request_id.go b/weed/util/request_id/request_id.go new file mode 100644 index 000000000..0550cb58b --- /dev/null +++ b/weed/util/request_id/request_id.go @@ -0,0 +1,26 @@ +package request_id + +import ( + "context" + "net/http" +) + +const AmzRequestIDHeader = "x-amz-request-id" + +func Set(ctx context.Context, id string) context.Context { + return context.WithValue(ctx, AmzRequestIDHeader, id) +} + +func Get(ctx context.Context) string { + if ctx == nil { + return "" + } + id, _ := ctx.Value(AmzRequestIDHeader).(string) + return id +} + +func InjectToRequest(ctx context.Context, req *http.Request) { + if req != nil { + req.Header.Set(AmzRequestIDHeader, Get(ctx)) + } +} |
