@fedify/webfinger 2.5.0-dev.2687 → 2.5.0-dev.2710
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mod.cjs +1 -1
- package/dist/mod.js +1 -1
- package/package.json +20 -3
- package/deno.json +0 -32
- package/dist/lookup.test.cjs +0 -2504
- package/dist/lookup.test.d.cts +0 -1
- package/dist/lookup.test.d.ts +0 -1
- package/dist/lookup.test.js +0 -2504
- package/src/body.ts +0 -101
- package/src/jrd.ts +0 -67
- package/src/lookup-impl.ts +0 -342
- package/src/lookup.test.ts +0 -1589
- package/src/lookup.ts +0 -332
- package/src/mod.ts +0 -7
- package/tsconfig.check.json +0 -5
- package/tsdown.config.ts +0 -33
package/src/body.ts
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
// Kept private in each package to avoid adding public API in a patch release.
|
|
2
|
-
// TODO(Jiwon Kwon): Consolidate the duplicated body helpers in @fedify/vocab-runtime,
|
|
3
|
-
// @fedify/webfinger, and @fedify/fedify into a shared implementation.
|
|
4
|
-
import { FetchError } from "@fedify/vocab-runtime";
|
|
5
|
-
import { getLogger } from "@logtape/logtape";
|
|
6
|
-
|
|
7
|
-
/** Decoded JSON body limit: 16 MiB. @internal */
|
|
8
|
-
export const MAX_BODY_SIZE: number = 16 * 1024 * 1024;
|
|
9
|
-
|
|
10
|
-
/** A body exceeded the byte limit. @internal */
|
|
11
|
-
export class BodyTooLargeError extends FetchError {
|
|
12
|
-
/** Creates an error for a body exceeding the given limit. */
|
|
13
|
-
constructor(url: string | URL, maxBytes: number) {
|
|
14
|
-
super(url, `Body exceeds the limit of ${maxBytes} bytes`);
|
|
15
|
-
this.name = "BodyTooLargeError";
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/** Validates a finite, positive byte limit. @internal */
|
|
20
|
-
function validateBodySizeLimit(maxBytes: number): void {
|
|
21
|
-
if (!Number.isSafeInteger(maxBytes) || maxBytes <= 0) {
|
|
22
|
-
throw new RangeError(
|
|
23
|
-
"The body size limit must be a positive safe integer.",
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Reads UTF-8 text while limiting bytes received from the body stream.
|
|
30
|
-
* Fetch responses are already decompressed, so the stream count is authoritative.
|
|
31
|
-
* @param message The response or request to read.
|
|
32
|
-
* @param maxBytes The maximum number of decoded bytes to read.
|
|
33
|
-
* @param url The URL to include in errors and logs.
|
|
34
|
-
* @returns The decoded body text.
|
|
35
|
-
* @throws {BodyTooLargeError} If the body exceeds the limit.
|
|
36
|
-
* @internal
|
|
37
|
-
*/
|
|
38
|
-
export async function readBoundedText(
|
|
39
|
-
message: Pick<Request, "body" | "headers">,
|
|
40
|
-
maxBytes: number,
|
|
41
|
-
url: string | URL,
|
|
42
|
-
): Promise<string> {
|
|
43
|
-
validateBodySizeLimit(maxBytes);
|
|
44
|
-
const reader = message.body?.getReader();
|
|
45
|
-
const tooLarge = (): never => {
|
|
46
|
-
getLogger(["fedify", "runtime", "body"]).warn(
|
|
47
|
-
"Body from {url} exceeds the limit of {maxBytes} bytes.",
|
|
48
|
-
{ url: url.toString(), maxBytes },
|
|
49
|
-
);
|
|
50
|
-
throw new BodyTooLargeError(url, maxBytes);
|
|
51
|
-
};
|
|
52
|
-
try {
|
|
53
|
-
// Content-Length describes the encoded body when compression is used.
|
|
54
|
-
// Only use it as an early rejection for an unencoded body.
|
|
55
|
-
const length = message.headers.get("Content-Length");
|
|
56
|
-
const encoding = message.headers.get("Content-Encoding");
|
|
57
|
-
if (
|
|
58
|
-
(encoding == null || encoding.toLowerCase() === "identity") &&
|
|
59
|
-
length != null &&
|
|
60
|
-
/^\d+$/.test(length) &&
|
|
61
|
-
Number(length) > maxBytes
|
|
62
|
-
)
|
|
63
|
-
tooLarge();
|
|
64
|
-
if (reader == null) return "";
|
|
65
|
-
let size = 0;
|
|
66
|
-
const bounded = new ReadableStream<BufferSource>(
|
|
67
|
-
{
|
|
68
|
-
async pull(controller) {
|
|
69
|
-
const { done, value } = await reader.read();
|
|
70
|
-
if (done) {
|
|
71
|
-
controller.close();
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
size += value.byteLength;
|
|
75
|
-
if (size > maxBytes) tooLarge();
|
|
76
|
-
controller.enqueue(value);
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
{ highWaterMark: 0 },
|
|
80
|
-
);
|
|
81
|
-
const textReader = bounded.pipeThrough(new TextDecoderStream()).getReader();
|
|
82
|
-
try {
|
|
83
|
-
const chunks: string[] = [];
|
|
84
|
-
while (true) {
|
|
85
|
-
const { done, value } = await textReader.read();
|
|
86
|
-
if (done) break;
|
|
87
|
-
chunks.push(value);
|
|
88
|
-
}
|
|
89
|
-
return chunks.join("");
|
|
90
|
-
} finally {
|
|
91
|
-
textReader.releaseLock();
|
|
92
|
-
}
|
|
93
|
-
} catch (error) {
|
|
94
|
-
// A cloned inbox request is a tee. Awaiting one branch's cancellation
|
|
95
|
-
// would deadlock until the other branch is canceled by the inbox handler.
|
|
96
|
-
if (reader != null) void reader.cancel(error).catch(() => {});
|
|
97
|
-
throw error;
|
|
98
|
-
} finally {
|
|
99
|
-
reader?.releaseLock();
|
|
100
|
-
}
|
|
101
|
-
}
|
package/src/jrd.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Describes a resource. See also
|
|
3
|
-
* [RFC 7033 section 4.4](https://datatracker.ietf.org/doc/html/rfc7033#section-4.4).
|
|
4
|
-
*/
|
|
5
|
-
export interface ResourceDescriptor {
|
|
6
|
-
/**
|
|
7
|
-
* A URI that identifies the entity that this descriptor describes.
|
|
8
|
-
*/
|
|
9
|
-
readonly subject?: string;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* URIs that identify the same entity as the `subject`.
|
|
13
|
-
*/
|
|
14
|
-
readonly aliases?: readonly string[];
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Conveys additional information about the `subject` of this descriptor.
|
|
18
|
-
*/
|
|
19
|
-
readonly properties?: Readonly<Record<string, string>>;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Links to other resources.
|
|
23
|
-
*/
|
|
24
|
-
readonly links?: readonly Link[];
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Represents a link. See also
|
|
29
|
-
* [RFC 7033 section 4.4.4](https://datatracker.ietf.org/doc/html/rfc7033#section-4.4.4).
|
|
30
|
-
*/
|
|
31
|
-
export interface Link {
|
|
32
|
-
/**
|
|
33
|
-
* The link's relation type, which is either a URI or a registered relation
|
|
34
|
-
* type (see [RFC 5988](https://datatracker.ietf.org/doc/html/rfc5988)).
|
|
35
|
-
*/
|
|
36
|
-
readonly rel: string;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* The media type of the target resource (see
|
|
40
|
-
* [RFC 6838](https://datatracker.ietf.org/doc/html/rfc6838)).
|
|
41
|
-
*/
|
|
42
|
-
readonly type?: string;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* A URI pointing to the target resource.
|
|
46
|
-
*/
|
|
47
|
-
readonly href?: string;
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Human-readable titles describing the link relation. If the language is
|
|
51
|
-
* unknown or unspecified, the key is `"und"`.
|
|
52
|
-
*/
|
|
53
|
-
readonly titles?: Readonly<Record<string, string>>;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Conveys additional information about the link relation.
|
|
57
|
-
*/
|
|
58
|
-
readonly properties?: Readonly<Record<string, string>>;
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* A URI Template (RFC 6570) that can be used to construct URIs by
|
|
62
|
-
* substituting variables. Used primarily for subscription endpoints
|
|
63
|
-
* where parameters like account URIs need to be dynamically inserted.
|
|
64
|
-
* @since 1.9.0
|
|
65
|
-
*/
|
|
66
|
-
readonly template?: string;
|
|
67
|
-
}
|
package/src/lookup-impl.ts
DELETED
|
@@ -1,342 +0,0 @@
|
|
|
1
|
-
import { getUserAgent, UrlError } from "@fedify/vocab-runtime";
|
|
2
|
-
import {
|
|
3
|
-
openDirectFetch,
|
|
4
|
-
openPublicFetch,
|
|
5
|
-
type PublicFetchSession,
|
|
6
|
-
} from "@fedify/vocab-runtime/internal";
|
|
7
|
-
import { getLogger } from "@logtape/logtape";
|
|
8
|
-
import { BodyTooLargeError, MAX_BODY_SIZE, readBoundedText } from "./body.ts";
|
|
9
|
-
import type { ResourceDescriptor } from "./jrd.ts";
|
|
10
|
-
import type {
|
|
11
|
-
LookupWebFingerOptions,
|
|
12
|
-
WebFingerLookupOutcome,
|
|
13
|
-
} from "./lookup.ts";
|
|
14
|
-
|
|
15
|
-
const logger = getLogger(["fedify", "webfinger", "lookup"]);
|
|
16
|
-
|
|
17
|
-
const DEFAULT_MAX_REDIRECTION = 5;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* The dependencies of {@link lookupWebFingerInternal}.
|
|
21
|
-
* @internal
|
|
22
|
-
*/
|
|
23
|
-
export interface LookupWebFingerDependencies {
|
|
24
|
-
/**
|
|
25
|
-
* Opens a fetch session for a single hop. Defaults to `openDirectFetch()`
|
|
26
|
-
* if `allowPrivateAddress` is turned on, or `openPublicFetch()` otherwise.
|
|
27
|
-
*/
|
|
28
|
-
readonly openHop?: (url: string) => Promise<PublicFetchSession>;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* The outcome of a single hop: either a redirect to follow, or the final
|
|
33
|
-
* result of the lookup.
|
|
34
|
-
*/
|
|
35
|
-
type HopResult =
|
|
36
|
-
| { readonly redirect: string; readonly statusCode: number }
|
|
37
|
-
| { readonly outcome: WebFingerLookupOutcome };
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Looks up a WebFinger resource, opening a fetch session per hop. This is
|
|
41
|
-
* the implementation of {@link lookupWebFinger}, which is not exported from
|
|
42
|
-
* the package entry point.
|
|
43
|
-
* @param resource The resource URL to look up.
|
|
44
|
-
* @param options Extra options for looking up the resource.
|
|
45
|
-
* @param deps The dependencies.
|
|
46
|
-
* @returns The resource descriptor and terminal lookup classification.
|
|
47
|
-
* @internal
|
|
48
|
-
*/
|
|
49
|
-
export async function lookupWebFingerInternal(
|
|
50
|
-
resource: URL | string,
|
|
51
|
-
options: LookupWebFingerOptions = {},
|
|
52
|
-
deps: LookupWebFingerDependencies = {},
|
|
53
|
-
): Promise<WebFingerLookupOutcome> {
|
|
54
|
-
if (typeof resource === "string") resource = new URL(resource);
|
|
55
|
-
let protocol = "https:";
|
|
56
|
-
let server: string;
|
|
57
|
-
if (resource.protocol === "acct:" || resource.protocol === "mailto:") {
|
|
58
|
-
// `acct:` (RFC 7565) and `mailto:` (RFC 6068, used as a WebFinger
|
|
59
|
-
// resource per RFC 7033 §4.5) are opaque-path schemes: their
|
|
60
|
-
// `user@host` authority lives in `pathname`, not in `host`. The
|
|
61
|
-
// WebFinger host is extracted from the substring after the last
|
|
62
|
-
// `@`, and the lookup always goes to https on that host.
|
|
63
|
-
const atPos = resource.pathname.lastIndexOf("@");
|
|
64
|
-
if (atPos < 0) return { resource: null, result: "invalid" };
|
|
65
|
-
server = resource.pathname.substring(atPos + 1);
|
|
66
|
-
// The authority part of both schemes must be a bare host: no
|
|
67
|
-
// path, query, or fragment characters embedded in it. The
|
|
68
|
-
// WHATWG URL parser routes anything after the first `?` or `#`
|
|
69
|
-
// into `search` / `hash`, so by the time we read `pathname` the
|
|
70
|
-
// only stray characters that can land in `server` are slashes.
|
|
71
|
-
// Reject those (along with an empty authority) for both schemes.
|
|
72
|
-
if (server === "" || /[/?#]/.test(server)) {
|
|
73
|
-
return { resource: null, result: "invalid" };
|
|
74
|
-
}
|
|
75
|
-
// `acct:` (RFC 7565 §3) is bare authority only: no `search` or
|
|
76
|
-
// `hash` allowed. `mailto:` (RFC 6068 §2) explicitly permits
|
|
77
|
-
// `?hfields=…` header fields and fragment identifiers, so we
|
|
78
|
-
// forward those to the remote WebFinger lookup unchanged and
|
|
79
|
-
// only enforce the stricter shape for `acct:`.
|
|
80
|
-
if (
|
|
81
|
-
resource.protocol === "acct:" &&
|
|
82
|
-
(resource.search !== "" || resource.hash !== "")
|
|
83
|
-
) {
|
|
84
|
-
return { resource: null, result: "invalid" };
|
|
85
|
-
}
|
|
86
|
-
} else {
|
|
87
|
-
protocol = resource.protocol;
|
|
88
|
-
server = resource.host;
|
|
89
|
-
}
|
|
90
|
-
let url = new URL(`${protocol}//${server}/.well-known/webfinger`);
|
|
91
|
-
url.searchParams.set("resource", resource.href);
|
|
92
|
-
const openHop =
|
|
93
|
-
deps.openHop ??
|
|
94
|
-
((hopUrl: string) =>
|
|
95
|
-
options.allowPrivateAddress === true
|
|
96
|
-
? openDirectFetch(hopUrl)
|
|
97
|
-
: openPublicFetch(hopUrl, { signal: options.signal }));
|
|
98
|
-
let redirected = 0;
|
|
99
|
-
while (true) {
|
|
100
|
-
logger.debug("Fetching WebFinger resource descriptor from {url}...", {
|
|
101
|
-
url: url.href,
|
|
102
|
-
});
|
|
103
|
-
const remoteHost = url.host;
|
|
104
|
-
const session = await openSession(url, openHop, options.signal);
|
|
105
|
-
if (session == null) {
|
|
106
|
-
return { resource: null, result: "network_error", remoteHost };
|
|
107
|
-
}
|
|
108
|
-
let hop: HopResult;
|
|
109
|
-
try {
|
|
110
|
-
hop = await fetchHop(session, url, options);
|
|
111
|
-
} finally {
|
|
112
|
-
await session.close();
|
|
113
|
-
}
|
|
114
|
-
if ("outcome" in hop) return hop.outcome;
|
|
115
|
-
redirected++;
|
|
116
|
-
const maxRedirection = options.maxRedirection ?? DEFAULT_MAX_REDIRECTION;
|
|
117
|
-
if (redirected > maxRedirection) {
|
|
118
|
-
logger.error(
|
|
119
|
-
"Too many redirections ({redirections}) while fetching WebFinger " +
|
|
120
|
-
"resource descriptor.",
|
|
121
|
-
{ redirections: redirected },
|
|
122
|
-
);
|
|
123
|
-
return {
|
|
124
|
-
resource: null,
|
|
125
|
-
result: "invalid",
|
|
126
|
-
statusCode: hop.statusCode,
|
|
127
|
-
remoteHost,
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
// The request URL is the base, since a pinned response's url can be an
|
|
131
|
-
// IP address URL:
|
|
132
|
-
let redirectedUrl: URL;
|
|
133
|
-
try {
|
|
134
|
-
redirectedUrl = new URL(hop.redirect, url);
|
|
135
|
-
} catch (error) {
|
|
136
|
-
logger.error(
|
|
137
|
-
"Invalid Location header while following WebFinger redirect: {error}",
|
|
138
|
-
{ url: url.href, error },
|
|
139
|
-
);
|
|
140
|
-
return {
|
|
141
|
-
resource: null,
|
|
142
|
-
result: "invalid",
|
|
143
|
-
statusCode: hop.statusCode,
|
|
144
|
-
remoteHost,
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
if (redirectedUrl.protocol !== url.protocol) {
|
|
148
|
-
logger.error(
|
|
149
|
-
"Redirected to a different protocol ({protocol} to " +
|
|
150
|
-
"{redirectedProtocol}) while fetching WebFinger resource " +
|
|
151
|
-
"descriptor.",
|
|
152
|
-
{
|
|
153
|
-
protocol: url.protocol,
|
|
154
|
-
redirectedProtocol: redirectedUrl.protocol,
|
|
155
|
-
},
|
|
156
|
-
);
|
|
157
|
-
return {
|
|
158
|
-
resource: null,
|
|
159
|
-
result: "invalid",
|
|
160
|
-
statusCode: hop.statusCode,
|
|
161
|
-
remoteHost,
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
url = redirectedUrl;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Opens a fetch session for a hop. A disallowed URL, a failed DNS lookup,
|
|
170
|
-
* or an aborted lookup yields `null` instead of an error.
|
|
171
|
-
*/
|
|
172
|
-
async function openSession(
|
|
173
|
-
url: URL,
|
|
174
|
-
openHop: (url: string) => Promise<PublicFetchSession>,
|
|
175
|
-
signal: AbortSignal | undefined,
|
|
176
|
-
): Promise<PublicFetchSession | null> {
|
|
177
|
-
try {
|
|
178
|
-
return await openHop(url.href);
|
|
179
|
-
} catch (e) {
|
|
180
|
-
if (e instanceof UrlError) {
|
|
181
|
-
if (e.reason === "dns") {
|
|
182
|
-
logger.debug("DNS lookup failed for {url}", {
|
|
183
|
-
url: url.href,
|
|
184
|
-
error: e,
|
|
185
|
-
});
|
|
186
|
-
} else {
|
|
187
|
-
logger.error("Invalid URL for WebFinger resource descriptor: {error}", {
|
|
188
|
-
error: e,
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
return null;
|
|
192
|
-
}
|
|
193
|
-
if (signal?.aborted) {
|
|
194
|
-
logger.debug("Failed to fetch WebFinger resource descriptor: {error}", {
|
|
195
|
-
url: url.href,
|
|
196
|
-
error: e,
|
|
197
|
-
});
|
|
198
|
-
return null;
|
|
199
|
-
}
|
|
200
|
-
throw e;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* Fetches a hop with the given session, and consumes the response body or
|
|
206
|
-
* starts cancelling it before returning. The caller closes the session.
|
|
207
|
-
*/
|
|
208
|
-
async function fetchHop(
|
|
209
|
-
session: PublicFetchSession,
|
|
210
|
-
url: URL,
|
|
211
|
-
options: LookupWebFingerOptions,
|
|
212
|
-
): Promise<HopResult> {
|
|
213
|
-
let response: Response;
|
|
214
|
-
try {
|
|
215
|
-
response = await session.fetch(url, {
|
|
216
|
-
headers: {
|
|
217
|
-
Accept: "application/jrd+json",
|
|
218
|
-
"User-Agent":
|
|
219
|
-
typeof options.userAgent === "string"
|
|
220
|
-
? options.userAgent
|
|
221
|
-
: getUserAgent(options.userAgent),
|
|
222
|
-
},
|
|
223
|
-
redirect: "manual",
|
|
224
|
-
signal: options.signal,
|
|
225
|
-
});
|
|
226
|
-
} catch (error) {
|
|
227
|
-
logger.debug("Failed to fetch WebFinger resource descriptor: {error}", {
|
|
228
|
-
url: url.href,
|
|
229
|
-
error,
|
|
230
|
-
});
|
|
231
|
-
return {
|
|
232
|
-
outcome: {
|
|
233
|
-
resource: null,
|
|
234
|
-
result: "network_error",
|
|
235
|
-
remoteHost: url.host,
|
|
236
|
-
},
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
if (
|
|
240
|
-
response.status >= 300 &&
|
|
241
|
-
response.status < 400 &&
|
|
242
|
-
response.headers.has("Location")
|
|
243
|
-
) {
|
|
244
|
-
cancelBody(response, url);
|
|
245
|
-
return {
|
|
246
|
-
redirect: response.headers.get("Location")!,
|
|
247
|
-
statusCode: response.status,
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
if (!response.ok) {
|
|
251
|
-
logger.debug(
|
|
252
|
-
"Failed to fetch WebFinger resource descriptor: {status} {statusText}.",
|
|
253
|
-
{
|
|
254
|
-
url: url.href,
|
|
255
|
-
status: response.status,
|
|
256
|
-
statusText: response.statusText,
|
|
257
|
-
},
|
|
258
|
-
);
|
|
259
|
-
cancelBody(response, url);
|
|
260
|
-
return {
|
|
261
|
-
outcome: {
|
|
262
|
-
resource: null,
|
|
263
|
-
result:
|
|
264
|
-
response.status === 404 || response.status === 410
|
|
265
|
-
? "not_found"
|
|
266
|
-
: "error",
|
|
267
|
-
statusCode: response.status,
|
|
268
|
-
remoteHost: url.host,
|
|
269
|
-
},
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
try {
|
|
273
|
-
const parsed: unknown = JSON.parse(
|
|
274
|
-
await readBoundedText(response, MAX_BODY_SIZE, url),
|
|
275
|
-
);
|
|
276
|
-
// A JSON primitive, null, or array is not a resource descriptor.
|
|
277
|
-
if (
|
|
278
|
-
typeof parsed !== "object" ||
|
|
279
|
-
parsed === null ||
|
|
280
|
-
Array.isArray(parsed)
|
|
281
|
-
) {
|
|
282
|
-
return {
|
|
283
|
-
outcome: {
|
|
284
|
-
resource: null,
|
|
285
|
-
result: "invalid",
|
|
286
|
-
statusCode: response.status,
|
|
287
|
-
remoteHost: url.host,
|
|
288
|
-
},
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
return {
|
|
292
|
-
outcome: {
|
|
293
|
-
resource: parsed as ResourceDescriptor,
|
|
294
|
-
result: "found",
|
|
295
|
-
statusCode: response.status,
|
|
296
|
-
remoteHost: url.host,
|
|
297
|
-
},
|
|
298
|
-
};
|
|
299
|
-
} catch (e) {
|
|
300
|
-
if (e instanceof BodyTooLargeError) {
|
|
301
|
-
return {
|
|
302
|
-
outcome: {
|
|
303
|
-
resource: null,
|
|
304
|
-
result: "invalid",
|
|
305
|
-
statusCode: response.status,
|
|
306
|
-
remoteHost: url.host,
|
|
307
|
-
},
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
if (e instanceof SyntaxError) {
|
|
311
|
-
logger.debug(
|
|
312
|
-
"Failed to parse WebFinger resource descriptor as JSON: {error}",
|
|
313
|
-
{ error: e },
|
|
314
|
-
);
|
|
315
|
-
return {
|
|
316
|
-
outcome: {
|
|
317
|
-
resource: null,
|
|
318
|
-
result: "invalid",
|
|
319
|
-
statusCode: response.status,
|
|
320
|
-
remoteHost: url.host,
|
|
321
|
-
},
|
|
322
|
-
};
|
|
323
|
-
}
|
|
324
|
-
throw e;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
/**
|
|
329
|
-
* Starts cancelling a response body that is not read, without waiting for it
|
|
330
|
-
* to settle. The cancellation of a branch of a tee (e.g., a body cloned by
|
|
331
|
-
* a fetch mock) settles only after the other branch is cancelled too, per
|
|
332
|
-
* the Streams standard, so awaiting it could block forever. A failure is
|
|
333
|
-
* only logged.
|
|
334
|
-
*/
|
|
335
|
-
function cancelBody(response: Response, url: URL): void {
|
|
336
|
-
response.body?.cancel().catch((error) => {
|
|
337
|
-
logger.debug("Failed to cancel the response body from {url}: {error}", {
|
|
338
|
-
url: url.href,
|
|
339
|
-
error,
|
|
340
|
-
});
|
|
341
|
-
});
|
|
342
|
-
}
|