Minor improvements
- WebFinger: detect when to use http or https, better function naming - RequestPool: add user agent
This commit is contained in:
@@ -18,11 +18,15 @@ private bool checkValidWebfingerResponse(Response rs) {
|
||||
return AcceptedWebfingerContentType.canFind(rs.responseHeaders()["content-type"].split(";")[0]);
|
||||
}
|
||||
|
||||
PRequest buildRequest(string uri, string[string] params) {
|
||||
private PRequest buildRequest(string uri, string[string] params) {
|
||||
PRequest rq = PRequest();
|
||||
string schema = "https";
|
||||
|
||||
if (uri.startsWith("localhost"))
|
||||
schema = "http";
|
||||
|
||||
rq.method = "GET";
|
||||
rq.url = format("https://%s/.well-known/webfinger", uri);
|
||||
rq.url = format("%s://%s/.well-known/webfinger", schema, uri);
|
||||
rq.headers["Accept"] = AcceptedWebfingerContentType;
|
||||
|
||||
QueryParam[] p;
|
||||
@@ -41,8 +45,8 @@ PRequest buildAcctRequest(string uri, string acct) {
|
||||
return buildRequest(uri, params);
|
||||
}
|
||||
|
||||
JSONValue requestAcct(string uri, string acct) {
|
||||
Response rs = RP.request(buildAcctRequest(uri, acct), true);
|
||||
JSONValue wfRequestAccount(string uri, string acct) {
|
||||
Response rs = Rp.request(buildAcctRequest(uri, acct), true);
|
||||
|
||||
if (checkValidWebfingerResponse(rs) == false)
|
||||
throw new Exception("Invalid webfinger response");
|
||||
@@ -50,11 +54,8 @@ JSONValue requestAcct(string uri, string acct) {
|
||||
return parseJSON(rs.responseBody().toString());
|
||||
}
|
||||
|
||||
JSONValue requestAcct(string handle) {
|
||||
string uri, acct;
|
||||
JSONValue wfRequestAccount(string handle) {
|
||||
string[] uriAcct = handle.split("@")[$ - 2 .. $];
|
||||
|
||||
uri = handle.split("@")[$ - 1];
|
||||
acct = handle.split("@")[$ - 2];
|
||||
|
||||
return requestAcct(uri, acct);
|
||||
return wfRequestAccount(uriAcct[1], uriAcct[0]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user