HttpIncoming
HttpIncoming is the incoming HTTP request interface used throughout OPRA. It extends NodeIncomingMessage with Express-compatible helpers for routing metadata, content negotiation, and body reading.
import { HttpIncoming } from '@opra/http';
In operation handlers ctx.request is an HttpIncoming. See HttpContext.
Properties
| Property | Type | Description |
|---|---|---|
res | HttpOutgoing | The paired response object. |
baseUrl | string | The URL prefix at which the router is mounted. |
originalUrl | string | The full original URL before any path rewriting. |
protocol | string | 'http' or 'https'. Respects X-Forwarded-Proto when trust proxy is enabled. |
ip | string | Remote IP address. Respects trusted proxy headers. |
ips | string[] | IP addresses in the proxy chain when trust proxy is enabled. |
secure | boolean | true when protocol === 'https'. |
secret | string | undefined | Used for signed cookies. |
hostname | string | undefined | Hostname from the Host header. Respects X-Forwarded-Host when trust proxy is enabled. |
fresh | boolean | true when Last-Modified and/or ETag headers match, indicating the client cache is current. |
params | Record<string, any> | Raw path parameter values from the router. |
cookies | Record<string, any> | undefined | Raw cookies (populated when cookie-parser middleware is used). |
Methods
header(name) / get(name)
header(name: string): string | undefined
get(name: string): string | undefined
Returns the value of a named request header. Case-insensitive. 'Referrer' and 'Referer' are treated as equivalent.
const token = ctx.request.header('authorization');
const ct = ctx.request.get('content-type');
is(type)
is(type: string | string[]): string | false | null
Checks whether the Content-Type header matches the given MIME type, extension, or wildcard pattern.
ctx.request.is('json') // 'json' or false
ctx.request.is(['json', 'html'])
ctx.request.is('multipart/*')
accepts(...types)
accepts(): string[]
accepts(type: string): string | false
accepts(type: string[]): string | false
accepts(...type: string[]): string | false
Content negotiation based on the Accept header. Returns the best match from the given types, or false.
Similarly: acceptsCharsets(), acceptsEncodings(), acceptsLanguages(), characterEncoding().
range(size, options?)
range(size: number, options?: RangeParserOptions): RangeParserRanges | RangeParserResult | undefined
Parses the Range header for range requests. Returns ranges capped to size, or undefined if the header is absent.
readBody(options?)
readBody(options?: BodyReader.Options): Promise<string | Buffer | undefined>
Reads the raw request body. Used internally by HttpContext.getBody(). Prefer ctx.getBody() in operation handlers.
Namespace
HttpIncoming.from(instance)
HttpIncoming.from(
instance: HttpIncoming | NodeIncomingMessage.Initiator | string | Iterable<any> | AsyncIterable<any>
): HttpIncoming
Factory that creates or upgrades an object into a full HttpIncoming instance. If instance is already an HttpIncoming it is returned as-is. Used by adapters and tests.