///
///
///
import * as Koa from 'koa';
import { Files } from 'formidable';
import { FileBag } from './file-bag.js';
import { InputBag } from './input-bag.js';
import { CookieBag } from './cookie-bag.js';
import { IncomingMessage } from 'node:http';
import { IncomingHttpHeaders } from 'node:http2';
import { ParsedUrlQuery } from 'node:querystring';
import { Macroable } from '@supercharge/macroable';
import { QueryParameterBag } from './query-parameter-bag.js';
import { InteractsWithState } from './interacts-with-state.js';
import { CookieConfig, InteractsWithContentTypes, HttpContext, HttpMethods, HttpRequest, HttpRequestHeaders, Protocol, RequestCookieBuilderCallback } from '@supercharge/contracts';
declare module 'koa' {
interface Request extends Koa.BaseRequest {
body?: any;
rawBody?: any;
files?: Files;
}
}
declare const Request_base: import("ts-mixer/dist/types/types.js").Class;
export declare class Request extends Request_base implements HttpRequest, InteractsWithContentTypes {
/**
* Stores the internal properties.
*/
private readonly meta;
/**
* The default cookie options.
*/
private readonly cookieConfig;
/**
* Create a new response instance.
*/
constructor(ctx: HttpContext, cookieConfig: CookieConfig);
/**
* Returns the HTTP context.
*/
ctx(): HttpContext;
/**
* Returns the raw Node.js request.
*/
req(): IncomingMessage;
/**
* Returns the request method.
*/
method(): HttpMethods;
/**
* Determine whether the request is using one of the given HTTP `methods`.
*/
isMethod(methods: HttpMethods | HttpMethods[]): methods is HttpMethods;
/**
* Returns the request’s URL path.
*/
path(): string;
/**
* Returns the request’s query parameters.
*/
query(): QueryParameterBag;
/**
* Returns the plain query string, without the leading ?.
*/
queryString(): string;
/**
* Returns the request’s path parameters.
*/
params = {}>(): InputBag;
param(name: string): string | undefined;
param(name: string, defaultValue: string): string;
/**
* Returns the cookie bag.
*/
cookies(): CookieBag;
/**
* Returns the cookie value for the given `name`. Supports an options
* builder as the second argument allowing you to change whether you
* want to retrieve the cookie `unsigned` from the incomig request.
*/
cookie(name: string, cookieBuilder?: RequestCookieBuilderCallback): string | undefined;
/**
* Determine whether a cookie exists for the given `name`.
*/
hasCookie(name: string): boolean;
/**
* Returns the full URL including protocol, host[:port], path, and query string.
*/
fullUrl(): string;
/**
* Returns the protocol value.
*/
protocol(): Protocol;
/**
* Returns the request payload.
*/
payload(): T;
/**
* Returns the merged request payload, files and query parameters. The query parameters
* take preceedence over the request payload and files. Files take preceedence over the
* request payload in case attributes with the same name are defined in both places.
*/
all(): {
[key: string]: any;
};
/**
* Returns an input item for the given `name` from the request payload or query parameters.
* Returns the `defaultValue` if a parameter for the name doesn’t exist.
*/
input(name: string, defaultValue?: T): T;
/**
* Determine whether a request body exists.
*/
hasPayload(): boolean;
/**
* Assign the given `payload` as the request body.
*/
setPayload(payload: any): this;
/**
* Returns the raw request payload
*/
rawPayload(): any;
/**
* Store the given raw `payload` for this request.
*/
setRawPayload(payload: any): this;
/**
* Returns all files on the request.
*/
files(): FileBag;
/**
* Assign the given `files` to the request.
*/
setFiles(files: Files): this;
/**
* Returns the request header bag.
*/
headers(): InputBag;
/**
* Returns the request header identified by the given `key`. The default
* value will be returned if no header is present for the given key.
*/
header(key: Header): HttpRequestHeaders[Header];
header(key: Header, defaultValue: T): HttpRequestHeaders[Header] | T;
/**
* Determine whether the request contains a header with the given `key`.
*/
hasHeader(key: Header): boolean;
/**
* Returns the request’s content size as a number retrieved from the `Content-Length` header field.
*
* @example
* ```
* request.contentLength()
* ```
*/
contentLength(): number;
/**
* Determine whether the request method is cacheable.
* Cacheable methods are `HEAD` and `GET`.
*
* @see https://tools.ietf.org/html/rfc7231#section-4.2.3
*/
isMethodCacheable(): boolean;
/**
* Determine whether the request method is not cacheable.
* Not cacheable methods are `POST`, `PUT`, `DELETE`, `PATCH`, and `OPTIONS`.
*
* @see https://tools.ietf.org/html/rfc7231#section-4.2.3
*/
isMethodNotCacheable(): boolean;
/**
* Returns the client’s user agent.
*/
userAgent(): IncomingHttpHeaders['user-agent'];
/**
* Determine whether the request contains any of the given content `types`.
* This method compares the "Content-Type" header value with all of the
* given `types` determining whether one of the content types matches.
*
* @example
* ```
* // Request with Content-Type: text/html; charset=utf-8
* request.isContentType('text/html') // true
* request.isContentType('text/html', 'application/json') // true
* request.isContentType(['text/html', 'application/json']) // true
*
* // Request with Content-Type: application/json
* request.isContentType('json') // true
* request.isContentType('application/*') // true
*
* request.isContentType('json', 'html') // true
* request.isContentType('html') // false
* ```
*/
isContentType(types: string[]): boolean;
isContentType(...types: string[]): boolean;
/**
* Determine whether the request is sending JSON payload.
*/
isJson(): boolean;
/**
* Determine whether the request is asking for a JSON response.
*/
wantsJson(): boolean;
/**
* Determine whether the request is asking for an HTML response.
*/
wantsHtml(): boolean;
/**
* Returns the request’s content mime type from the `Content-Type` header field.
*
* @example
* ```
* request.contentType()
* ```
*/
contentType(): HttpRequestHeaders['content-type'];
/**
* Determine whether the request the request is an XMLHttpRequest.
*/
isXmlHttpRequest(): boolean;
/**
* Determine whether the request is the result of an AJAX call.
* This is an alias for {@link HttpRequest#isXmlHttpRequest}.
*/
isAjax(): boolean;
/**
* Determine whether the request is the result of a PJAX call.
*/
isPjax(): boolean;
/**
* Determine whether the request is the result of a prefetch call.
*/
isPrefetch(): boolean;
}
export {};