Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit c17ac89

Browse files
authored
Merge pull request #267 from Taillis-Labs/my-req-branch
feat(server): Return the `Host` or `X-Forwarded-Host` header field to a hostname.
2 parents 4fb9940 + ab717f8 commit c17ac89

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

server/api.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ export class Request implements APIRequest {
5252
return this.#req.method
5353
}
5454

55+
get hostname(): string {
56+
return (this.#req.conn.remoteAddr as Deno.NetAddr).hostname;
57+
}
58+
5559
get headers(): Headers {
5660
return this.#req.headers
5761
}

types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ export interface APIRequest extends ServerRequest {
161161
readonly params: Record<string, string>
162162
readonly query: URLSearchParams
163163
readonly cookies: ReadonlyMap<string, string>
164+
readonly hostname: string
164165
/** `readBody` reads the body to an object in bytes, string, json, or multipart form data. */
165166
readBody(type?: 'raw'): Promise<Uint8Array>
166167
readBody(type: 'text'): Promise<string>

0 commit comments

Comments
 (0)