Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

Integration test fails when read with Range: bytes=-xxx #66

Closed
JinnyYi opened this issue Sep 30, 2021 · 3 comments
Closed

Integration test fails when read with Range: bytes=-xxx #66

JinnyYi opened this issue Sep 30, 2021 · 3 comments

Comments

@JinnyYi
Copy link
Contributor

JinnyYi commented Sep 30, 2021

Expected Behavior

According to COS API doc, when GetObject with Range header:

例如 bytes=0-9,表示下载对象的开头10个字节的数据;bytes=5-9,表示下载对象的第6到第10个字节。此时返回 HTTP 状态码206(Partial Content)及 Content-Range 响应头部。

And also, FormatRangeOptions() was provided to format Range value in cos-go-sdk:

func FormatRangeOptions(opt *RangeOptions) string {
	if opt == nil {
		return ""
	}
	if opt.HasStart && opt.HasEnd {
		return fmt.Sprintf("bytes=%v-%v", opt.Start, opt.End)
	}
	if opt.HasStart {
		return fmt.Sprintf("bytes=%v-", opt.Start)
	}
	if opt.HasEnd {
		return fmt.Sprintf("bytes=-%v", opt.End)
	}
	return ""
}

Based on the above, we envision that when Range: bytes=-9 we should be able to download data from 0 to 9([0-9]).

Current Behavior

  • When setting RangeOptions.End as follows, we will get the read size check error.
    rangeOptions := &cos.RangeOptions{}
    if opt.HasSize {
      	rangeOptions.HasEnd = true
      	rangeOptions.End = rangeOptions.Start + opt.Size - 1
    }
    
  • When setting RangeOptions.End as follows, we will get the read content check error.
    rangeOptions := &cos.RangeOptions{}
    if opt.HasSize {
      	rangeOptions.HasEnd = true
      	rangeOptions.End = opt.Size
    }
    

Steps to Reproduce

Run integration test after modifying the code as above.

Enviroment

github.com/tencentyun/cos-go-sdk-v5 v0.7.31

@JinnyYi
Copy link
Contributor Author

JinnyYi commented Oct 3, 2021

Based on the above, we envision that when Range: bytes=-9 we should be able to download data from 0 to 9([0-9]).

Seems that Range: bytes=-9 identifies the final 9 bytes, ref: https://datatracker.ietf.org/doc/html/rfc7233#section-2.1. I'll test and verify it later.

Hypertext Transfer Protocol (HTTP/1.1): Range Requests (RFC )

@JinnyYi
Copy link
Contributor Author

JinnyYi commented Oct 14, 2021

GetObject with Range: bytes=-5 will get the final 5 bytes. So if Read with only size, we have to set the offset to 0 actively.

image

@JinnyYi JinnyYi closed this as completed Oct 14, 2021
@Xuanwo
Copy link
Collaborator

Xuanwo commented Oct 14, 2021

Nice work!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants