cache generated host-meta xml

This commit is contained in:
Benjamin Neff 2015-06-19 01:52:12 +02:00
parent 28694e28cf
commit 82eb5415ab
4 changed files with 16 additions and 3 deletions

View file

@ -15,8 +15,7 @@ module DiasporaFederation
#
# GET /.well-known/host-meta
def host_meta
doc = WebFinger::HostMeta.from_base_url(DiasporaFederation.server_uri.to_s)
render body: doc.to_xml, content_type: "application/xrd+xml"
render body: WebfingerController.host_meta_xml, content_type: "application/xrd+xml"
end
##
@ -34,6 +33,13 @@ module DiasporaFederation
private
##
# creates the host-meta xml with the configured server_uri and caches it
# @return [String] XML string
def self.host_meta_xml
@host_meta_xml ||= WebFinger::HostMeta.from_base_url(DiasporaFederation.server_uri.to_s).to_xml
end
def find_person(query)
DiasporaFederation.person_class.find_local_by_diaspora_handle(query.strip.downcase.gsub("acct:", ""))
end

View file

@ -1,7 +1,7 @@
require "diaspora_federation/engine"
require "diaspora_federation/logging"
require "diaspora_federation/webfinger"
require "diaspora_federation/web_finger"
##
# diaspora* federation rails engine

View file

@ -5,6 +5,7 @@ module DiasporaFederation
describe "#host_meta" do
before do
DiasporaFederation.server_uri = URI("http://localhost:3000/")
WebfingerController.instance_variable_set(:@host_meta_xml, nil) # clear cache
end
it "succeeds" do
@ -26,6 +27,12 @@ module DiasporaFederation
expect(WebFinger::HostMeta).to receive(:from_base_url).with("http://localhost:3000/").and_call_original
get :host_meta
end
it "caches the xml" do
expect(WebFinger::HostMeta).to receive(:from_base_url).exactly(1).times.and_call_original
get :host_meta
get :host_meta
end
end
describe "#legacy_webfinger" do