From 4b79ee12763d76c5ff9f869497b7d63a92628319 Mon Sep 17 00:00:00 2001 From: Mia <49593536+mia-pi-git@users.noreply.github.com> Date: Tue, 28 Nov 2023 12:27:38 -0600 Subject: [PATCH] Net: Expose response data to consumers Headers are useful for a couple of Net consumers (rate limit data, that sort of thing.) --- lib/net.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/net.ts b/lib/net.ts index f9f7dc5a63..7d663e617b 100644 --- a/lib/net.ts +++ b/lib/net.ts @@ -172,6 +172,8 @@ export class NetStream extends Streams.ReadWriteStream { } export class NetRequest { uri: string; + /** Response from last request, made so response stuff is available without being hacky */ + response?: http.IncomingMessage; constructor(uri: string) { this.uri = uri; } @@ -202,6 +204,7 @@ export class NetRequest { async get(opts: NetRequestOptions = {}): Promise { const stream = this.getStream(opts); const response = await stream.response; + if (response) this.response = response; if (response && response.statusCode !== 200) { throw new HttpError(response.statusMessage || "Connection error", response.statusCode, await stream.readAll()); }