@@ -50,7 +50,10 @@ func (s *SproxydClient) Head(key string) (*SproxydObjectInfo, error) {
5050 return nil , fmt .Errorf ("HEAD %s returned %d" , url , resp .StatusCode )
5151 }
5252
53- cl , _ := strconv .ParseInt (resp .Header .Get ("Content-Length" ), 10 , 64 )
53+ cl , err := strconv .ParseInt (resp .Header .Get ("Content-Length" ), 10 , 64 )
54+ if err != nil || cl <= 0 {
55+ return nil , fmt .Errorf ("HEAD %s: missing or invalid Content-Length header" , url )
56+ }
5457 return & SproxydObjectInfo {
5558 ContentLength : cl ,
5659 UserMD : resp .Header .Get ("X-Scal-Usermd" ),
@@ -75,7 +78,11 @@ func (s *SproxydClient) Get(key string) (io.ReadCloser, *SproxydObjectInfo, erro
7578 return nil , nil , fmt .Errorf ("GET %s returned %d" , url , resp .StatusCode )
7679 }
7780
78- cl , _ := strconv .ParseInt (resp .Header .Get ("Content-Length" ), 10 , 64 )
81+ cl , err := strconv .ParseInt (resp .Header .Get ("Content-Length" ), 10 , 64 )
82+ if err != nil || cl <= 0 {
83+ resp .Body .Close ()
84+ return nil , nil , fmt .Errorf ("GET %s: missing or invalid Content-Length header" , url )
85+ }
7986 info := & SproxydObjectInfo {
8087 ContentLength : cl ,
8188 UserMD : resp .Header .Get ("X-Scal-Usermd" ),
@@ -100,11 +107,11 @@ func (s *SproxydClient) Put(key string, body io.Reader, info *SproxydObjectInfo)
100107 if err != nil {
101108 return fmt .Errorf ("PUT %s: %w" , url , err )
102109 }
103- defer resp .Body . Close ( )
104- io . Copy ( io . Discard , resp .Body )
110+ respBody , _ := io . ReadAll ( resp .Body )
111+ resp .Body . Close ( )
105112
106113 if resp .StatusCode != http .StatusOK {
107- return fmt .Errorf ("PUT %s returned %d" , url , resp .StatusCode )
114+ return fmt .Errorf ("PUT %s returned %d: %s " , url , resp .StatusCode , string ( respBody ) )
108115 }
109116 return nil
110117}
0 commit comments