Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • Request
    • Request

Implements

  • ReadableStream

Index

Constructors

constructor

  • new Request(socket: Socket): Request
  • Parameters

    • socket: Socket

    Returns Request

Properties

accepted

accepted: MediaType[]

Return an array of Accepted media types ordered from highest quality to lowest.

app

app: Application

baseUrl

baseUrl: string

body

body: any

connection

connection: Socket

cookies

cookies: any

fresh

fresh: boolean

Check if the request is fresh, aka Last-Modified and/or the ETag still match.

headers

headers: IncomingHttpHeaders

host

host: string
deprecated

Use hostname instead.

hostname

hostname: string

Parse the "Host" header field hostname.

httpVersion

httpVersion: string

httpVersionMajor

httpVersionMajor: number

httpVersionMinor

httpVersionMinor: number

Optional id

id: string | number | string[]

ip

ip: string

Return the remote address, or when "trust proxy" is true return the upstream addr.

ips

ips: string[]

When "trust proxy" is true, parse the "X-Forwarded-For" ip address list.

For example if the value were "client, proxy1, proxy2" you would receive the array ["client", "proxy1", "proxy2"] where "proxy2" is the furthest down-stream.

Optional log

log: Logger

method

method: string

Optional next

originalUrl

originalUrl: string

params

params: any

path

path: string

Short-hand for url.parse(req.url).pathname.

protocol

protocol: string

Return the protocol string "http" or "https" when requested with TLS. When the "trust proxy" setting is enabled the "X-Forwarded-Proto" header field will be trusted. If you're running behind a reverse proxy that supplies https for you this may be enabled.

query

query: any

rawHeaders

rawHeaders: string[]

rawTrailers

rawTrailers: string[]

readable

readable: boolean

readableHighWaterMark

readableHighWaterMark: number

readableLength

readableLength: number

Optional res

After middleware.init executed, Request will contain res and next properties See: express/lib/middleware/init.js

route

route: any

secure

secure: boolean

Short-hand for:

req.protocol == 'https'

signedCookies

signedCookies: any

socket

socket: Socket

stale

stale: boolean

Check if the request is stale, aka "Last-Modified" and / or the "ETag" for the resource has changed.

Optional statusCode

statusCode: undefined | number

Only valid for response obtained from http.ClientRequest.

Optional statusMessage

statusMessage: undefined | string

Only valid for response obtained from http.ClientRequest.

subdomains

subdomains: string[]

Return subdomains as an array.

Subdomains are the dot-separated parts of the host before the main domain of the app. By default, the domain of the app is assumed to be the last two parts of the host. This can be changed by setting "subdomain offset".

For example, if the domain is "tobi.ferrets.example.com": If "subdomain offset" is not set, req.subdomains is ["ferrets", "tobi"]. If "subdomain offset" is 3, req.subdomains is ["tobi"].

trailers

trailers: object

Type declaration

  • [key: string]: string | undefined

url

url: string

xhr

xhr: boolean

Check if the request was an XMLHttpRequest.

Static defaultMaxListeners

defaultMaxListeners: number

Methods

__@asyncIterator

  • __@asyncIterator(): AsyncIterableIterator<Buffer | string>
  • Returns AsyncIterableIterator<Buffer | string>

_destroy

  • _destroy(err: Error, callback: Function): void
  • Parameters

    • err: Error
    • callback: Function

    Returns void

_read

  • _read(size: number): void
  • Parameters

    • size: number

    Returns void

