2020-10-02 12:23:52 +00:00
|
|
|
package v2
|
|
|
|
|
|
|
|
import (
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session"
|
|
|
|
eaclSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/eacl"
|
2020-10-02 12:23:52 +00:00
|
|
|
)
|
|
|
|
|
2023-07-06 08:28:36 +00:00
|
|
|
type XHeaderSource interface {
|
2022-05-17 13:40:25 +00:00
|
|
|
GetXHeaders() []eaclSDK.Header
|
2020-10-02 12:23:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type requestXHeaderSource struct {
|
|
|
|
req Request
|
|
|
|
}
|
|
|
|
|
2023-07-06 08:28:36 +00:00
|
|
|
func NewRequestXHeaderSource(req Request) XHeaderSource {
|
|
|
|
return requestXHeaderSource{req: req}
|
|
|
|
}
|
|
|
|
|
2020-10-02 12:23:52 +00:00
|
|
|
type responseXHeaderSource struct {
|
|
|
|
resp Response
|
2020-12-28 15:59:42 +00:00
|
|
|
|
|
|
|
req Request
|
2020-10-02 12:23:52 +00:00
|
|
|
}
|
|
|
|
|
2023-07-06 08:28:36 +00:00
|
|
|
func NewResponseXHeaderSource(resp Response, req Request) XHeaderSource {
|
|
|
|
return responseXHeaderSource{resp: resp, req: req}
|
|
|
|
}
|
|
|
|
|
2022-05-17 13:40:25 +00:00
|
|
|
func (s requestXHeaderSource) GetXHeaders() []eaclSDK.Header {
|
2020-10-02 12:23:52 +00:00
|
|
|
ln := 0
|
|
|
|
|
|
|
|
for meta := s.req.GetMetaHeader(); meta != nil; meta = meta.GetOrigin() {
|
2022-05-17 13:44:35 +00:00
|
|
|
ln += len(meta.GetXHeaders())
|
2020-10-02 12:23:52 +00:00
|
|
|
}
|
|
|
|
|
2022-05-17 13:40:25 +00:00
|
|
|
res := make([]eaclSDK.Header, 0, ln)
|
2022-05-17 13:44:35 +00:00
|
|
|
for meta := s.req.GetMetaHeader(); meta != nil; meta = meta.GetOrigin() {
|
|
|
|
x := meta.GetXHeaders()
|
|
|
|
for i := range x {
|
2022-05-18 15:20:08 +00:00
|
|
|
res = append(res, (xHeader)(x[i]))
|
2020-10-02 12:23:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
2022-05-17 13:40:25 +00:00
|
|
|
func (s responseXHeaderSource) GetXHeaders() []eaclSDK.Header {
|
2020-10-02 12:23:52 +00:00
|
|
|
ln := 0
|
2022-05-18 15:20:08 +00:00
|
|
|
xHdrs := make([][]session.XHeader, 0)
|
2020-10-02 12:23:52 +00:00
|
|
|
|
2020-12-28 15:59:42 +00:00
|
|
|
for meta := s.req.GetMetaHeader(); meta != nil; meta = meta.GetOrigin() {
|
2022-05-18 15:20:08 +00:00
|
|
|
x := meta.GetXHeaders()
|
|
|
|
|
|
|
|
ln += len(x)
|
|
|
|
|
|
|
|
xHdrs = append(xHdrs, x)
|
2020-10-02 12:23:52 +00:00
|
|
|
}
|
|
|
|
|
2022-05-17 13:40:25 +00:00
|
|
|
res := make([]eaclSDK.Header, 0, ln)
|
2022-05-18 15:20:08 +00:00
|
|
|
|
|
|
|
for i := range xHdrs {
|
|
|
|
for j := range xHdrs[i] {
|
|
|
|
res = append(res, xHeader(xHdrs[i][j]))
|
2020-10-02 12:23:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res
|
|
|
|
}
|