@@ -1299,11 +1299,10 @@ func TestOutputFileWithBaseDirAndRelativePath(t *testing.T) {
12991299 SetRedirectPolicy (FlexibleRedirectPolicy (10 )).
13001300 SetOutputDirectory (baseOutputDir ).
13011301 SetDebug (true )
1302- client .outputLogTo (io .Discard )
13031302
13041303 outputFilePath := "go-resty/test-img-success.png"
13051304 resp , err := client .R ().
1306- SetOutputFile (outputFilePath ).
1305+ SetOutputFileName (outputFilePath ).
13071306 Get (ts .URL + "/my-image.png" )
13081307
13091308 assertError (t , err )
@@ -1332,7 +1331,7 @@ func TestOutputPathDirNotExists(t *testing.T) {
13321331 SetOutputDirectory (filepath .Join (getTestDataPath (), "not-exists-dir" ))
13331332
13341333 resp , err := client .R ().
1335- SetOutputFile ("test-img-success.png" ).
1334+ SetOutputFileName ("test-img-success.png" ).
13361335 Get (ts .URL + "/my-image.png" )
13371336
13381337 assertError (t , err )
@@ -1348,7 +1347,7 @@ func TestOutputFileAbsPath(t *testing.T) {
13481347 outputFile := filepath .Join (getTestDataPath (), "go-resty" , "test-img-success-2.png" )
13491348
13501349 res , err := dcnlr ().
1351- SetOutputFile (outputFile ).
1350+ SetOutputFileName (outputFile ).
13521351 Get (ts .URL + "/my-image.png" )
13531352
13541353 assertError (t , err )
@@ -1358,6 +1357,51 @@ func TestOutputFileAbsPath(t *testing.T) {
13581357 assertNil (t , err )
13591358}
13601359
1360+ func TestRequestSaveResponse (t * testing.T ) {
1361+ ts := createGetServer (t )
1362+ defer ts .Close ()
1363+ defer cleanupFiles (filepath .Join (".testdata" , "go-resty" ))
1364+
1365+ c := dcnl ().
1366+ SetSaveResponse (true ).
1367+ SetOutputDirectory (filepath .Join (getTestDataPath (), "go-resty" ))
1368+
1369+ assertEqual (t , true , c .IsSaveResponse ())
1370+
1371+ t .Run ("content-disposition save response request" , func (t * testing.T ) {
1372+ outputFile := filepath .Join (getTestDataPath (), "go-resty" , "test-img-success-2.png" )
1373+ c .SetSaveResponse (false )
1374+ assertEqual (t , false , c .IsSaveResponse ())
1375+
1376+ res , err := c .R ().
1377+ SetSaveResponse (true ).
1378+ Get (ts .URL + "/my-image.png?content-disposition=true&filename=test-img-success-2.png" )
1379+
1380+ assertError (t , err )
1381+ assertEqual (t , int64 (2579468 ), res .Size ())
1382+
1383+ _ , err = os .Stat (outputFile )
1384+ assertNil (t , err )
1385+ })
1386+
1387+ t .Run ("use filename from path" , func (t * testing.T ) {
1388+ outputFile := filepath .Join (getTestDataPath (), "go-resty" , "my-image.png" )
1389+ c .SetSaveResponse (false )
1390+ assertEqual (t , false , c .IsSaveResponse ())
1391+
1392+ res , err := c .R ().
1393+ SetSaveResponse (true ).
1394+ Get (ts .URL + "/my-image.png" )
1395+
1396+ assertError (t , err )
1397+ assertEqual (t , int64 (2579468 ), res .Size ())
1398+
1399+ _ , err = os .Stat (outputFile )
1400+ assertNil (t , err )
1401+ })
1402+
1403+ }
1404+
13611405func TestContextInternal (t * testing.T ) {
13621406 ts := createGetServer (t )
13631407 defer ts .Close ()
@@ -2175,7 +2219,7 @@ func TestRequestSetResultAndSetOutputFile(t *testing.T) {
21752219 SetBody (& credentials {Username : "testuser" , Password : "testpass" }).
21762220 SetResponseBodyUnlimitedReads (true ).
21772221 SetResult (& AuthSuccess {}).
2178- SetOutputFile (outputFile ).
2222+ SetOutputFileName (outputFile ).
21792223 Post ("/login" )
21802224
21812225 assertError (t , err )
0 commit comments