ensure forward slash

This commit is contained in:
Kyle Drake 2015-07-03 16:09:42 -07:00
parent a5fdbfe4a7
commit bb44965c8e
2 changed files with 12 additions and 0 deletions

View file

@ -52,4 +52,13 @@ describe PurgeCacheWorker do
assert_requested :get, url
end
it 'works without forward slash' do
stub_request(:get, "http://#{@test_ip}/:cache/purge/test.jpg").
with(headers: {'Host' => 'kyledrake.neocities.org'})
.to_return(status: 200)
worker = PurgeCacheWorker.new
worker.perform @test_ip, 'kyledrake', 'test.jpg'
end
end

View file

@ -10,6 +10,9 @@ class PurgeCacheWorker
end
def perform(proxy_ip, username, path)
# Must always have a forward slash
path = '/' + path if path[0] != '/'
url = Addressable::URI.encode_component(
"http://#{proxy_ip}/:cache/purge#{path}",
Addressable::URI::CharacterClasses::QUERY