Skip to content

Commit 0f1c350

Browse files
committed
[rget]rename function
1 parent d00487a commit 0f1c350

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

kadai3/imura81gt/rget/rget.go

+16-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type Units []Unit
4040

4141
func Run(option Option) {
4242
fmt.Printf("%+v\n", option)
43-
err := option.contentLength()
43+
err := option.checkingHeaders()
4444
if err != nil {
4545
fmt.Errorf("%s", err)
4646
}
@@ -66,8 +66,7 @@ func Run(option Option) {
6666

6767
}
6868

69-
func (o *Option) contentLength() error {
70-
//resp, err := http.Head(url)
69+
func (o *Option) checkingHeaders() error {
7170
resp, err := http.Head(o.URL)
7271
if err != nil {
7372
return err
@@ -77,17 +76,30 @@ func (o *Option) contentLength() error {
7776
err := fmt.Errorf("%s URL cannot support Ranges Requests", o.URL)
7877
return err
7978
}
79+
8080
if resp.Header["Accept-Ranges"][0] == "none" {
8181
err := fmt.Errorf("%s cannot support Ranges Requests", o.URL)
8282
return err
8383
}
84+
8485
if resp.ContentLength == 0 {
8586
err := fmt.Errorf("%s size is %s", o.URL, resp.Header["Content-Length"][0])
8687
return err
8788
}
8889

90+
redirectURL := resp.Request.URL.String()
91+
if err != nil {
92+
return err
93+
}
94+
8995
o.ContentLength = resp.ContentLength
90-
//return resp.ContentLength, nil
96+
97+
// keep the redirect URL that accept Ranges Requests because some mirror sites may deny.
98+
// TODO: redirectURL should set by Unit separately.
99+
if o.URL != redirectURL {
100+
o.URL = redirectURL
101+
}
102+
91103
return err
92104
}
93105

kadai3/imura81gt/rget/rget_test.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ func TestWrite(t *testing.T) {
1212
func TestRun(t *testing.T) {
1313
}
1414

15-
func TestContentLength(t *testing.T) {
16-
}
17-
18-
func TestAcceptRangesHeaderCheck(t *testing.T) {
15+
func TestCheckingHeaders(t *testing.T) {
1916
}
2017

2118
//func divide(contentLength int64, concurrency int) Units {

0 commit comments

Comments
 (0)