鸣镝 9 년 전
부모
커밋
fac1fd69e1
3개의 변경된 파일77개의 추가작업 그리고 2개의 파일을 삭제
  1. 1 1
      oss/const.go
  2. 1 1
      oss/error.go
  3. 75 0
      oss/error_test.go

+ 1 - 1
oss/const.go

@@ -78,5 +78,5 @@ const (
 
 	TempFilePrefix = "oss-go-temp-" // 临时文件前缀
 
-	Version = "1.2.0" // Go sdk版本
+	Version = "1.2.1" // Go sdk版本
 )

+ 1 - 1
oss/error.go

@@ -75,7 +75,7 @@ func (e CRCCheckError) Error() string {
 }
 
 func checkCRC(resp *Response, operation string) error {
-	if resp.ClientCRC == resp.ServerCRC {
+	if resp.Headers.Get(HTTPHeaderOssCRC64) == "" || resp.ClientCRC == resp.ServerCRC {
 		return nil
 	}
 	return CRCCheckError{resp.ClientCRC, resp.ServerCRC, operation, resp.Headers.Get(HTTPHeaderOssRequestID)}

+ 75 - 0
oss/error_test.go

@@ -0,0 +1,75 @@
+package oss
+
+import (
+	"math"
+	"net/http"
+
+	"fmt"
+
+	. "gopkg.in/check.v1"
+)
+
+type OssErrorSuite struct{}
+
+var _ = Suite(&OssErrorSuite{})
+
+func (s *OssErrorSuite) TestCheckCRCHasCRCInResp(c *C) {
+	headers := http.Header{
+		"Expires":              {"-1"},
+		"Content-Length":       {"0"},
+		"Content-Encoding":     {"gzip"},
+		"X-Oss-Hash-Crc64ecma": {"0"},
+	}
+
+	resp := &Response{
+		StatusCode: 200,
+		Headers:    headers,
+		Body:       nil,
+		ClientCRC:  math.MaxUint64,
+		ServerCRC:  math.MaxUint64,
+	}
+
+	err := checkCRC(resp, "test")
+	c.Assert(err, IsNil)
+	fmt.Printf("completed\n")
+}
+
+func (s *OssErrorSuite) TestCheckCRCNotHasCRCInResp(c *C) {
+	headers := http.Header{
+		"Expires":          {"-1"},
+		"Content-Length":   {"0"},
+		"Content-Encoding": {"gzip"},
+	}
+
+	resp := &Response{
+		StatusCode: 200,
+		Headers:    headers,
+		Body:       nil,
+		ClientCRC:  math.MaxUint64,
+		ServerCRC:  math.MaxUint32,
+	}
+
+	err := checkCRC(resp, "test")
+	c.Assert(err, IsNil)
+}
+
+func (s *OssErrorSuite) TestCheckCRCCNegative(c *C) {
+	headers := http.Header{
+		"Expires":              {"-1"},
+		"Content-Length":       {"0"},
+		"Content-Encoding":     {"gzip"},
+		"X-Oss-Hash-Crc64ecma": {"0"},
+	}
+
+	resp := &Response{
+		StatusCode: 200,
+		Headers:    headers,
+		Body:       nil,
+		ClientCRC:  0,
+		ServerCRC:  math.MaxUint64,
+	}
+
+	err := checkCRC(resp, "test")
+	c.Assert(err, NotNil)
+	testLogger.Println("error:", err)
+}