forked from adonisjs/http-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.ts
83 lines (74 loc) · 2.33 KB
/
context.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
/**
* @adonisjs/http-server
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare module '@ioc:Adonis/Core/HttpContext' {
import { RouteNode } from '@ioc:Adonis/Core/Route'
import { IncomingMessage, ServerResponse } from 'http'
import { MacroableConstructorContract } from 'macroable'
import { LoggerContract } from '@ioc:Adonis/Core/Logger'
import { RequestContract } from '@ioc:Adonis/Core/Request'
import { ResponseContract } from '@ioc:Adonis/Core/Response'
import { ProfilerRowContract } from '@ioc:Adonis/Core/Profiler'
import { ApplicationContract } from '@ioc:Adonis/Core/Application'
/**
* Http request context passed to all middleware
* and route handler
*/
export interface HttpContextContract {
/**
* A helper to see top level properties on the context object
*/
inspect(): any
request: RequestContract
response: ResponseContract
logger: LoggerContract
profiler: ProfilerRowContract
route?: RouteNode
routeKey: string
params: Record<string, any>
subdomains: Record<string, any>
}
/**
* Shape of the constructor. We export the constructor and not
* the context instance, since that is passed to the HTTP
* lifecycle
*/
export interface HttpContextConstructorContract
extends MacroableConstructorContract<HttpContextContract> {
app?: ApplicationContract
/**
* Whether async hooks are enabled and the async HTTP context can be used.
*/
readonly asyncHttpContextEnabled: boolean
/**
* Returns the current HTTP context or null if there is none.
*/
get(): HttpContextContract | null
/**
* Returns the current HTTP context or throws if there is none.
*/
getOrFail(): HttpContextContract
/**
* Creates a new fake context instance for a given route.
*/
create(
routePattern: string,
routeParams: Record<string, any>,
req?: IncomingMessage,
res?: ServerResponse
): HttpContextContract
new (
request: RequestContract,
response: ResponseContract,
logger: LoggerContract,
profiler: ProfilerRowContract
): HttpContextContract
}
const HttpContext: HttpContextConstructorContract
export default HttpContext
}