accepts

  • accepts(): string[]
  • accepts(type: string): string | false
  • accepts(type: string[]): string | false
  • accepts(...type: string[]): string | false
  • Check if the given type(s) is acceptable, returning the best match when true, otherwise undefined, in which case you should respond with 406 "Not Acceptable".

    The type value may be a single mime type string such as "application/json", the extension name such as "json", a comma-delimted list such as "json, html, text/plain", or an array ["json", "html", "text/plain"]. When a list or array is given the best match, if any is returned.

    Examples:

    // Accept: text/html
    req.accepts('html');
    // => "html"
    
    // Accept: text/*, application/json
    req.accepts('html');
    // => "html"
    req.accepts('text/html');
    // => "text/html"
    req.accepts('json, text');
    // => "json"
    req.accepts('application/json');
    // => "application/json"
    
    // Accept: text/*, application/json
    req.accepts('image/png');
    req.accepts('png');
    // => undefined
    
    // Accept: text/*;q=.5, application/json
    req.accepts(['html', 'json']);
    req.accepts('html, json');
    // => "json"
    

    Returns string[]

  • Parameters

    • type: string

    Returns string | false

  • Parameters

    • type: string[]

    Returns string | false

  • Parameters

    • Rest ...type: string[]

    Returns string | false

acceptsCharsets

  • acceptsCharsets(): string[]
  • acceptsCharsets(charset: string): string | false
  • acceptsCharsets(charset: string[]): string | false
  • acceptsCharsets(...charset: string[]): string | false
  • Returns the first accepted charset of the specified character sets, based on the request's Accept-Charset HTTP header field. If none of the specified charsets is accepted, returns false.

    For more information, or if you have issues or concerns, see accepts.

    Returns string[]

  • Parameters

    • charset: string

    Returns string | false

  • Parameters

    • charset: string[]

    Returns string | false

  • Parameters

    • Rest ...charset: string[]

    Returns string | false

acceptsEncodings

  • acceptsEncodings(): string[]
  • acceptsEncodings(encoding: string): string | false
  • acceptsEncodings(encoding: string[]): string | false
  • acceptsEncodings(...encoding: string[]): string | false
  • Returns the first accepted encoding of the specified encodings, based on the request's Accept-Encoding HTTP header field. If none of the specified encodings is accepted, returns false.

    For more information, or if you have issues or concerns, see accepts.

    Returns string[]

  • Parameters

    • encoding: string

    Returns string | false

  • Parameters

    • encoding: string[]

    Returns string | false

  • Parameters

    • Rest ...encoding: string[]

    Returns string | false

acceptsLanguages

  • acceptsLanguages(): string[]
  • acceptsLanguages(lang: string): string | false
  • acceptsLanguages(lang: string[]): string | false
  • acceptsLanguages(...lang: string[]): string | false
  • Returns the first accepted language of the specified languages, based on the request's Accept-Language HTTP header field. If none of the specified languages is accepted, returns false.

    For more information, or if you have issues or concerns, see accepts.

    Returns string[]

  • Parameters

    • lang: string

    Returns string | false

  • Parameters

    • lang: string[]

    Returns string | false

  • Parameters

    • Rest ...lang: string[]

    Returns string | false

addListener

  • addListener(event: string, listener: function): this
  • addListener(event: "close", listener: function): this
  • addListener(event: "data", listener: function): this
  • addListener(event: "end", listener: function): this
  • addListener(event: "readable", listener: function): this
  • addListener(event: "error", listener: function): this
  • Event emitter The defined events on documents including:

    1. close
    2. data
    3. end
    4. readable
    5. error

    Parameters

    • event: string
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

  • Parameters

    • event: "close"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "data"
    • listener: function
        • (chunk: Buffer | string): void
        • Parameters

          • chunk: Buffer | string

          Returns void

    Returns this

  • Parameters

    • event: "end"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "readable"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "error"
    • listener: function
        • (err: Error): void
        • Parameters

          • err: Error

          Returns void

    Returns this

clearCookie

  • clearCookie(name: string, options?: any): Response
  • Clear cookie name.

    Parameters

    • name: string
    • Optional options: any

    Returns Response

destroy

  • destroy(error?: Error): void
  • Parameters

    Returns void

emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • emit(event: "close"): boolean
  • emit(event: "data", chunk: Buffer | string): boolean
  • emit(event: "end"): boolean
  • emit(event: "readable"): boolean
  • emit(event: "error", err: Error): boolean
  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

  • Parameters

    • event: "close"

    Returns boolean

  • Parameters

    • event: "data"
    • chunk: Buffer | string

    Returns boolean

  • Parameters

    • event: "end"

    Returns boolean

  • Parameters

    • event: "readable"

    Returns boolean

  • Parameters

    • event: "error"
    • err: Error

    Returns boolean

