Return 204 instead of 200 for CDN cache
This commit is contained in:
parent
e30e538d5f
commit
5e3e2bf688
|
|
@ -228,7 +228,7 @@ class AdminController extends Controller
|
||||||
{
|
{
|
||||||
$form->checkbox('force_ssl')->label()->hint();
|
$form->checkbox('force_ssl')->label()->hint();
|
||||||
$form->checkbox('auto_detect_asset_url')->label()->description();
|
$form->checkbox('auto_detect_asset_url')->label()->description();
|
||||||
$form->checkbox('return_200_when_notfound')->label()->description();
|
$form->checkbox('return_204_when_notfound')->label()->description();
|
||||||
|
|
||||||
$form->text('cache_expire_time')->hint(OptionForm::AUTO_DETECT);
|
$form->text('cache_expire_time')->hint(OptionForm::AUTO_DETECT);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,12 +38,10 @@ class CheckPlayerExist
|
||||||
if (! Player::where('player_name', $player_name)->get()->isEmpty())
|
if (! Player::where('player_name', $player_name)->get()->isEmpty())
|
||||||
return $next($request);
|
return $next($request);
|
||||||
|
|
||||||
if (option('return_200_when_notfound')) {
|
if (option('return_204_when_notfound')) {
|
||||||
return json([
|
return response('', 204, [
|
||||||
'player_name' => $player_name,
|
'Cache-Control' => 'public, max-age='.option('cache_expire_time')
|
||||||
'errno' => 404,
|
]);
|
||||||
'msg' => 'Player Not Found.'
|
|
||||||
])->header('Cache-Control', 'public, max-age='.option('cache_expire_time'));
|
|
||||||
} else {
|
} else {
|
||||||
return abort(404, trans('general.unexistent-player'));
|
return abort(404, trans('general.unexistent-player'));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ return [
|
||||||
'auto_del_invalid_texture' => 'false',
|
'auto_del_invalid_texture' => 'false',
|
||||||
'allow_downloading_texture' => 'true',
|
'allow_downloading_texture' => 'true',
|
||||||
'texture_name_regexp' => '',
|
'texture_name_regexp' => '',
|
||||||
'return_200_when_notfound' => 'false',
|
'return_204_when_notfound' => 'false',
|
||||||
'cache_expire_time' => '31536000',
|
'cache_expire_time' => '31536000',
|
||||||
'max_upload_file_size' => '1024',
|
'max_upload_file_size' => '1024',
|
||||||
'force_ssl' => 'false',
|
'force_ssl' => 'false',
|
||||||
|
|
|
||||||
|
|
@ -136,9 +136,9 @@ resources:
|
||||||
title: Assets URL
|
title: Assets URL
|
||||||
label: Determine assets url automatically.
|
label: Determine assets url automatically.
|
||||||
description: Load asset files according to current URL. The site url will be used if this is not enabled. Please unable this if requests don't go through CDN.
|
description: Load asset files according to current URL. The site url will be used if this is not enabled. Please unable this if requests don't go through CDN.
|
||||||
return_200_when_notfound:
|
return_204_when_notfound:
|
||||||
title: HTTP Response Code
|
title: HTTP Response Code
|
||||||
label: Return 200 instead of 404 when requesting un-existent player.
|
label: Return 204 instead of 404 when requesting un-existent player.
|
||||||
description: If your CDN doesn't cache 404 pages, please turn this on. A flood of requests to un-existent players will greatly slow down the site.
|
description: If your CDN doesn't cache 404 pages, please turn this on. A flood of requests to un-existent players will greatly slow down the site.
|
||||||
cache_expire_time:
|
cache_expire_time:
|
||||||
title: Cache Exipre Time
|
title: Cache Exipre Time
|
||||||
|
|
|
||||||
|
|
@ -136,9 +136,9 @@ resources:
|
||||||
title: 资源地址
|
title: 资源地址
|
||||||
label: 自动判断资源文件地址
|
label: 自动判断资源文件地址
|
||||||
description: 根据当前 URL 自动加载资源文件,如果关闭则将根据「站点地址」填写的内容加载。如果出现 CDN 回源问题请关闭
|
description: 根据当前 URL 自动加载资源文件,如果关闭则将根据「站点地址」填写的内容加载。如果出现 CDN 回源问题请关闭
|
||||||
return_200_when_notfound:
|
return_204_when_notfound:
|
||||||
title: HTTP 响应码
|
title: HTTP 响应码
|
||||||
label: 请求不存在的角色时返回 200 而不是 404
|
label: 请求不存在的角色时返回 204 而不是 404
|
||||||
description: 如果你的 CDN 不缓存 404 页面,请打开此项。否则大量对不存在角色的 Profile 请求会加重站点负载。
|
description: 如果你的 CDN 不缓存 404 页面,请打开此项。否则大量对不存在角色的 Profile 请求会加重站点负载。
|
||||||
cache_expire_time:
|
cache_expire_time:
|
||||||
title: 缓存失效时间
|
title: 缓存失效时间
|
||||||
|
|
|
||||||
|
|
@ -140,12 +140,12 @@ class AdminControllerTest extends BrowserKitTestCase
|
||||||
$this->visit('/admin/options')
|
$this->visit('/admin/options')
|
||||||
->check('force_ssl')
|
->check('force_ssl')
|
||||||
->uncheck('auto_detect_asset_url')
|
->uncheck('auto_detect_asset_url')
|
||||||
->check('return_200_when_notfound')
|
->check('return_204_when_notfound')
|
||||||
->type('0', 'cache_expire_time')
|
->type('0', 'cache_expire_time')
|
||||||
->press('submit_resources');
|
->press('submit_resources');
|
||||||
$this->assertTrue(option('force_ssl'));
|
$this->assertTrue(option('force_ssl'));
|
||||||
$this->assertFalse(option('auto_detect_asset_url'));
|
$this->assertFalse(option('auto_detect_asset_url'));
|
||||||
$this->assertTrue(option('return_200_when_notfound'));
|
$this->assertTrue(option('return_204_when_notfound'));
|
||||||
$this->assertEquals('0', option('cache_expire_time'));
|
$this->assertEquals('0', option('cache_expire_time'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -95,14 +95,8 @@ class MiddlewareTest extends TestCase
|
||||||
->assertStatus(404)
|
->assertStatus(404)
|
||||||
->assertSee('Un-existent player');
|
->assertSee('Un-existent player');
|
||||||
|
|
||||||
Option::set('return_200_when_notfound', true);
|
Option::set('return_204_when_notfound', true);
|
||||||
$this->getJson('/nope.json')
|
$this->getJson('/nope.json')->assertStatus(204);
|
||||||
->assertSuccessful()
|
|
||||||
->assertJson([
|
|
||||||
'player_name' => 'nope',
|
|
||||||
'errno' => 404,
|
|
||||||
'msg' => 'Player Not Found.'
|
|
||||||
]);
|
|
||||||
|
|
||||||
$player = factory(App\Models\Player::class)->create();
|
$player = factory(App\Models\Player::class)->create();
|
||||||
$this->getJson("/{$player->player_name}.json")
|
$this->getJson("/{$player->player_name}.json")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user