feat(blobnode): do not return crc in range shard get

. #1000114180

Signed-off-by: slasher <shenjie1@oppo.com>
This commit is contained in:
slasher 2025-05-13 11:09:47 +08:00
parent bc0af29d84
commit b6e0936257
2 changed files with 7 additions and 3 deletions

View File

@ -112,18 +112,21 @@ func (s *Service) ShardGet(c *rpc.Context) {
// build http response header
w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Content-Transfer-Encoding", "binary")
w.Header().Set("CRC", strconv.FormatUint(uint64(shard.Crc), 10))
from, to := shard.From, shard.To
bodySize := int64(shard.Size)
if rangeBytesStr != "" {
bodySize = to - from
if bodySize == int64(shard.Size) {
w.Header().Set("CRC", strconv.FormatUint(uint64(shard.Crc), 10))
}
rangeResp := "bytes " + strconv.FormatInt(from, 10) + "-" + strconv.FormatInt(to-1, 10) + "/" + strconv.FormatInt(int64(shard.Size), 10)
w.Header().Set("Content-Length", strconv.FormatInt(int64(bodySize), 10))
w.Header().Set("Content-Range", rangeResp)
c.RespondStatus(http.StatusPartialContent)
} else {
w.Header().Set("CRC", strconv.FormatUint(uint64(shard.Crc), 10))
w.Header().Set("Content-Length", strconv.FormatInt(bodySize, 10))
c.RespondStatus(http.StatusOK)
}

View File

@ -826,14 +826,15 @@ func TestShardRangeGet(t *testing.T) {
b, err := io.ReadAll(body)
require.NoError(t, err)
require.Equal(t, expectCrc, getCrc)
require.Equal(t, uint32(0), getCrc)
require.Equal(t, 1, len(b))
require.Equal(t, byte('e'), byte(b[0]))
getShardArg.Offset = 4
getShardArg.Size = 2
body, _, err = client.RangeGetShard(ctx, host, getShardArg)
body, getCrc, err = client.RangeGetShard(ctx, host, getShardArg)
require.NoError(t, err)
require.Equal(t, uint32(0), getCrc)
b, err = io.ReadAll(body)
require.NoError(t, err)