@@ -57,7 +57,8 @@ def test_health_check(self):
57
57
host = '127.0.0.1'
58
58
resp = self .client .get (url , HTTP_HOST = host )
59
59
self .assertEqual (resp .status_code , 200 )
60
- self .assertEqual (resp .json (), {'status' : 200 })
60
+ self .assertEqual (resp .json (), {"status" : 200 })
61
+ self .assertEqual (resp ["CDN-Cache-Control" ], "private" )
61
62
62
63
def test_subproject_serving (self ):
63
64
url = '/projects/subproject/en/latest/awesome.html'
@@ -366,7 +367,24 @@ def test_project_nginx_serving_unicode_filename(self):
366
367
)
367
368
368
369
@override_settings (PYTHON_MEDIA = False )
369
- def test_download_files (self ):
370
+ def test_download_files_public_version (self ):
371
+ for type_ in DOWNLOADABLE_MEDIA_TYPES :
372
+ resp = self .client .get (
373
+ f"/_/downloads/en/latest/{ type_ } /" ,
374
+ HTTP_HOST = "project.dev.readthedocs.io" ,
375
+ )
376
+ self .assertEqual (resp .status_code , 200 )
377
+ extension = "zip" if type_ == MEDIA_TYPE_HTMLZIP else type_
378
+ self .assertEqual (
379
+ resp ["X-Accel-Redirect" ],
380
+ f"/proxito/media/{ type_ } /project/latest/project.{ extension } " ,
381
+ )
382
+ self .assertEqual (resp ["CDN-Cache-Control" ], "public" )
383
+
384
+ @override_settings (PYTHON_MEDIA = False , ALLOW_PRIVATE_REPOS = True )
385
+ def test_download_files_private_version (self ):
386
+ self .version .privacy_level = PRIVATE
387
+ self .version .save ()
370
388
for type_ in DOWNLOADABLE_MEDIA_TYPES :
371
389
resp = self .client .get (
372
390
f"/_/downloads/en/latest/{ type_ } /" ,
@@ -378,6 +396,7 @@ def test_download_files(self):
378
396
resp ["X-Accel-Redirect" ],
379
397
f"/proxito/media/{ type_ } /project/latest/project.{ extension } " ,
380
398
)
399
+ self .assertEqual (resp ["CDN-Cache-Control" ], "private" )
381
400
382
401
@override_settings (PYTHON_MEDIA = False )
383
402
def test_invalid_download_files (self ):
@@ -1395,11 +1414,13 @@ def test_cache_on_private_versions_custom_domain(self):
1395
1414
self .domain .save ()
1396
1415
self ._test_cache_control_header_project (expected_value = 'private' , host = self .domain .domain )
1397
1416
1398
- # HTTPS redirect respects the privacy level of the version.
1399
- resp = self .client .get ('/en/latest/' , secure = False , HTTP_HOST = self .domain .domain )
1400
- self .assertEqual (resp ['Location' ], f'https://{ self .domain .domain } /en/latest/' )
1401
- self .assertEqual (resp .headers ['CDN-Cache-Control' ], 'private' )
1402
- self .assertEqual (resp .headers ['Cache-Tag' ], 'project,project:latest' )
1417
+ # HTTPS redirect can always be cached.
1418
+ resp = self .client .get (
1419
+ "/en/latest/" , secure = False , HTTP_HOST = self .domain .domain
1420
+ )
1421
+ self .assertEqual (resp ["Location" ], f"https://{ self .domain .domain } /en/latest/" )
1422
+ self .assertEqual (resp .headers ["CDN-Cache-Control" ], "public" )
1423
+ self .assertEqual (resp .headers ["Cache-Tag" ], "project,project:latest" )
1403
1424
1404
1425
def test_cache_public_versions (self ):
1405
1426
self .project .versions .update (privacy_level = PUBLIC )
@@ -1427,15 +1448,18 @@ def test_cache_on_private_versions_custom_domain_subproject(self):
1427
1448
self .domain .save ()
1428
1449
self ._test_cache_control_header_subproject (expected_value = 'private' , host = self .domain .domain )
1429
1450
1430
- # HTTPS redirect respects the privacy level of the version .
1451
+ # HTTPS redirect can always be cached .
1431
1452
resp = self .client .get (
1432
1453
'/projects/subproject/en/latest/' ,
1433
1454
secure = False ,
1434
1455
HTTP_HOST = self .domain .domain ,
1435
1456
)
1436
- self .assertEqual (resp ['Location' ], f'https://{ self .domain .domain } /projects/subproject/en/latest/' )
1437
- self .assertEqual (resp .headers ['CDN-Cache-Control' ], 'private' )
1438
- self .assertEqual (resp .headers ['Cache-Tag' ], 'subproject,subproject:latest' )
1457
+ self .assertEqual (
1458
+ resp ["Location" ],
1459
+ f"https://{ self .domain .domain } /projects/subproject/en/latest/" ,
1460
+ )
1461
+ self .assertEqual (resp .headers ["CDN-Cache-Control" ], "public" )
1462
+ self .assertEqual (resp .headers ["Cache-Tag" ], "subproject,subproject:latest" )
1439
1463
1440
1464
def test_cache_public_versions_subproject (self ):
1441
1465
self .subproject .versions .update (privacy_level = PUBLIC )
0 commit comments