mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 01:32:36 +02:00
Fix for cache purging for subdir default indexes
This commit is contained in:
parent
46b402a633
commit
0428a1246e
3 changed files with 15 additions and 6 deletions
|
@ -634,6 +634,7 @@ class Site < Sequel::Model
|
||||||
PurgeCacheOrderWorker.perform_async username, relative_path
|
PurgeCacheOrderWorker.perform_async username, relative_path
|
||||||
|
|
||||||
purge_file_path = Pathname(relative_path).dirname.to_s
|
purge_file_path = Pathname(relative_path).dirname.to_s
|
||||||
|
purge_file_path += '/' if purge_file_path != '/'
|
||||||
|
|
||||||
PurgeCacheOrderWorker.perform_async username, '/?surf=1' if purge_file_path == '/'
|
PurgeCacheOrderWorker.perform_async username, '/?surf=1' if purge_file_path == '/'
|
||||||
PurgeCacheOrderWorker.perform_async username, purge_file_path
|
PurgeCacheOrderWorker.perform_async username, purge_file_path
|
||||||
|
|
|
@ -217,6 +217,14 @@ describe 'site_files' do
|
||||||
@site.reload.title.must_equal title
|
@site.reload.title.must_equal title
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'purges cache for /subdir/' do # (not /subdir which is just a redirect to /subdir/)
|
||||||
|
upload(
|
||||||
|
'dir' => 'subdir',
|
||||||
|
'files[]' => Rack::Test::UploadedFile.new('./tests/files/index.html', 'text/html')
|
||||||
|
)
|
||||||
|
PurgeCacheOrderWorker.jobs.select {|j| j['args'].last == '/subdir/'}.length.must_equal 1
|
||||||
|
end
|
||||||
|
|
||||||
it 'succeeds with valid file' do
|
it 'succeeds with valid file' do
|
||||||
initial_space_used = @site.space_used
|
initial_space_used = @site.space_used
|
||||||
uploaded_file = Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
uploaded_file = Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||||
|
|
|
@ -6,7 +6,7 @@ describe PurgeCacheWorker do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'handles 404 without exception' do
|
it 'handles 404 without exception' do
|
||||||
stub_request(:head, "http://#{@test_ip}/test.jpg").
|
stub_request(:head, "https://#{@test_ip}/test.jpg").
|
||||||
with(headers: {'Host' => 'kyledrake.neocities.org', 'Cache-Purge' => '1'})
|
with(headers: {'Host' => 'kyledrake.neocities.org', 'Cache-Purge' => '1'})
|
||||||
.to_return(status: 404)
|
.to_return(status: 404)
|
||||||
|
|
||||||
|
@ -15,23 +15,23 @@ describe PurgeCacheWorker do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sends a purge request' do
|
it 'sends a purge request' do
|
||||||
stub_request(:head, "http://#{@test_ip}/test.jpg").
|
stub_request(:head, "https://#{@test_ip}/test.jpg").
|
||||||
with(headers: {'Host' => 'kyledrake.neocities.org', 'Cache-Purge' => '1'})
|
with(headers: {'Host' => 'kyledrake.neocities.org', 'Cache-Purge' => '1'})
|
||||||
.to_return(status: 200)
|
.to_return(status: 200)
|
||||||
|
|
||||||
worker = PurgeCacheWorker.new
|
worker = PurgeCacheWorker.new
|
||||||
worker.perform @test_ip, 'kyledrake', '/test.jpg'
|
worker.perform @test_ip, 'kyledrake', '/test.jpg'
|
||||||
|
|
||||||
assert_requested :head, "http://#{@test_ip}/test.jpg"
|
assert_requested :head, "https://#{@test_ip}/test.jpg"
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'handles spaces correctly' do
|
it 'handles spaces correctly' do
|
||||||
stub_request(:head, "http://#{@test_ip}/te st.jpg").
|
stub_request(:head, "https://#{@test_ip}/te st.jpg").
|
||||||
with(headers: {'Host' => 'kyledrake.neocities.org', 'Cache-Purge' => '1'})
|
with(headers: {'Host' => 'kyledrake.neocities.org', 'Cache-Purge' => '1'})
|
||||||
.to_return(status: 200)
|
.to_return(status: 200)
|
||||||
|
|
||||||
url = Addressable::URI.encode_component(
|
url = Addressable::URI.encode_component(
|
||||||
"http://#{@test_ip}/te st.jpg",
|
"https://#{@test_ip}/te st.jpg",
|
||||||
Addressable::URI::CharacterClasses::QUERY
|
Addressable::URI::CharacterClasses::QUERY
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ describe PurgeCacheWorker do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'works without forward slash' do
|
it 'works without forward slash' do
|
||||||
stub_request(:head, "http://#{@test_ip}/test.jpg").
|
stub_request(:head, "https://#{@test_ip}/test.jpg").
|
||||||
with(headers: {'Host' => 'kyledrake.neocities.org', 'Cache-Purge' => '1'})
|
with(headers: {'Host' => 'kyledrake.neocities.org', 'Cache-Purge' => '1'})
|
||||||
.to_return(status: 200)
|
.to_return(status: 200)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue