Skip to content

feat(server): Return the Host or X-Forwarded-Host header field to a hostname. #267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions server/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export class Request implements APIRequest {
return this.#req.method
}

get hostname(): string {
return (this.#req.conn.remoteAddr as Deno.NetAddr).hostname;
}

get headers(): Headers {
return this.#req.headers
}
Expand Down
1 change: 1 addition & 0 deletions types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ export interface APIRequest extends ServerRequest {
readonly params: Record<string, string>
readonly query: URLSearchParams
readonly cookies: ReadonlyMap<string, string>
readonly hostname: string
/** `readBody` reads the body to an object in bytes, string, json, or multipart form data. */
readBody(type?: 'raw'): Promise<Uint8Array>
readBody(type: 'text'): Promise<string>
Expand Down