eventNames

  • eventNames(): Array<string | symbol>
  • Returns Array<string | symbol>

get

  • get(name: "set-cookie"): string[] | undefined
  • get(name: string): string | undefined
  • Return request header.

    The Referrer header field is special-cased, both Referrer and Referer are interchangeable.

    Examples:

    req.get('Content-Type');
    // => "text/plain"
    
    req.get('content-type');
    // => "text/plain"
    
    req.get('Something');
    // => undefined
    

    Aliased as req.header().

    Parameters

    • name: "set-cookie"

    Returns string[] | undefined

  • Parameters

    • name: string

    Returns string | undefined

getMaxListeners

  • getMaxListeners(): number
  • Returns number

header

  • header(name: "set-cookie"): string[] | undefined
  • header(name: string): string | undefined
  • Parameters

    • name: "set-cookie"

    Returns string[] | undefined

  • Parameters

    • name: string

    Returns string | undefined

is

  • is(type: string): string | false
  • Check if the incoming request contains the "Content-Type" header field, and it contains the give mime type.

    Examples:

     // With Content-Type: text/html; charset=utf-8
     req.is('html');
     req.is('text/html');
     req.is('text/*');
     // => true
    
     // When Content-Type is application/json
     req.is('json');
     req.is('application/json');
     req.is('application/*');
     // => true
    
     req.is('html');
     // => false
    

    Parameters

    • type: string

    Returns string | false

isPaused

  • isPaused(): boolean
  • Returns boolean

listenerCount

  • listenerCount(type: string | symbol): number
  • Parameters

    • type: string | symbol

    Returns number

listeners

  • listeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

