breaking change: modify API for working with response metadata (#213)
Some checks failed
coverage / build (push) Has been skipped
test / test (push) Successful in 3m20s
sync / sync (push) Has been cancelled

* implement functions to append/get metadata and set/get status code

* сhanged behavior to return nil instead of empty metadata for getResponseMetadata()

* сhanged work with HTTP headers to use direct array assignment instead of for-range

* fix linters

* fix meter handler

* fix uninitialized response metadata for incoming context

* removed a useless test

* metrics handler has been fixed to work with compressed data
This commit is contained in:
2025-05-03 12:45:46 +05:00
committed by Vasiliy Tolstov
parent d7ffae7b16
commit 545e372b82
9 changed files with 323 additions and 121 deletions

29
response.go Normal file
View File

@@ -0,0 +1,29 @@
package http
import (
"context"
"net/http"
)
type (
rspStatusCodeKey struct{}
rspStatusCodeVal struct {
code int
}
)
// SetResponseStatusCode sets the status code in the context.
func SetResponseStatusCode(ctx context.Context, code int) {
if rsp, ok := ctx.Value(rspStatusCodeKey{}).(*rspStatusCodeVal); ok {
rsp.code = code
}
}
// GetResponseStatusCode retrieves the response status code from the context.
func GetResponseStatusCode(ctx context.Context) int {
code := http.StatusOK
if rsp, ok := ctx.Value(rspStatusCodeKey{}).(*rspStatusCodeVal); ok {
code = rsp.code
}
return code
}