From a823863d0b0e55ff6625161998401f5bd0641969 Mon Sep 17 00:00:00 2001 From: CPTProgrammer <46586216+CPTProgrammer@users.noreply.github.com> Date: Mon, 6 Jul 2026 23:13:17 +0800 Subject: [PATCH] Make User-Agent header optional in ModrinthClient --- src/lib/modrinth/client.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/lib/modrinth/client.ts b/src/lib/modrinth/client.ts index 26ac2d7..086bc8a 100644 --- a/src/lib/modrinth/client.ts +++ b/src/lib/modrinth/client.ts @@ -2,19 +2,22 @@ export class ModrinthClient { private base = "https://api.modrinth.com/v2"; private token: string; - private userAgent: string; + private userAgent?: string; constructor(token: string, userAgent?: string) { this.token = token; - this.userAgent = userAgent ?? ""; + this.userAgent = userAgent; } - /** 构造通用请求头(Authorization + User-Agent)。 */ + /** 构造通用请求头(Authorization,以及可选的 User-Agent)。 */ private headers(): Record { - return { + const h: Record = { Authorization: this.token, - "User-Agent": this.userAgent, }; + if (this.userAgent) { + h["User-Agent"] = this.userAgent; + } + return h; } /** 发送 GET 请求并解析 JSON 响应体。 */