@@ -58,7 +58,8 @@ def test_health_check(self):
58
58
host = '127.0.0.1'
59
59
resp = self .client .get (url , HTTP_HOST = host )
60
60
self .assertEqual (resp .status_code , 200 )
61
- self .assertEqual (resp .json (), {'status' : 200 })
61
+ self .assertEqual (resp .json (), {"status" : 200 })
62
+ self .assertEqual (resp ["CDN-Cache-Control" ], "private" )
62
63
63
64
def test_subproject_serving (self ):
64
65
url = '/projects/subproject/en/latest/awesome.html'
@@ -397,7 +398,24 @@ def test_project_nginx_serving_unicode_filename(self):
397
398
)
398
399
399
400
@override_settings (PYTHON_MEDIA = False )
400
- def test_download_files (self ):
401
+ def test_download_files_public_version (self ):
402
+ for type_ in DOWNLOADABLE_MEDIA_TYPES :
403
+ resp = self .client .get (
404
+ f"/_/downloads/en/latest/{ type_ } /" ,
405
+ HTTP_HOST = "project.dev.readthedocs.io" ,
406
+ )
407
+ self .assertEqual (resp .status_code , 200 )
408
+ extension = "zip" if type_ == MEDIA_TYPE_HTMLZIP else type_
409
+ self .assertEqual (
410
+ resp ["X-Accel-Redirect" ],
411
+ f"/proxito/media/{ type_ } /project/latest/project.{ extension } " ,
412
+ )
413
+ self .assertEqual (resp ["CDN-Cache-Control" ], "public" )
414
+
415
+ @override_settings (PYTHON_MEDIA = False , ALLOW_PRIVATE_REPOS = True )
416
+ def test_download_files_private_version (self ):
417
+ self .version .privacy_level = PRIVATE
418
+ self .version .save ()
401
419
for type_ in DOWNLOADABLE_MEDIA_TYPES :
402
420
resp = self .client .get (
403
421
f"/_/downloads/en/latest/{ type_ } /" ,
@@ -409,6 +427,7 @@ def test_download_files(self):
409
427
resp ["X-Accel-Redirect" ],
410
428
f"/proxito/media/{ type_ } /project/latest/project.{ extension } " ,
411
429
)
430
+ self .assertEqual (resp ["CDN-Cache-Control" ], "private" )
412
431
413
432
@override_settings (PYTHON_MEDIA = False )
414
433
def test_invalid_download_files (self ):
@@ -1460,11 +1479,13 @@ def test_cache_on_private_versions_custom_domain(self):
1460
1479
self .domain .save ()
1461
1480
self ._test_cache_control_header_project (expected_value = 'private' , host = self .domain .domain )
1462
1481
1463
- # HTTPS redirect respects the privacy level of the version.
1464
- resp = self .client .get ('/en/latest/' , secure = False , HTTP_HOST = self .domain .domain )
1465
- self .assertEqual (resp ['Location' ], f'https://{ self .domain .domain } /en/latest/' )
1466
- self .assertEqual (resp .headers ['CDN-Cache-Control' ], 'private' )
1467
- self .assertEqual (resp .headers ['Cache-Tag' ], 'project,project:latest' )
1482
+ # HTTPS redirect can always be cached.
1483
+ resp = self .client .get (
1484
+ "/en/latest/" , secure = False , HTTP_HOST = self .domain .domain
1485
+ )
1486
+ self .assertEqual (resp ["Location" ], f"https://{ self .domain .domain } /en/latest/" )
1487
+ self .assertEqual (resp .headers ["CDN-Cache-Control" ], "public" )
1488
+ self .assertEqual (resp .headers ["Cache-Tag" ], "project,project:latest" )
1468
1489
1469
1490
def test_cache_public_versions (self ):
1470
1491
self .project .versions .update (privacy_level = PUBLIC )
@@ -1492,15 +1513,18 @@ def test_cache_on_private_versions_custom_domain_subproject(self):
1492
1513
self .domain .save ()
1493
1514
self ._test_cache_control_header_subproject (expected_value = 'private' , host = self .domain .domain )
1494
1515
1495
- # HTTPS redirect respects the privacy level of the version .
1516
+ # HTTPS redirect can always be cached .
1496
1517
resp = self .client .get (
1497
1518
'/projects/subproject/en/latest/' ,
1498
1519
secure = False ,
1499
1520
HTTP_HOST = self .domain .domain ,
1500
1521
)
1501
- self .assertEqual (resp ['Location' ], f'https://{ self .domain .domain } /projects/subproject/en/latest/' )
1502
- self .assertEqual (resp .headers ['CDN-Cache-Control' ], 'private' )
1503
- self .assertEqual (resp .headers ['Cache-Tag' ], 'subproject,subproject:latest' )
1522
+ self .assertEqual (
1523
+ resp ["Location" ],
1524
+ f"https://{ self .domain .domain } /projects/subproject/en/latest/" ,
1525
+ )
1526
+ self .assertEqual (resp .headers ["CDN-Cache-Control" ], "public" )
1527
+ self .assertEqual (resp .headers ["Cache-Tag" ], "subproject,subproject:latest" )
1504
1528
1505
1529
def test_cache_public_versions_subproject (self ):
1506
1530
self .subproject .versions .update (privacy_level = PUBLIC )
0 commit comments