HttpContext
Class: HttpContext
The HttpContext
It has similar properties than URL
See
https://developer.mozilla.org/en-US/docs/Web/API/URL_API
Constructors
new HttpContext(hostname, method, uri, protocol, port, headers)
new HttpContext(
hostname,method,uri,protocol,port,headers):HttpContext
Parameters
• hostname: string
• method: HttpMethodType
• uri: string
• protocol: "http" | "https"= "http"
• port: string | number= "80"
• headers: Object= {}
Returns
Source
packages/core/src/utils/httpcontext.ts:59
Properties
body
body:
Buffer|Readable
Source
packages/core/src/utils/httpcontext.ts:51
clientIp
clientIp:
string
Get the client ip if available
Source
packages/core/src/utils/httpcontext.ts:43
cookies
cookies:
any
Source
packages/core/src/utils/httpcontext.ts:52
headers
headers:
HeadersRequest
Source
packages/core/src/utils/httpcontext.ts:48
host
host:
string
Source
packages/core/src/utils/httpcontext.ts:50
hostname
hostname:
string
Hostname
Example
test.webda.io
Source
packages/core/src/utils/httpcontext.ts:31
method
method:
HttpMethodType
HTTP Method
Source
packages/core/src/utils/httpcontext.ts:35
origin
origin:
string
Source
packages/core/src/utils/httpcontext.ts:49
path
path:
string
Source
packages/core/src/utils/httpcontext.ts:44
port
port:
string
Source
packages/core/src/utils/httpcontext.ts:47
prefix
prefix:
string=""
URI prefix in case it is exposed through something that prefix the uri
Source
packages/core/src/utils/httpcontext.ts:57
protocol
protocol:
"http:"|"https:"
Source
packages/core/src/utils/httpcontext.ts:46
search
search:
string
Source
packages/core/src/utils/httpcontext.ts:45
uri
uri:
string
Pathname
Source
packages/core/src/utils/httpcontext.ts:39
Methods
getAbsoluteUrl()
getAbsoluteUrl(
uri):string
Parameters
• uri: string= undefined
to return absolute url from
Returns
string
Source
packages/core/src/utils/httpcontext.ts:362
getClientIp()
getClientIp():
string
Get the client ip
Returns
string
Source
packages/core/src/utils/httpcontext.ts:112
getCookies()
getCookies():
any
Get cookies
Returns
any
Source
packages/core/src/utils/httpcontext.ts:155
getHeader()
getHeader(
name,def?):string|string[]
Get header value
Parameters
• name: string
• def?: string
Returns
string | string[]
Source
packages/core/src/utils/httpcontext.ts:307
getHeaders()
getHeaders():
Readonly<IncomingHttpHeaders>
Get HTTP Headers
Returns
Readonly<IncomingHttpHeaders>
Source
packages/core/src/utils/httpcontext.ts:297
getHost()
getHost():
string
Return hostname and port
Returns
string
Source
packages/core/src/utils/httpcontext.ts:186
getHostName()
getHostName():
string
Get the hostname
Returns
string
Source
packages/core/src/utils/httpcontext.ts:202
getHref()
getHref():
string
Returns
string
See
https://developer.mozilla.org/en-US/docs/Web/API/URL/href
Source
packages/core/src/utils/httpcontext.ts:121
getMethod()
getMethod():
HttpMethodType
Get HTTP Method used
Returns
Source
packages/core/src/utils/httpcontext.ts:210
getOrigin()
getOrigin():
string
Return protocol, hostname and port
Returns
string
Source
packages/core/src/utils/httpcontext.ts:194
getPathName()
getPathName():
string
Get request path name
Returns
string
See
https://developer.mozilla.org/en-US/docs/Web/API/URL/pathname
Source
packages/core/src/utils/httpcontext.ts:344
getPort()
getPort():
string
Get port number as string
If http on port 80, or https on port 443 will return ""
Returns
string
Source
packages/core/src/utils/httpcontext.ts:164
getPortNumber()
getPortNumber():
number
Get the port number
Returns
number
Source
packages/core/src/utils/httpcontext.ts:171
getProtocol()
getProtocol():
"http:"|"https:"
Get protocol used
Returns
"http:" | "https:"
Source
packages/core/src/utils/httpcontext.ts:218
getRawBody()
getRawBody(
limit,timeout):Promise<Buffer>
Get request body
Parameters
• limit: number= undefined
the size of readable request
• timeout: number= 60000
the time to read the request
Returns
Promise<Buffer>
Source
packages/core/src/utils/httpcontext.ts:253
getRawBodyAsString()
getRawBodyAsString(
limit,timeout,encoding?):Promise<string>
Get the raw body as string
Parameters
• limit: number= undefined
the size of readable request
• timeout: number= 60000
the time to read the request
• encoding?: string
to analyze
Returns
Promise<string>
Source
packages/core/src/utils/httpcontext.ts:230
getRawStream()
getRawStream():
Readable
Get the body as stream
Returns
Readable
Source
packages/core/src/utils/httpcontext.ts:286
getRelativeUri()
getRelativeUri():
string
Return Uri without prefix
Returns
string
Source
packages/core/src/utils/httpcontext.ts:139
getSearch()
getSearch():
string
Get search section
Returns
string
See
https://developer.mozilla.org/en-US/docs/Web/API/URL/search
Source
packages/core/src/utils/httpcontext.ts:354
getUniqueHeader()
getUniqueHeader(
name,def?):string
Return the last header found with that name
Parameters
• name: string
• def?: string
Returns
string
Source
packages/core/src/utils/httpcontext.ts:314
getUrl()
getUrl():
string
Get full URI
Returns
string
Source
packages/core/src/utils/httpcontext.ts:147
setBody()
setBody(
body):this
Used for test
Parameters
• body: any
Returns
this
Source
packages/core/src/utils/httpcontext.ts:326
setClientIp()
setClientIp(
ip):this
Set the client ip
Parameters
• ip: string
Returns
this
Source
packages/core/src/utils/httpcontext.ts:104
setPrefix()
setPrefix(
prefix):void
Parameters
• prefix: string
uri to not consider
Returns
void