cache generated host-meta xml
This commit is contained in:
parent
28694e28cf
commit
82eb5415ab
4 changed files with 16 additions and 3 deletions
|
|
@ -15,8 +15,7 @@ module DiasporaFederation
|
||||||
#
|
#
|
||||||
# GET /.well-known/host-meta
|
# GET /.well-known/host-meta
|
||||||
def host_meta
|
def host_meta
|
||||||
doc = WebFinger::HostMeta.from_base_url(DiasporaFederation.server_uri.to_s)
|
render body: WebfingerController.host_meta_xml, content_type: "application/xrd+xml"
|
||||||
render body: doc.to_xml, content_type: "application/xrd+xml"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
@ -34,6 +33,13 @@ module DiasporaFederation
|
||||||
|
|
||||||
private
|
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)
|
def find_person(query)
|
||||||
DiasporaFederation.person_class.find_local_by_diaspora_handle(query.strip.downcase.gsub("acct:", ""))
|
DiasporaFederation.person_class.find_local_by_diaspora_handle(query.strip.downcase.gsub("acct:", ""))
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
require "diaspora_federation/engine"
|
require "diaspora_federation/engine"
|
||||||
require "diaspora_federation/logging"
|
require "diaspora_federation/logging"
|
||||||
|
|
||||||
require "diaspora_federation/webfinger"
|
require "diaspora_federation/web_finger"
|
||||||
|
|
||||||
##
|
##
|
||||||
# diaspora* federation rails engine
|
# diaspora* federation rails engine
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ module DiasporaFederation
|
||||||
describe "#host_meta" do
|
describe "#host_meta" do
|
||||||
before do
|
before do
|
||||||
DiasporaFederation.server_uri = URI("http://localhost:3000/")
|
DiasporaFederation.server_uri = URI("http://localhost:3000/")
|
||||||
|
WebfingerController.instance_variable_set(:@host_meta_xml, nil) # clear cache
|
||||||
end
|
end
|
||||||
|
|
||||||
it "succeeds" do
|
it "succeeds" do
|
||||||
|
|
@ -26,6 +27,12 @@ module DiasporaFederation
|
||||||
expect(WebFinger::HostMeta).to receive(:from_base_url).with("http://localhost:3000/").and_call_original
|
expect(WebFinger::HostMeta).to receive(:from_base_url).with("http://localhost:3000/").and_call_original
|
||||||
get :host_meta
|
get :host_meta
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe "#legacy_webfinger" do
|
describe "#legacy_webfinger" do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue