forked from oakserver/oak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.d.ts
94 lines (86 loc) · 2.56 KB
/
types.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright 2018-2020 the oak authors. All rights reserved. MIT license.
import { BufReader, BufWriter, Status } from "./deps.ts";
/** A HTTP status that is an error (4XX and 5XX). */
export type ErrorStatus =
| Status.BadRequest
| Status.Unauthorized
| Status.PaymentRequired
| Status.Forbidden
| Status.NotFound
| Status.MethodNotAllowed
| Status.NotAcceptable
| Status.ProxyAuthRequired
| Status.RequestTimeout
| Status.Conflict
| Status.Gone
| Status.LengthRequired
| Status.PreconditionFailed
| Status.RequestEntityTooLarge
| Status.RequestURITooLong
| Status.UnsupportedMediaType
| Status.RequestedRangeNotSatisfiable
| Status.ExpectationFailed
| Status.Teapot
| Status.MisdirectedRequest
| Status.UnprocessableEntity
| Status.Locked
| Status.FailedDependency
| Status.UpgradeRequired
| Status.PreconditionRequired
| Status.TooManyRequests
| Status.RequestHeaderFieldsTooLarge
| Status.UnavailableForLegalReasons
| Status.InternalServerError
| Status.NotImplemented
| Status.BadGateway
| Status.ServiceUnavailable
| Status.GatewayTimeout
| Status.HTTPVersionNotSupported
| Status.VariantAlsoNegotiates
| Status.InsufficientStorage
| Status.LoopDetected
| Status.NotExtended
| Status.NetworkAuthenticationRequired;
/** A HTTP status that is a redirect (3XX). */
export type RedirectStatus =
| Status.MultipleChoices // 300
| Status.MovedPermanently // 301
| Status.Found // 302
| Status.SeeOther // 303
| Status.UseProxy // 305 - DEPRECATED
| Status.TemporaryRedirect // 307
| Status.PermanentRedirect; // 308
export type HTTPMethods =
| "HEAD"
| "OPTIONS"
| "GET"
| "PUT"
| "PATCH"
| "POST"
| "DELETE";
type HTTPOptions = Omit<Deno.ListenOptions, "transport">;
type HTTPSOptions = Omit<Deno.ListenTlsOptions, "transport">;
export type Serve = (options: string | HTTPOptions) => Server;
export type ServeTls = (options: HTTPSOptions) => Server;
export interface Server extends AsyncIterable<ServerRequest> {
close(): void;
}
/** An interface that aligns to the parts of `std/http/server`'s
* `ServerRequest` that actually is consumed by oak. */
export interface ServerRequest {
body: Deno.Reader;
conn: Deno.Conn;
headers: Headers;
method: string;
r: BufReader;
respond(response: ServerResponse): Promise<void>;
url: string;
w: BufWriter;
}
/** An interface that aligns to what oak returns and is compatible with
* `std/http/server`'s `request.respond()`. */
export interface ServerResponse {
status: number;
headers: Headers;
body: Uint8Array | Deno.Reader | undefined;
}