off

  • off(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

on

  • on(event: string, listener: function): this
  • on(event: "close", listener: function): this
  • on(event: "data", listener: function): this
  • on(event: "end", listener: function): this
  • on(event: "readable", listener: function): this
  • on(event: "error", listener: function): this
  • Parameters

    • event: string
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

  • Parameters

    • event: "close"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "data"
    • listener: function
        • (chunk: Buffer | string): void
        • Parameters

          • chunk: Buffer | string

          Returns void

    Returns this

  • Parameters

    • event: "end"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "readable"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "error"
    • listener: function
        • (err: Error): void
        • Parameters

          • err: Error

          Returns void

    Returns this

once

  • once(event: string, listener: function): this
  • once(event: "close", listener: function): this
  • once(event: "data", listener: function): this
  • once(event: "end", listener: function): this
  • once(event: "readable", listener: function): this
  • once(event: "error", listener: function): this
  • Parameters

    • event: string
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

  • Parameters

    • event: "close"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "data"
    • listener: function
        • (chunk: Buffer | string): void
        • Parameters

          • chunk: Buffer | string

          Returns void

    Returns this

  • Parameters

    • event: "end"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "readable"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "error"
    • listener: function
        • (err: Error): void
        • Parameters

          • err: Error

          Returns void

    Returns this

param

  • param(name: string, defaultValue?: any): string
  • deprecated

    since 4.11 Use either req.params, req.body or req.query, as applicable.

    Return the value of param name when present or defaultValue.

    • Checks route placeholders, ex: /user/:id
    • Checks body params, ex: id=12, {"id":12}
    • Checks query string params, ex: ?id=12

    To utilize request bodies, req.body should be an object. This can be done by using the connect.bodyParser() middleware.

    Parameters

    • name: string
    • Optional defaultValue: any

    Returns string

pause

  • pause(): this
  • Returns this

pipe

  • pipe<T>(destination: T, options?: undefined | object): T
  • Type parameters

    • T: WritableStream

    Parameters

    • destination: T
    • Optional options: undefined | object

    Returns T

prependListener

  • prependListener(event: string, listener: function): this
  • prependListener(event: "close", listener: function): this
  • prependListener(event: "data", listener: function): this
  • prependListener(event: "end", listener: function): this
  • prependListener(event: "readable", listener: function): this
  • prependListener(event: "error", listener: function): this
  • Parameters

    • event: string
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

  • Parameters

    • event: "close"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "data"
    • listener: function
        • (chunk: Buffer | string): void
        • Parameters

          • chunk: Buffer | string

          Returns void

    Returns this

  • Parameters

    • event: "end"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "readable"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "error"
    • listener: function
        • (err: Error): void
        • Parameters

          • err: Error

          Returns void

    Returns this

prependOnceListener

  • prependOnceListener(event: string, listener: function): this
  • prependOnceListener(event: "close", listener: function): this
  • prependOnceListener(event: "data", listener: function): this
  • prependOnceListener(event: "end", listener: function): this
  • prependOnceListener(event: "readable", listener: function): this
  • prependOnceListener(event: "error", listener: function): this
  • Parameters

    • event: string
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

  • Parameters

    • event: "close"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "data"
    • listener: function
        • (chunk: Buffer | string): void
        • Parameters

          • chunk: Buffer | string

          Returns void

    Returns this

  • Parameters

    • event: "end"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "readable"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "error"
    • listener: function
        • (err: Error): void
        • Parameters

          • err: Error

          Returns void

    Returns this

push

  • push(chunk: any, encoding?: undefined | string): boolean
  • Parameters

    • chunk: any
    • Optional encoding: undefined | string

    Returns boolean

range

  • range(size: number, options?: RangeParserOptions): RangeParserRanges | RangeParserResult | undefined
  • Parse Range header field, capping to the given size.

    Unspecified ranges such as "0-" require knowledge of your resource length. In the case of a byte range this is of course the total number of bytes. If the Range header field is not given undefined is returned. If the Range header field is given, return value is a result of range-parser. See more ./types/range-parser/index.d.ts

    NOTE: remember that ranges are inclusive, so for example "Range: users=0-3" should respond with 4 users when available, not 3.

    Parameters

    • size: number
    • Optional options: RangeParserOptions

    Returns RangeParserRanges | RangeParserResult | undefined

rawListeners

  • rawListeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

read

  • read(size?: undefined | number): any
  • Parameters

    • Optional size: undefined | number

    Returns any

removeAllListeners

  • removeAllListeners(event?: string | symbol): this
  • Parameters

    • Optional event: string | symbol

    Returns this

removeListener

  • removeListener(event: string, listener: function): this
  • removeListener(event: "close", listener: function): this
  • removeListener(event: "data", listener: function): this
  • removeListener(event: "end", listener: function): this
  • removeListener(event: "readable", listener: function): this
  • removeListener(event: "error", listener: function): this
  • Parameters

    • event: string
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

  • Parameters

    • event: "close"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "data"
    • listener: function
        • (chunk: Buffer | string): void
        • Parameters

          • chunk: Buffer | string

          Returns void

    Returns this

  • Parameters

    • event: "end"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "readable"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "error"
    • listener: function
        • (err: Error): void
        • Parameters

          • err: Error

          Returns void

    Returns this

resume

  • resume(): this
  • Returns this

setEncoding

  • setEncoding(encoding: string): this
  • Parameters

    • encoding: string

    Returns this

setMaxListeners

  • setMaxListeners(n: number): this
  • Parameters

    • n: number

    Returns this

setTimeout

  • setTimeout(msecs: number, callback: function): this
  • Parameters

    • msecs: number
    • callback: function
        • (): void
        • Returns void

    Returns this

unpipe

  • unpipe<T>(destination?: T): this
  • Type parameters

    • T: WritableStream

    Parameters

    • Optional destination: T

    Returns this

unshift

  • unshift(chunk: any): void
  • Parameters

    • chunk: any

    Returns void

wrap

  • wrap(oldStream: ReadableStream): this
  • Parameters

    • oldStream: ReadableStream

    Returns this

Static listenerCount

  • listenerCount(emitter: EventEmitter, event: string | symbol): number
  • deprecated

    since v4.0.0

    Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc