{"owner":"hapijs","repo":"hapi","hasSkills":true,"totalSkillsCount":1,"totalTokensCount":11326,"categories":["project-spec"],"hasMcp":false,"mcpConfig":null,"found":["API.md"],"skills":{"API.md":"\n## Server\n\nThe server object is the main application container. The server manages all incoming requests\nalong with all the facilities provided by the framework. Each server supports a single connection\n(e.g. listen to port `80`).\n\n### <a name=\"server()\" /> `server([options])`\n\nCreates a new server object where:\n- `options` - (optional) a [server configuration object](#server.options).\n\n```js\nconst Hapi = require('@hapi/hapi');\n\nconst server = Hapi.server({ load: { sampleInterval: 1000 } });\n```\n\n### <a name=\"server.options\" /> Server options\n\nThe server options control the behavior of the server object. Note that the options object is\ndeeply cloned (with the exception of [`listener`](#server.options.listener) which is shallowly\ncopied) and should not contain any values that are unsafe to perform deep copy on.\n\nAll options are optionals.\n\n#### <a name=\"server.options.address\" /> `server.options.address`\n\nDefault value: `'::'` if IPv6 is available, otherwise `'0.0.0.0'` (i.e. all available network interfaces).\n\nSets the hostname or IP address the server will listen on. If not configured, defaults to\n[`host`](#server.options.host) if present, otherwise to all available network interfaces. Set to\n`'127.0.0.1'`, `'::1'`, or `'localhost'` to restrict the server to only those coming from the same host.\n\n#### <a name=\"server.options.app\" /> `server.options.app`\n\nDefault value: `{}`.\n\nProvides application-specific configuration which can later be accessed via\n[`server.settings.app`](#server.settings). The framework does not interact with this object. It is\nsimply a reference made available anywhere a `server` reference is provided.\n\nNote the difference between `server.settings.app` which is used to store static configuration\nvalues and [`server.app`](#server.app) which is meant for storing run-time state.\n\n#### <a name=\"server.options.autolisten\" /> `server.options.autoListen`\n\nDefault value: `true`.\n\nUsed to disable the automatic initialization of the [`listener`](#server.options.listener). When\n`false`, indicates that the [`listener`](#server.options.listener) will be started manually outside\nthe framework.\n\nCannot be set to `false` along with a [`port`](#server.options.port) value.\n\n#### <a name=\"server.options.cache\" /> `server.options.cache`\n\nDefault value: `{ provider: { constructor: require('@hapi/catbox-memory'), options: { partition: 'hapi-cache' } } }`.\n\nSets up server-side caching providers. Every server includes a default cache for storing\napplication state. By default, a simple memory-based cache is created which has limited capacity\nand capabilities.\n\n**hapi** uses [**catbox**](https://hapi.dev/family/catbox/api) for its cache implementation which\nincludes support for common storage solutions (e.g. Redis, MongoDB, Memcached, Riak, among others).\nCaching is only utilized if [methods](#server.methods) and [plugins](#plugins) explicitly store\ntheir state in the cache.\n\nThe server cache configuration only defines the storage container itself. The configuration can be\nassigned one or more (array):\n\n- a class or prototype function (usually obtained by calling `require()` on a **catbox** strategy\n    such as `require('@hapi/catbox-redis')`). A new **catbox** [client](https://hapi.dev/family/catbox/api#client)\n    will be created internally using this constructor.\n\n- a configuration object with the following:\n\n    - `engine` - a **catbox** engine object instance.\n\n    - `name` - an identifier used later when provisioning or configuring caching for\n        [server methods](#server.methods) or [plugins](#plugins). Each cache name must be unique.\n        A single item may omit the `name` option which defines the default cache. If every cache\n        includes a `name`, a default memory cache is provisioned as well.\n\n    - `provider` - a class, a constructor function, or an object with the following:\n\n        - `constructor` - a class or a prototype function.\n\n        - `options` - (optional) a settings object passed as-is to the `constructor` with the following:\n\n            - `partition` - (optional) string used to isolate cached data. Defaults to `'hapi-cache'`.\n            - other constructor-specific options passed to the `constructor` on instantiation.\n\n    - `shared` - if `true`, allows multiple cache users to share the same segment (e.g.\n        multiple methods using the same cache storage container). Default to `false`.\n\n    - One (and only one) of `engine` or `provider` is required per configuration object.\n\n#### <a name=\"server.options.compression\" /> `server.options.compression`\n\nDefault value: `{ minBytes: 1024 }`.\n\nDefines server handling of content encoding requests. If `false`, response content encoding is\ndisabled and no compression is performed by the server.\n\n##### <a name=\"server.options.compression.minBytes\" /> `server.options.compression.minBytes`\n\nDefault value: '1024'.\n\nSets the minimum response payload size in bytes that is required for content encoding compression.\nIf the payload size is under the limit, no compression is performed.\n\n#### <a name=\"server.options.debug\" /> `server.options.debug`\n\nDefault value: `{ request: ['implementation'] }`.\n\nDetermines which logged events are sent to the console. This should only be used for development\nand does not affect which events are actually logged internally and recorded. Set to `false` to\ndisable all console logging, or to an object with:\n\n- `log` - a string array of server log tags to be displayed via `console.error()` when\n    the events are logged via [`server.log()`](#server.log()) as well as\n    internally generated [server logs](#server-logs). Defaults to no output.\n\n- `request` - a string array of request log tags to be displayed via `console.error()` when\n    the events are logged via [`request.log()`](#request.log()) as well as\n    internally generated [request logs](#request-logs). For example, to display all errors,\n    set the option to `['error']`. To turn off all console debug messages set it to `false`.\n    To display all request logs, set it to `'*'`.\n    Defaults to uncaught errors thrown in external code (these errors are handled\n    automatically and result in an Internal Server Error response) or runtime errors due to\n    developer error.\n\nFor example, to display all errors, set the `log` or `request` to `['error']`. To turn off all\noutput set the `log` or `request` to `false`. To display all server logs, set the `log` or\n`request` to `'*'`. To disable all debug information, set `debug` to `false`.\n\n#### <a name=\"server.options.host\" /> `server.options.host`\n\nDefault value: the operating system hostname and if not available, to `'localhost'`.\n\nThe public hostname or IP address. Used to set [`server.info.host`](#server.info) and\n[`server.info.uri`](#server.info) and as [`address`](#server.options.address) if none is provided.\n\n#### <a name=\"server.options.info.remote\" /> `server.options.info.remote`\n\nDefault value: `false`.\n\nIf `true`, the `request.info.remoteAddress` and `request.info.remotePort` are populated when the request is received which can consume more resource (but is ok if the information is needed, especially for aborted requests). When `false`, the fields are only populated upon demand (but will be `undefined` if accessed after the request is aborted).\n\n#### <a name=\"server.options.listener\" /> `server.options.listener`\n\nDefault value: none.\n\nAn optional node HTTP (or HTTPS) [`http.Server`](https://nodejs.org/api/http.html#http_class_http_server)\nobject (or an object with a compatible interface).\n\nIf the `listener` needs to be manually started, set [`autoListen`](#server.options.autolisten) to\n`false`.\n\nIf the `listener` uses TLS, set [`tls`](#server.options.tls) to `true`.\n\n#### <a name=\"server.options.load\" /> `server.options.load`\n\nDefault value: `{ sampleInterval: 0, maxHeapUsedBytes: 0, maxRssBytes: 0, maxEventLoopDelay: 0, maxEventLoopUtilization: 0 }`.\n\nServer excessive load handling limits where:\n\n- `sampleInterval` - the frequency of sampling in milliseconds. When set to `0`, the other load options are ignored. Defaults to `0` (no sampling).\n\n- `maxHeapUsedBytes` - maximum V8 heap size over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to `0` (no limit).\n\n- `maxRssBytes` - maximum process RSS size over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to `0` (no limit).\n\n- `maxEventLoopDelay` - maximum event loop delay duration in milliseconds over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to `0` (no limit).\n\n- `maxEventLoopUtilization` - maximum event loop utilization value over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to `0` (no limit).\n\n#### <a name=\"server.options.mime\" /> `server.options.mime`\n\nDefault value: none.\n\nOptions passed to the [**mimos**](https://hapi.dev/family/mimos/api) module when generating the mime database used by the server (and accessed via [`server.mime`](#server.mime)):\n\n- `override` - an object hash that is merged into the built in mime information specified [here](https://github.com/jshttp/mime-db). Each key value pair represents a single mime object. Each override value must contain:\n\n    - `key` - the lower-cased mime-type string (e.g. `'application/javascript'`).\n\n    - `value` - an object following the specifications outlined [here](https://github.com/jshttp/mime-db#data-structure). Additional values include:\n\n        - `type` - specify the `type` value of result objects, defaults to `key`.\n\n        - `predicate` - method with signature `function(mime)` when this mime type is found in the database, this function will execute to allows customizations.\n\n```js\nconst options = {\n    mime: {\n        override: {\n            'node/module': {\n                source: 'iana',\n                compressible: true,\n                extensions: ['node', 'module', 'npm'],\n                type: 'node/module'\n            },\n            'application/javascript': {\n                source: 'iana',\n                charset: 'UTF-8',\n                compressible: true,\n                extensions: ['js', 'javascript'],\n                type: 'text/javascript'\n            },\n            'text/html': {\n                predicate: function(mime) {\n                    if (someCondition) {\n                        mime.foo = 'test';\n                    }\n                    else {\n                        mime.foo = 'bar';\n                    }\n                    return mime;\n                }\n            }\n        }\n    }\n};\n```\n\n#### <a name=\"server.options.operations\" /> `server.options.operations`\n\nDefault value: `{ cleanStop: true }`.\n\nDefines server handling of server operations:\n\n- `cleanStop` - if `true`, the server keeps track of open connections and properly closes them\n  when the server is stopped. Under normal load, this should not interfere with server performance.\n  However, under severe load connection monitoring can consume additional resources and aggravate\n  the situation. If the server is never stopped, or if it is forced to stop without waiting for\n  open connection to close, setting this to `false` can save resources that are not being utilized\n  anyway. Defaults to `true`.\n\n#### <a name=\"server.options.plugins\" /> `server.options.plugins`\n\nDefault value: `{}`.\n\nPlugin-specific configuration which can later be accessed via [`server.settings.plugins`](#server.settings).\n`plugins` is an object where each key is a plugin name and the value is the configuration.\nNote the difference between [`server.settings.plugins`](#server.settings) which is used to store\nstatic configuration values and [`server.plugins`](#server.plugins) which is meant for storing\nrun-time state.\n\n#### <a name=\"server.options.port\" /> `server.options.port`\n\nDefault value: `0` (an ephemeral port).\n\nThe TCP port the server will listen to. Defaults the next available port when the server is started\n(and assigned to [`server.info.port`](#server.info)).\n\nIf `port` is a string containing a '/' character, it is used as a UNIX domain socket path.\nIf it starts with '\\\\.\\pipe', it is used as a Windows named pipe.\n\n#### <a name=\"server.options.query\" /> `server.options.query`\n\nDefault value: `{}`.\n\nDefines server handling of the request path query component.\n\n##### <a name=\"server.options.query.parser\" /> `server.options.query.parser`\n\nDefault value: none.\n\nSets a query parameters parser method using the signature `function(query)` where:\n\n- `query` - an object containing the incoming [`request.query`](#request.query) parameters.\n- the method must return an object where each key is a parameter and matching value is the\n  parameter value. If the method throws, the error is used as the response or returned when\n  [`request.setUrl()`](#request.setUrl()) is called.\n\n```js\nconst Qs = require('qs');\n\nconst options = {\n    query: {\n        parser: (query) => Qs.parse(query)\n    }\n};\n```\n\n#### <a name=\"server.options.router\" /> `server.options.router`\n\nDefault value: `{ isCaseSensitive: true, stripTrailingSlash: false }`.\n\nControls how incoming request URIs are matched against the routing table:\n\n- `isCaseSensitive` - determines whether the paths '/example' and '/EXAMPLE' are considered\n  different resources. Defaults to `true`.\n\n- `stripTrailingSlash` - removes trailing slashes on incoming paths. Defaults to `false`.\n\n#### <a name=\"server.options.routes\" /> `server.options.routes`\n\nDefault value: none.\n\nA [route options](#route-options) object used as the default configuration for every route.\n\n#### <a name=\"server.options.state\" /> `server.options.state`\n\nDefault value:\n```js\n{\n    strictHeader: true,\n    ignoreErrors: false,\n    isSecure: true,\n    isHttpOnly: true,\n    isSameSite: 'Strict',\n    isPartitioned: false,\n    encoding: 'none'\n}\n```\n\nSets the default configuration for every state (cookie) set explicitly via\n[`server.state()`](#server.state()) or implicitly (without definition) using the\n[state configuration](#server.state()) object.\n\n#### <a name=\"server.options.tls\" /> `server.options.tls`\n\nDefault value: none.\n\nUsed to create an HTTPS connection. The `tls` object is passed unchanged to the node\nHTTPS server as described in the [node HTTPS documentation](https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener).\n\nSet to `true` when passing a [`listener`](#server.options.listener) object that has been configured\nto use TLS directly.\n\n#### <a name=\"server.options.uri\" /> `server.options.uri`\n\nDefault value: constructed from runtime server information.\n\nThe full public URI without the path (e.g. 'http://example.com:8080'). If present, used as the\nserver [`server.info.uri`](#server.info), otherwise constructed from the server settings.\n\n### Server properties\n\n#### <a name=\"server.app\" /> `server.app`\n\nAccess: read / write.\n\nProvides a safe place to store server-specific run-time application data without potential\nconflicts with the framework internals. The data can be accessed whenever the server is\naccessible. Initialized with an empty object.\n\n```js\nconst server = Hapi.server();\n\nserver.app.key = 'value';\n\nconst handler = function (request, h) {\n\n    return request.server.app.key;        // 'value'\n};\n```\n\n#### <a name=\"server.auth.api\" /> `server.auth.api`\n\nAccess: authentication strategy specific.\n\nAn object where each key is an authentication strategy name and the value is the exposed strategy\nAPI. Available only when the authentication scheme exposes an API by returning an `api` key in the\nobject returned from its implementation function.\n\n```js\nconst server = Hapi.server({ port: 80 });\n\nconst scheme = function (server, options) {\n\n    return {\n        api: {\n            settings: {\n                x: 5\n            }\n        },\n        authenticate: function (request, h) {\n\n            const authorization = request.headers.authorization;\n            if (!authorization) {\n                throw Boom.unauthorized(null, 'Custom');\n            }\n\n            return h.authenticated({ credentials: { user: 'john' } });\n        }\n    };\n};\n\nserver.auth.scheme('custom', scheme);\nserver.auth.strategy('default', 'custom');\n\nconsole.log(server.auth.api.default.settings.x);    // 5\n```\n\n#### <a name=\"server.auth.settings.default\" /> `server.auth.settings.default`\n\nAccess: read only.\n\nContains the default authentication configuration if a default strategy was set via\n[`server.auth.default()`](#server.auth.default()).\n\n#### <a name=\"server.decorations\" /> `server.decorations`\n\nAccess: read only.\n\nProvides access to the decorations already applied to various framework interfaces. The object must\nnot be modified directly, but only through [`server.decorate`](#server.decorate()).\nContains:\n\n- `request` - decorations on the [request object](#request).\n- `response` - decorations on the [response object](#response-object).\n- `toolkit` - decorations on the [response toolkit](#response-toolkit).\n- `server` - decorations on the [server](#server) object.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({ port: 80 });\n\nconst success = function () {\n\n    return this.response({ status: 'ok' });\n};\n\nserver.decorate('toolkit', 'success', success);\nconsole.log(server.decorations.toolkit);            // ['success']\n```\n\n#### <a name=\"server.events\" /> `server.events`\n\nAccess: **podium** public interface.\n\nThe server events emitter. Utilizes the [**podium**](https://hapi.dev/family/podium/api) with support\nfor event criteria validation, channels, and filters.\n\nUse the following methods to interact with `server.events`:\n\n- [`server.event(events)`](#server.event()) - register application events.\n- [`server.events.emit(criteria, data)`](#server.events.emit()) - emit server events.\n- [`server.events.on(criteria, listener, context)`](#server.events.on()) - subscribe to all events.\n- [`server.events.once(criteria, listener, context)`](#server.events.once()) - subscribe to a single event.\n\nOther methods include: `server.events.removeListener(name, listener)`,\n`server.events.removeAllListeners(name)`, and `server.events.hasListeners(name)`.\n\n##### <a name=\"server.events.log\" /> `'log'` Event\n\nThe `'log'` event type emits internal server events generated by the framework as well as\napplication events logged with [`server.log()`](#server.log()).\n\nThe `'log'` event handler uses the function signature `function(event, tags)` where:\n\n- `event` - an object with the following properties:\n    - `timestamp` - the event timestamp.\n    - `tags` - an array of tags identifying the event (e.g. `['error', 'http']`).\n    - `channel` - set to `'internal'` for internally generated events, otherwise `'app'` for events\n      generated by [`server.log()`](#server.log()).\n    - `data` - event-specific information. Available when event data was provided and is not an\n      error. Errors are passed via `error`.\n    - `error` - the error object related to the event if applicable. Cannot appear together with\n      `data`.\n\n- `tags` - an object where each `event.tag` is a key and the value is `true`. Useful for quick\n  identification of events.\n\n```js\nserver.events.on('log', (event, tags) => {\n\n    if (tags.error) {\n        console.log(`Server error: ${event.error ? event.error.message : 'unknown'}`);\n    }\n});\n```\n\nThe internally generated events are (identified by their `tags`):\n\n- `load` - logs the current server load measurements when the server rejects a request due to\n  [high load](#server.options.load). The event data contains the process load metrics.\n\n- `connection` `client` `error` - a `clientError` event was received from the HTTP or HTTPS\n  listener. The event data is the error object received.\n\n##### <a name=\"server.events.cachePolicy\" /> `'cachePolicy'` Event\n\nThe `'cachePolicy'` event type is emitted when a server [cache policy](https://hapi.dev/module/catbox/api#policy)\nis created via [`server.cache()`](#server.cache()) or a [`server.method()`](#server.method()) with caching enabled is registered.\nThe `'cachePolicy'` event handler uses the function signature `function(cachePolicy, cache, segment)` where:\n\n- `cachePolicy` - the catbox [cache policy](https://hapi.dev/module/catbox/api#policy).\n- `cache` - the [cache provision](#server.options.cache) name used when the policy was created or `undefined` if the default cache was used.\n- `segment` - the segment name used when the policy was created.\n\n```js\nserver.events.on('cachePolicy', (cachePolicy, cache, segment) => {\n\n    console.log(`New cache policy created using cache: ${cache === undefined ? 'default' : cache} and segment: ${segment}`);\n});\n```\n\n##### <a name=\"server.events.request\" /> `'request'` Event\n\nThe `'request'` event type emits internal request events generated by the framework as well as\napplication events logged with [`request.log()`](#request.log()).\n\nThe `'request'` event handler uses the function signature `function(request, event, tags)` where:\n\n- `request` - the [request object](#request).\n\n- `event` - an object with the following properties:\n    - `timestamp` - the event timestamp.\n    - `tags` - an array of tags identifying the event (e.g. `['error', 'http']`).\n    - `channel` - one of\n        - `'app'` - events generated by [`request.log()`](#request.log()).\n        - `'error'` - emitted once per request if the response had a `500` status code.\n        - `'internal'` - internally generated events.\n    - `request` - the request [identifier](#request.info.id).\n    - `data` - event-specific information. Available when event data was provided and is not an\n      error. Errors are passed via `error`.\n    - `error` - the error object related to the event if applicable. Cannot appear together with\n      `data`.\n\n- `tags` - an object where each `event.tag` is a key and the value is `true`. Useful for quick\n  identification of events.\n\n```js\nserver.events.on('request', (request, event, tags) => {\n\n    if (tags.error) {\n        console.log(`Request ${event.request} error: ${event.error ? event.error.message : 'unknown'}`);\n    }\n});\n```\n\nTo listen to only one of the channels, use the event criteria object:\n\n```js\nserver.events.on({ name: 'request', channels: 'error' }, (request, event, tags) => {\n\n    console.log(`Request ${event.request} failed`);\n});\n```\n\nThe internally generated events are (identified by their `tags`):\n\n- `accept-encoding` `error` - a request received contains an invalid Accept-Encoding header.\n- `auth` `unauthenticated` - no authentication scheme included with the request.\n- `auth` `unauthenticated` `response` `{strategy}` - the authentication strategy listed returned a non-error response (e.g. a redirect to a login page).\n- `auth` `unauthenticated` `error` `{strategy}` - the request failed to pass the listed authentication strategy (invalid credentials).\n- `auth` `unauthenticated` `missing` `{strategy}` - the request failed to pass the listed authentication strategy (no credentials found).\n- `auth` `unauthenticated` `try` `{strategy}` - the request failed to pass the listed authentication strategy in `'try'` mode and will continue.\n- `auth` `scope` `error` - the request authenticated but failed to meet the scope requirements.\n- `auth` `entity` `user` `error` - the request authenticated but included an application entity when a user entity was required.\n- `auth` `entity` `app` `error` - the request authenticated but included a user entity when an application entity was required.\n- `ext` `error` - an `onPostResponse` extension handler errored.\n- `handler` `error` - the route handler returned an error. Includes the execution duration and the error message.\n- `pre` `error` - a pre method was executed and returned an error. Includes the execution duration, assignment key, and error.\n- `internal` `error` - an HTTP 500 error response was assigned to the request.\n- `internal` `implementation` `error` - an incorrectly implemented [lifecycle method](#lifecycle-methods).\n- `request` `error` `abort` - the request aborted.\n- `request` `error` `close` - the request closed prematurely.\n- `request` `error` - the request stream emitted an error. Includes the error.\n- `request` `server` `timeout` `error` - the request took too long to process by the server. Includes the timeout configuration value and the duration.\n- `state` `error` - the request included an invalid cookie or cookies. Includes the cookies and error details.\n- `state` `response` `error` - the response included an invalid cookie which prevented generating a valid header. Includes the error.\n- `payload` `error` - failed processing the request payload. Includes the error.\n- `response` `error` - failed writing the response to the client. Includes the error.\n- `response` `error` `close` - failed writing the response to the client due to prematurely closed connection.\n- `response` `error` `aborted` - failed writing the response to the client due to prematurely aborted connection.\n- `response` `error` `cleanup` - failed freeing response resources.\n- `validation` `error` `{input}` - input (i.e. payload, query, params, headers) validation failed. Includes the error. Only emitted when `failAction` is set to `'log'`.\n- `validation` `response` `error` - response validation failed. Includes the error message. Only emitted when `failAction` is set to `'log'`.\n\n##### <a name=\"server.events.response\" /> `'response'` Event\n\nThe `'response'` event type is emitted after the response is sent back to the client (or when the\nclient connection closed and no response sent, in which case [`request.response`](#request.response)\nis `null`). A single event is emitted per request. The `'response'` event handler uses the function\nsignature `function(request)` where:\n\n- `request` - the [request object](#request).\n\n```js\nserver.events.on('response', (request) => {\n\n    console.log(`Response sent for request: ${request.info.id}`);\n});\n```\n\n##### <a name=\"server.events.route\" /> `'route'` Event\n\nThe `'route'` event type is emitted when a route is added via [`server.route()`](#server.route()).\nThe `'route'` event handler uses the function signature `function(route)` where:\n\n- `route` - the [route information](#request.route). The `route` object must not be modified.\n\n```js\nserver.events.on('route', (route) => {\n\n    console.log(`New route added: ${route.path}`);\n});\n```\n\n##### <a name=\"server.events.start\" /> `'start'` Event\n\nThe `'start'` event type is emitted when the server is started using [`server.start()`](#server.start()).\nThe `'start'` event handler uses the function signature `function()`.\n\n```js\nserver.events.on('start', () => {\n\n    console.log('Server started');\n});\n```\n\n##### <a name=\"server.events.closing\" /> `'closing'` Event\n\nThe `'closing'` event type is emitted when the server is stopped using [`server.stop()`](#server.stop()). It is triggered when incoming requests are no longer accepted but before all underlying active connections have been closed, and thus before the [`'stop'`](#server.events.stop) event is triggered.\nThe `'closing'` event handler uses the function signature `function()`.\n\n```js\nserver.events.on('closing', () => {\n\n    console.log('Server is closing');\n});\n```\n\n##### <a name=\"server.events.stop\" /> `'stop'` Event\n\nThe `'stop'` event type is emitted when the server is stopped using [`server.stop()`](#server.stop()).\nThe `'stop'` event handler uses the function signature `function()`.\n\n```js\nserver.events.on('stop', () => {\n\n    console.log('Server stopped');\n});\n```\n\n#### <a name=\"server.info\" /> `server.info`\n\nAccess: read only.\n\nAn object containing information about the server where:\n\n- `id` - a unique server identifier (using the format '{hostname}:{pid}:{now base36}').\n\n- `created` - server creation timestamp.\n\n- `started` - server start timestamp (`0` when stopped).\n\n- `port` - the connection port based on the following rules:\n\n    - before the server has been started: the configured [`port`](#server.options.port) value.\n    - after the server has been started: the actual port assigned when no port is configured or was\n      set to `0`.\n\n- `host` - The [`host`](#server.options.host) configuration value.\n\n- `address` - the active IP address the connection was bound to after starting. Set to `undefined`\n  until the server has been started or when using a non TCP port (e.g. UNIX domain socket).\n\n- `protocol` - the protocol used:\n\n    - `'http'` - HTTP.\n    - `'https'` - HTTPS.\n    - `'socket'` - UNIX domain socket or Windows named pipe.\n\n- `uri` - a string representing the connection (e.g. 'http://example.com:8080' or\n  'socket:/unix/domain/socket/path'). Contains the [`uri`](#server.options.uri) value if set,\n  otherwise constructed from the available settings. If no [`port`](#server.options.port) is\n  configured or is set to `0`, the `uri` will not include a port component until the server is\n  started.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({ port: 80 });\n\nconsole.log(server.info.port);            // 80\n```\n\n#### <a name=\"server.listener\" /> `server.listener`\n\nAccess: read only and listener public interface.\n\nThe node HTTP server object.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst SocketIO = require('socket.io');\n\nconst server = Hapi.server({ port: 80 });\n\nconst io = SocketIO.listen(server.listener);\nio.sockets.on('connection', (socket) => {\n\n    socket.emit({ msg: 'welcome' });\n});\n```\n\n#### <a name=\"server.load\" /> `server.load`\n\nAccess: read only.\n\nAn object containing the process load metrics (when [`load.sampleInterval`](#server.options.load)\nis enabled):\n\n- `eventLoopDelay` - event loop delay milliseconds.\n- `eventLoopUtilization` - current event loop utilization value.\n- `heapUsed` - V8 heap usage.\n- `rss` - RSS memory usage.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({ load: { sampleInterval: 1000 } });\n\nconsole.log(server.load.rss);\n```\n\n#### <a name=\"server.methods\" /> `server.methods`\n\nAccess: read only.\n\nServer methods are functions registered with the server and used throughout the application as a\ncommon utility. Their advantage is in the ability to configure them to use the built-in cache and\nshare across multiple request handlers without having to create a common module.\n\n`sever.methods` is an object which provides access to the methods registered via\n[server.method()](#server.method()) where each server method name is an object\nproperty.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server();\n\nserver.method('add', (a, b) => (a + b));\nconst result = server.methods.add(1, 2);    // 3\n```\n\n#### <a name=\"server.mime\" /> `server.mime`\n\nAccess: read only and **mimos** public interface.\n\nProvides access to the server MIME database used for setting content-type information. The object\nmust not be modified directly but only through the [`mime`](#server.options.mime) server setting.\n\n```js\nconst Hapi = require('@hapi/hapi');\n\nconst options = {\n    mime: {\n        override: {\n            'node/module': {\n                source: 'steve',\n                compressible: false,\n                extensions: ['node', 'module', 'npm'],\n                type: 'node/module'\n            }\n        }\n    }\n};\n\nconst server = Hapi.server(options);\nconsole.log(server.mime.path('code.js').type)        // 'application/javascript'\nconsole.log(server.mime.path('file.npm').type)        // 'node/module'\n```\n\n#### <a name=\"server.plugins\" /> `server.plugins`\n\nAccess: read / write.\n\nAn object containing the values exposed by each registered plugin where each key is a plugin name\nand the values are the exposed properties by each plugin using\n[`server.expose()`](#server.expose()). Plugins may set the value of the\n`server.plugins[name]` object directly or via the `server.expose()` method.\n\n```js\nexports.plugin = {\n    name: 'example',\n    register: function (server, options) {\n\n        server.expose('key', 'value');\n        server.plugins.example.other = 'other';\n\n        console.log(server.plugins.example.key);      // 'value'\n        console.log(server.plugins.example.other);    // 'other'\n    }\n};\n```\n\n#### <a name=\"server.realm\" /> `server.realm`\n\nAccess: read only.\n\nThe realm object contains sandboxed server settings specific to each plugin or authentication\nstrategy. When registering a plugin or an authentication scheme, a `server` object reference is\nprovided with a new `server.realm` container specific to that registration. It allows each plugin\nto maintain its own settings without leaking and affecting other plugins.\n\nFor example, a plugin can set a default file path for local resources without breaking other\nplugins' configured paths. When calling [`server.bind()`](#server.bind()), the active realm's\n`settings.bind` property is set which is then used by routes and extensions added at the same level\n(server root or plugin).\n\nThe `server.realm` object contains:\n\n- `modifiers` - when the server object is provided as an argument to the plugin `register()`\n  method, `modifiers` provides the registration preferences passed the\n  [`server.register()`](#server.register()) method and includes:\n\n    - `route` - routes preferences:\n\n        - `prefix` - the route path prefix used by any calls to [`server.route()`](#server.route())\n          from the server. Note that if a prefix is used and the route path is set to `'/'`, the\n          resulting path will not include the trailing slash.\n        - `vhost` - the route virtual host settings used by any calls to\n          [`server.route()`](#server.route()) from the server.\n\n- `parent` - the realm of the parent server object, or `null` for the root server.\n\n- `plugin` - the active plugin name (empty string if at the server root).\n\n- `pluginOptions` - the plugin options passed at registration.\n\n- `plugins` - plugin-specific state to be shared only among activities sharing the same active\n  state. `plugins` is an object where each key is a plugin name and the value is the plugin state.\n\n- `settings` - settings overrides:\n\n    - `files.relativeTo`\n    - `bind`\n\nThe `server.realm` object should be considered read-only and must not be changed directly except\nfor the `plugins` property which can be directly manipulated by each plugin, setting its properties\ninside `plugins[name]`.\n\n```js\nexports.register = function (server, options) {\n\n    console.log(server.realm.modifiers.route.prefix);\n};\n```\n\n#### <a name=\"server.registrations\" /> `server.registrations`\n\nAccess: read only.\n\nAn object of the currently registered plugins where each key is a registered plugin name and the\nvalue is an object containing:\n\n- `version` - the plugin version.\n- `name` - the plugin name.\n- `options` - (optional) options passed to the plugin during registration.\n\n#### <a name=\"server.settings\" /> `server.settings`\n\nAccess: read only.\n\nThe server configuration object after defaults applied.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({\n    app: {\n        key: 'value'\n    }\n});\n\nconsole.log(server.settings.app);   // { key: 'value' }\n```\n\n#### <a name=\"server.states\" /> `server.states`\n\nAccess: read only and **statehood** public interface.\n\nThe server cookies manager.\n\n#### <a name=\"server.states.settings\" /> `server.states.settings`\n\nAccess: read only.\n\nThe server cookies manager settings. The settings are based on the values configured in\n[`server.options.state`](#server.options.state).\n\n#### <a name=\"server.states.cookies\" /> `server.states.cookies`\n\nAccess: read only.\n\nAn object containing the configuration of each cookie added via [`server.state()`](#server.state())\nwhere each key is the cookie name and value is the configuration object.\n\n#### <a name=\"server.states.names\" /> `server.states.names`\n\nAccess: read only.\n\nAn array containing the names of all configured cookies.\n\n#### <a name=\"server.type\" /> `server.type`\n\nAccess: read only.\n\nA string indicating the listener type where:\n- `'socket'` - UNIX domain socket or Windows named pipe.\n- `'tcp'` - an HTTP listener.\n\n#### <a name=\"server.version\" /> `server.version`\n\nAccess: read only.\n\nThe **hapi** module version number.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server();\n\nconsole.log(server.version);        // '17.0.0'\n```\n\n### <a name=\"server.auth.default()\" /> `server.auth.default(options)`\n\nSets a default strategy which is applied to every route where:\n\n- `options` - one of:\n\n    - a string with the default strategy name\n    - an authentication configuration object using the same format as the\n      [route `auth` handler options](#route.options.auth).\n\nReturn value: none.\n\nThe default does not apply when a route config specifies `auth` as `false`, or has an\nauthentication strategy configured (contains the [`strategy`](#route.options.auth.strategy) or\n[`strategies`](#route.options.auth.strategies) authentication settings). Otherwise, the route\nauthentication config is applied to the defaults.\n\nNote that if the route has authentication configured, the default only applies at the time of\nadding the route, not at runtime. This means that calling `server.auth.default()` after adding a\nroute with some authentication config will have no impact on the routes added prior. However, the\ndefault will apply to routes added before `server.auth.default()` is called if those routes lack\nany authentication config.\n\nThe default auth strategy configuration can be accessed via [`server.auth.settings.default`](#server.auth.settings.default).\nTo obtain the active authentication configuration of a route, use `server.auth.lookup(request.route)`.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({ port: 80 });\n\nserver.auth.scheme('custom', scheme);\nserver.auth.strategy('default', 'custom');\nserver.auth.default('default');\n\nserver.route({\n    method: 'GET',\n    path: '/',\n    handler: function (request, h) {\n\n        return request.auth.credentials.user;\n    }\n});\n```\n\n### <a name=\"server.auth.scheme()\" /> `server.auth.scheme(name, scheme)`\n\nRegisters an authentication scheme where:\n\n- `name` - the scheme name.\n- `scheme` - the method implementing the scheme with signature `function(server, options)` where:\n    - `server` - a reference to the server object the scheme is added to. Each auth strategy is given its own [`server.realm`](#server.realm) whose parent is the realm of the `server` in the call to [`server.auth.strategy()`](#server.auth.strategy()).\n    - `options` - (optional) the scheme `options` argument passed to\n      [`server.auth.strategy()`](#server.auth.strategy()) when instantiation a strategy.\n\nReturn value: none.\n\nThe `scheme` function must return an [authentication scheme object](#authentication-scheme) when\ninvoked.\n\n#### Authentication scheme\n\nAn authentication scheme is an object with the following properties:\n\n- `api` - (optional) object which is exposed via the [`server.auth.api`](#server.auth.api) object.\n\n- `async authenticate(request, h)` - (required) a [lifecycle method](#lifecycle-methods) function\n  called for each incoming request configured with the authentication scheme. The method is\n  provided with two special toolkit methods for returning an authenticated or an unauthenticate\n  result:\n    - [`h.authenticated()`](#h.authenticated()) - indicate request authenticated successfully.\n    - [`h.unauthenticated()`](#h.unauthenticated()) - indicate request failed to authenticate.\n\n- `async payload(request, h)` - (optional) a [lifecycle method](#lifecycle-methods) to authenticate\n  the request payload.\n\n- `async response(request, h)` - (optional) a [lifecycle method](#lifecycle-methods) to decorate\n  the response with authentication headers before the response headers or payload is written.\n\n- `async verify(auth)` - (optional) a method used to verify the authentication credentials provided\n  are still valid (e.g. not expired or revoked after the initial authentication) where:\n  - `auth` - the [`request.auth`](#request.auth) object containing the `credentials` and\n    `artifacts` objects returned by the scheme's `authenticate()` method.\n  - the method throws an `Error` when the credentials passed are no longer valid (e.g. expired or\n  revoked). Note that the method does not have access to the original request, only to the\n  credentials and artifacts produced by the `authenticate()` method.\n\n- `options` - (optional) an object with the following keys:\n    - `payload` - if `true`, requires payload validation as part of the scheme and forbids routes\n      from disabling payload auth validation. Defaults to `false`.\n\nWhen the scheme `authenticate()` method implementation throws an error or calls\n[`h.unauthenticated()`](#h.unauthenticated()), the specifics of the error affect whether additional\nauthentication strategies will be attempted (if configured for the route). If the error includes a\nmessage, no additional strategies will be attempted. If the `err` does not include a message but\ndoes include the scheme name (e.g. `Boom.unauthorized(null, 'Custom')`), additional strategies will\nbe attempted in the order of preference (defined in the route configuration). If authentication\nfails, the scheme names will be present in the 'WWW-Authenticate' header.\n\nWhen the scheme `payload()` method throws an error with a message, it means payload validation\nfailed due to bad payload. If the error has no message but includes a scheme name (e.g.\n`Boom.unauthorized(null, 'Custom')`), authentication may still be successful if the route\n[`auth.payload`](#route.options.auth.payload) configuration is set to `'optional'`.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({ port: 80 });\n\nconst scheme = function (server, options) {\n\n    return {\n        authenticate: function (request, h) {\n\n            const req = request.raw.req;\n            const authorization = req.headers.authorization;\n            if (!authorization) {\n                throw Boom.unauthorized(null, 'Custom');\n            }\n\n            return h.authenticated({ credentials: { user: 'john' } });\n        }\n    };\n};\n\nserver.auth.scheme('custom', scheme);\n```\n\n### <a name=\"server.auth.strategy()\" /> `server.auth.strategy(name, scheme, [options])`\n\nRegisters an authentication strategy where:\n\n- `name` - the strategy name.\n- `scheme` - the scheme name (must be previously registered using\n  [`server.auth.scheme()`](#server.auth.scheme())).\n- `options` - scheme options based on the scheme requirements.\n\nReturn value: none.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({ port: 80 });\n\nserver.auth.scheme('custom', scheme);\nserver.auth.strategy('default', 'custom');\n\nserver.route({\n    method: 'GET',\n    path: '/',\n    options: {\n        auth: 'default',\n        handler: function (request, h) {\n\n            return request.auth.credentials.user;\n        }\n    }\n});\n```\n\n### <a name=\"server.auth.test()\" /> `await server.auth.test(strategy, request)`\n\nTests a request against an authentication strategy where:\n\n- `strategy` - the strategy name registered with [`server.auth.strategy()`](#server.auth.strategy()).\n- `request` - the [request object](#request).\n\nReturn value: an object containing the authentication `credentials` and `artifacts` if authentication\nwas successful, otherwise throws an error.\n\nNote that the `test()` method does not take into account the route authentication configuration. It\nalso does not perform payload authentication. It is limited to the basic strategy authentication\nexecution. It does not include verifying scope, entity, or other route properties.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({ port: 80 });\n\nserver.auth.scheme('custom', scheme);\nserver.auth.strategy('default', 'custom');\n\nserver.route({\n    method: 'GET',\n    path: '/',\n    handler: async function (request, h) {\n\n        try {\n            const { credentials, artifacts } = await request.server.auth.test('default', request);\n            return { status: true, user: credentials.name };\n        }\n        catch (err) {\n            return { status: false };\n        }\n    }\n});\n```\n\n\n### <a name=\"server.auth.verify()\" /> `await server.auth.verify(request)`\n\nVerify a request's authentication credentials against an authentication strategy where:\n\n- `request` - the [request object](#request).\n\nReturn value: nothing if verification was successful, otherwise throws an error.\n\nNote that the `verify()` method does not take into account the route authentication configuration\nor any other information from the request other than the `request.auth` object. It also does not\nperform payload authentication. It is limited to verifying that the previously valid credentials\nare still valid (e.g. have not been revoked or expired). It does not include verifying scope,\nentity, or other route properties.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({ port: 80 });\n\nserver.auth.scheme('custom', scheme);\nserver.auth.strategy('default', 'custom');\n\nserver.route({\n    method: 'GET',\n    path: '/',\n    handler: async function (request, h) {\n\n        try {\n            const credentials = await request.server.auth.verify(request);\n            return { status: true, user: credentials.name };\n        }\n        catch (err) {\n            return { status: false };\n        }\n    }\n});\n```\n\n### <a name=\"server.bind()\" /> `server.bind(context)`\n\nSets a global context used as the default bind object when adding a route or an extension where:\n\n- `context` - the object used to bind `this` in [lifecycle methods](#lifecycle-methods) such as\n  the [route handler](#route.options.handler) and [extension methods](#server.ext()). The context\n  is also made available as [`h.context`](#h.context).\n\nReturn value: none.\n\nWhen setting a context inside a plugin, the context is applied only to methods set up by the\nplugin. Note that the context applies only to routes and extensions added after it has been set.\nIgnored if the method being bound is an arrow function.\n\n```js\nconst handler = function (request, h) {\n\n    return this.message;    // Or h.context.message\n};\n\nexports.plugin = {\n    name: 'example',\n    register: function (server, options) {\n\n        const bind = {\n            message: 'hello'\n        };\n\n        server.bind(bind);\n        server.route({ method: 'GET', path: '/', handler });\n    }\n};\n```\n\n### <a name=\"server.cache()\" /> `server.cache(options)`\n\nProvisions a cache segment within the server cache facility where:\n\n- `options` - [**catbox** policy](https://hapi.dev/family/catbox/api#policy) configuration where:\n\n    - `expiresIn` - relative expiration expressed in the number of milliseconds since the item was\n      saved in the cache. Cannot be used together with `expiresAt`.\n\n    - `expiresAt` - time of day expressed in 24h notation using the 'HH:MM' format, at which point\n      all cache records expire. Uses local time. Cannot be used together with `expiresIn`.\n\n    - `generateFunc` - a function used to generate a new cache item if one is not found in the\n      cache when calling `get()`. The method's signature is `async function(id, flags)` where:\n\n          - `id` - the `id` string or object provided to the `get()` method.\n          - `flags` - an object used to pass back additional flags to the cache where:\n              - `ttl` - the cache ttl value in milliseconds. Set to `0` to skip storing in the\n                cache. Defaults to the cache global policy.\n\n    - `staleIn` - number of milliseconds to mark an item stored in cache as stale and attempt to\n      regenerate it when `generateFunc` is provided. Must be less than `expiresIn`.\n\n    - `staleTimeout` - number of milliseconds to wait before checking if an item is stale.\n\n    - `generateTimeout` - number of milliseconds to wait before returning a timeout error when the\n      `generateFunc` function takes too long to return a value. When the value is eventually\n      returned, it is stored in the cache for future requests. Required if `generateFunc` is\n      present. Set to `false` to disable timeouts which may cause all `get()` requests to get stuck\n      forever.\n\n    - `generateOnReadError` - if `false`, an upstream cache read error will stop the `cache.get()`\n      method from calling the generate function and will instead pass back the cache error. Defaults\n      to `true`.\n\n    - `generateIgnoreWriteError` - if `false`, an upstream cache write error when calling\n      `cache.get()` will be passed back with the generated value when calling. Defaults to `true`.\n\n    - `dropOnError` - if `true`, an error or timeout in the `generateFunc` causes the stale value\n      to be evicted from the cache.  Defaults  to `true`.\n\n    - `pendingGenerateTimeout` - number of milliseconds while `generateFunc` call is in progress\n      for a given id, before a subsequent `generateFunc` call is allowed. Defaults to `0` (no\n      blocking of concurrent `generateFunc` calls beyond `staleTimeout`).\n\n    - `cache` - the cache name configured in [`server.cache`](#server.options.cache). Defaults to\n      the default cache.\n\n    - `segment` - string segment name, used to isolate cached items within the cache partition.\n      When called within a plugin, defaults to '!name' where 'name' is the plugin name. When called\n      within a server method, defaults to '#name' where 'name' is the server method name. Required\n      when called outside of a plugin.\n\n    - `shared` - if `true`, allows multiple cache provisions to share the same segment. Default to\n      `false`.\n\nReturn value: a [**catbox** policy](https://hapi.dev/family/catbox/api#policy) object.\n\n```js\nconst Hapi = require('@hapi/hapi');\n\nasync function example() {\n\n    const server = Hapi.server({ port: 80 });\n    const cache = server.cache({ segment: 'countries', expiresIn: 60 * 60 * 1000 });\n    await cache.set('norway', { capital: 'oslo' });\n    const value = await cache.get('norway');\n}\n```\n\n### <a name=\"server.cache.provision()\" /> `await server.cache.provision(options)`\n\nProvisions a server cache as described in [`server.cache`](#server.options.cache"},"files":{"API.md":"\n## Server\n\nThe server object is the main application container. The server manages all incoming requests\nalong with all the facilities provided by the framework. Each server supports a single connection\n(e.g. listen to port `80`).\n\n### <a name=\"server()\" /> `server([options])`\n\nCreates a new server object where:\n- `options` - (optional) a [server configuration object](#server.options).\n\n```js\nconst Hapi = require('@hapi/hapi');\n\nconst server = Hapi.server({ load: { sampleInterval: 1000 } });\n```\n\n### <a name=\"server.options\" /> Server options\n\nThe server options control the behavior of the server object. Note that the options object is\ndeeply cloned (with the exception of [`listener`](#server.options.listener) which is shallowly\ncopied) and should not contain any values that are unsafe to perform deep copy on.\n\nAll options are optionals.\n\n#### <a name=\"server.options.address\" /> `server.options.address`\n\nDefault value: `'::'` if IPv6 is available, otherwise `'0.0.0.0'` (i.e. all available network interfaces).\n\nSets the hostname or IP address the server will listen on. If not configured, defaults to\n[`host`](#server.options.host) if present, otherwise to all available network interfaces. Set to\n`'127.0.0.1'`, `'::1'`, or `'localhost'` to restrict the server to only those coming from the same host.\n\n#### <a name=\"server.options.app\" /> `server.options.app`\n\nDefault value: `{}`.\n\nProvides application-specific configuration which can later be accessed via\n[`server.settings.app`](#server.settings). The framework does not interact with this object. It is\nsimply a reference made available anywhere a `server` reference is provided.\n\nNote the difference between `server.settings.app` which is used to store static configuration\nvalues and [`server.app`](#server.app) which is meant for storing run-time state.\n\n#### <a name=\"server.options.autolisten\" /> `server.options.autoListen`\n\nDefault value: `true`.\n\nUsed to disable the automatic initialization of the [`listener`](#server.options.listener). When\n`false`, indicates that the [`listener`](#server.options.listener) will be started manually outside\nthe framework.\n\nCannot be set to `false` along with a [`port`](#server.options.port) value.\n\n#### <a name=\"server.options.cache\" /> `server.options.cache`\n\nDefault value: `{ provider: { constructor: require('@hapi/catbox-memory'), options: { partition: 'hapi-cache' } } }`.\n\nSets up server-side caching providers. Every server includes a default cache for storing\napplication state. By default, a simple memory-based cache is created which has limited capacity\nand capabilities.\n\n**hapi** uses [**catbox**](https://hapi.dev/family/catbox/api) for its cache implementation which\nincludes support for common storage solutions (e.g. Redis, MongoDB, Memcached, Riak, among others).\nCaching is only utilized if [methods](#server.methods) and [plugins](#plugins) explicitly store\ntheir state in the cache.\n\nThe server cache configuration only defines the storage container itself. The configuration can be\nassigned one or more (array):\n\n- a class or prototype function (usually obtained by calling `require()` on a **catbox** strategy\n    such as `require('@hapi/catbox-redis')`). A new **catbox** [client](https://hapi.dev/family/catbox/api#client)\n    will be created internally using this constructor.\n\n- a configuration object with the following:\n\n    - `engine` - a **catbox** engine object instance.\n\n    - `name` - an identifier used later when provisioning or configuring caching for\n        [server methods](#server.methods) or [plugins](#plugins). Each cache name must be unique.\n        A single item may omit the `name` option which defines the default cache. If every cache\n        includes a `name`, a default memory cache is provisioned as well.\n\n    - `provider` - a class, a constructor function, or an object with the following:\n\n        - `constructor` - a class or a prototype function.\n\n        - `options` - (optional) a settings object passed as-is to the `constructor` with the following:\n\n            - `partition` - (optional) string used to isolate cached data. Defaults to `'hapi-cache'`.\n            - other constructor-specific options passed to the `constructor` on instantiation.\n\n    - `shared` - if `true`, allows multiple cache users to share the same segment (e.g.\n        multiple methods using the same cache storage container). Default to `false`.\n\n    - One (and only one) of `engine` or `provider` is required per configuration object.\n\n#### <a name=\"server.options.compression\" /> `server.options.compression`\n\nDefault value: `{ minBytes: 1024 }`.\n\nDefines server handling of content encoding requests. If `false`, response content encoding is\ndisabled and no compression is performed by the server.\n\n##### <a name=\"server.options.compression.minBytes\" /> `server.options.compression.minBytes`\n\nDefault value: '1024'.\n\nSets the minimum response payload size in bytes that is required for content encoding compression.\nIf the payload size is under the limit, no compression is performed.\n\n#### <a name=\"server.options.debug\" /> `server.options.debug`\n\nDefault value: `{ request: ['implementation'] }`.\n\nDetermines which logged events are sent to the console. This should only be used for development\nand does not affect which events are actually logged internally and recorded. Set to `false` to\ndisable all console logging, or to an object with:\n\n- `log` - a string array of server log tags to be displayed via `console.error()` when\n    the events are logged via [`server.log()`](#server.log()) as well as\n    internally generated [server logs](#server-logs). Defaults to no output.\n\n- `request` - a string array of request log tags to be displayed via `console.error()` when\n    the events are logged via [`request.log()`](#request.log()) as well as\n    internally generated [request logs](#request-logs). For example, to display all errors,\n    set the option to `['error']`. To turn off all console debug messages set it to `false`.\n    To display all request logs, set it to `'*'`.\n    Defaults to uncaught errors thrown in external code (these errors are handled\n    automatically and result in an Internal Server Error response) or runtime errors due to\n    developer error.\n\nFor example, to display all errors, set the `log` or `request` to `['error']`. To turn off all\noutput set the `log` or `request` to `false`. To display all server logs, set the `log` or\n`request` to `'*'`. To disable all debug information, set `debug` to `false`.\n\n#### <a name=\"server.options.host\" /> `server.options.host`\n\nDefault value: the operating system hostname and if not available, to `'localhost'`.\n\nThe public hostname or IP address. Used to set [`server.info.host`](#server.info) and\n[`server.info.uri`](#server.info) and as [`address`](#server.options.address) if none is provided.\n\n#### <a name=\"server.options.info.remote\" /> `server.options.info.remote`\n\nDefault value: `false`.\n\nIf `true`, the `request.info.remoteAddress` and `request.info.remotePort` are populated when the request is received which can consume more resource (but is ok if the information is needed, especially for aborted requests). When `false`, the fields are only populated upon demand (but will be `undefined` if accessed after the request is aborted).\n\n#### <a name=\"server.options.listener\" /> `server.options.listener`\n\nDefault value: none.\n\nAn optional node HTTP (or HTTPS) [`http.Server`](https://nodejs.org/api/http.html#http_class_http_server)\nobject (or an object with a compatible interface).\n\nIf the `listener` needs to be manually started, set [`autoListen`](#server.options.autolisten) to\n`false`.\n\nIf the `listener` uses TLS, set [`tls`](#server.options.tls) to `true`.\n\n#### <a name=\"server.options.load\" /> `server.options.load`\n\nDefault value: `{ sampleInterval: 0, maxHeapUsedBytes: 0, maxRssBytes: 0, maxEventLoopDelay: 0, maxEventLoopUtilization: 0 }`.\n\nServer excessive load handling limits where:\n\n- `sampleInterval` - the frequency of sampling in milliseconds. When set to `0`, the other load options are ignored. Defaults to `0` (no sampling).\n\n- `maxHeapUsedBytes` - maximum V8 heap size over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to `0` (no limit).\n\n- `maxRssBytes` - maximum process RSS size over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to `0` (no limit).\n\n- `maxEventLoopDelay` - maximum event loop delay duration in milliseconds over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to `0` (no limit).\n\n- `maxEventLoopUtilization` - maximum event loop utilization value over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to `0` (no limit).\n\n#### <a name=\"server.options.mime\" /> `server.options.mime`\n\nDefault value: none.\n\nOptions passed to the [**mimos**](https://hapi.dev/family/mimos/api) module when generating the mime database used by the server (and accessed via [`server.mime`](#server.mime)):\n\n- `override` - an object hash that is merged into the built in mime information specified [here](https://github.com/jshttp/mime-db). Each key value pair represents a single mime object. Each override value must contain:\n\n    - `key` - the lower-cased mime-type string (e.g. `'application/javascript'`).\n\n    - `value` - an object following the specifications outlined [here](https://github.com/jshttp/mime-db#data-structure). Additional values include:\n\n        - `type` - specify the `type` value of result objects, defaults to `key`.\n\n        - `predicate` - method with signature `function(mime)` when this mime type is found in the database, this function will execute to allows customizations.\n\n```js\nconst options = {\n    mime: {\n        override: {\n            'node/module': {\n                source: 'iana',\n                compressible: true,\n                extensions: ['node', 'module', 'npm'],\n                type: 'node/module'\n            },\n            'application/javascript': {\n                source: 'iana',\n                charset: 'UTF-8',\n                compressible: true,\n                extensions: ['js', 'javascript'],\n                type: 'text/javascript'\n            },\n            'text/html': {\n                predicate: function(mime) {\n                    if (someCondition) {\n                        mime.foo = 'test';\n                    }\n                    else {\n                        mime.foo = 'bar';\n                    }\n                    return mime;\n                }\n            }\n        }\n    }\n};\n```\n\n#### <a name=\"server.options.operations\" /> `server.options.operations`\n\nDefault value: `{ cleanStop: true }`.\n\nDefines server handling of server operations:\n\n- `cleanStop` - if `true`, the server keeps track of open connections and properly closes them\n  when the server is stopped. Under normal load, this should not interfere with server performance.\n  However, under severe load connection monitoring can consume additional resources and aggravate\n  the situation. If the server is never stopped, or if it is forced to stop without waiting for\n  open connection to close, setting this to `false` can save resources that are not being utilized\n  anyway. Defaults to `true`.\n\n#### <a name=\"server.options.plugins\" /> `server.options.plugins`\n\nDefault value: `{}`.\n\nPlugin-specific configuration which can later be accessed via [`server.settings.plugins`](#server.settings).\n`plugins` is an object where each key is a plugin name and the value is the configuration.\nNote the difference between [`server.settings.plugins`](#server.settings) which is used to store\nstatic configuration values and [`server.plugins`](#server.plugins) which is meant for storing\nrun-time state.\n\n#### <a name=\"server.options.port\" /> `server.options.port`\n\nDefault value: `0` (an ephemeral port).\n\nThe TCP port the server will listen to. Defaults the next available port when the server is started\n(and assigned to [`server.info.port`](#server.info)).\n\nIf `port` is a string containing a '/' character, it is used as a UNIX domain socket path.\nIf it starts with '\\\\.\\pipe', it is used as a Windows named pipe.\n\n#### <a name=\"server.options.query\" /> `server.options.query`\n\nDefault value: `{}`.\n\nDefines server handling of the request path query component.\n\n##### <a name=\"server.options.query.parser\" /> `server.options.query.parser`\n\nDefault value: none.\n\nSets a query parameters parser method using the signature `function(query)` where:\n\n- `query` - an object containing the incoming [`request.query`](#request.query) parameters.\n- the method must return an object where each key is a parameter and matching value is the\n  parameter value. If the method throws, the error is used as the response or returned when\n  [`request.setUrl()`](#request.setUrl()) is called.\n\n```js\nconst Qs = require('qs');\n\nconst options = {\n    query: {\n        parser: (query) => Qs.parse(query)\n    }\n};\n```\n\n#### <a name=\"server.options.router\" /> `server.options.router`\n\nDefault value: `{ isCaseSensitive: true, stripTrailingSlash: false }`.\n\nControls how incoming request URIs are matched against the routing table:\n\n- `isCaseSensitive` - determines whether the paths '/example' and '/EXAMPLE' are considered\n  different resources. Defaults to `true`.\n\n- `stripTrailingSlash` - removes trailing slashes on incoming paths. Defaults to `false`.\n\n#### <a name=\"server.options.routes\" /> `server.options.routes`\n\nDefault value: none.\n\nA [route options](#route-options) object used as the default configuration for every route.\n\n#### <a name=\"server.options.state\" /> `server.options.state`\n\nDefault value:\n```js\n{\n    strictHeader: true,\n    ignoreErrors: false,\n    isSecure: true,\n    isHttpOnly: true,\n    isSameSite: 'Strict',\n    isPartitioned: false,\n    encoding: 'none'\n}\n```\n\nSets the default configuration for every state (cookie) set explicitly via\n[`server.state()`](#server.state()) or implicitly (without definition) using the\n[state configuration](#server.state()) object.\n\n#### <a name=\"server.options.tls\" /> `server.options.tls`\n\nDefault value: none.\n\nUsed to create an HTTPS connection. The `tls` object is passed unchanged to the node\nHTTPS server as described in the [node HTTPS documentation](https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener).\n\nSet to `true` when passing a [`listener`](#server.options.listener) object that has been configured\nto use TLS directly.\n\n#### <a name=\"server.options.uri\" /> `server.options.uri`\n\nDefault value: constructed from runtime server information.\n\nThe full public URI without the path (e.g. 'http://example.com:8080'). If present, used as the\nserver [`server.info.uri`](#server.info), otherwise constructed from the server settings.\n\n### Server properties\n\n#### <a name=\"server.app\" /> `server.app`\n\nAccess: read / write.\n\nProvides a safe place to store server-specific run-time application data without potential\nconflicts with the framework internals. The data can be accessed whenever the server is\naccessible. Initialized with an empty object.\n\n```js\nconst server = Hapi.server();\n\nserver.app.key = 'value';\n\nconst handler = function (request, h) {\n\n    return request.server.app.key;        // 'value'\n};\n```\n\n#### <a name=\"server.auth.api\" /> `server.auth.api`\n\nAccess: authentication strategy specific.\n\nAn object where each key is an authentication strategy name and the value is the exposed strategy\nAPI. Available only when the authentication scheme exposes an API by returning an `api` key in the\nobject returned from its implementation function.\n\n```js\nconst server = Hapi.server({ port: 80 });\n\nconst scheme = function (server, options) {\n\n    return {\n        api: {\n            settings: {\n                x: 5\n            }\n        },\n        authenticate: function (request, h) {\n\n            const authorization = request.headers.authorization;\n            if (!authorization) {\n                throw Boom.unauthorized(null, 'Custom');\n            }\n\n            return h.authenticated({ credentials: { user: 'john' } });\n        }\n    };\n};\n\nserver.auth.scheme('custom', scheme);\nserver.auth.strategy('default', 'custom');\n\nconsole.log(server.auth.api.default.settings.x);    // 5\n```\n\n#### <a name=\"server.auth.settings.default\" /> `server.auth.settings.default`\n\nAccess: read only.\n\nContains the default authentication configuration if a default strategy was set via\n[`server.auth.default()`](#server.auth.default()).\n\n#### <a name=\"server.decorations\" /> `server.decorations`\n\nAccess: read only.\n\nProvides access to the decorations already applied to various framework interfaces. The object must\nnot be modified directly, but only through [`server.decorate`](#server.decorate()).\nContains:\n\n- `request` - decorations on the [request object](#request).\n- `response` - decorations on the [response object](#response-object).\n- `toolkit` - decorations on the [response toolkit](#response-toolkit).\n- `server` - decorations on the [server](#server) object.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({ port: 80 });\n\nconst success = function () {\n\n    return this.response({ status: 'ok' });\n};\n\nserver.decorate('toolkit', 'success', success);\nconsole.log(server.decorations.toolkit);            // ['success']\n```\n\n#### <a name=\"server.events\" /> `server.events`\n\nAccess: **podium** public interface.\n\nThe server events emitter. Utilizes the [**podium**](https://hapi.dev/family/podium/api) with support\nfor event criteria validation, channels, and filters.\n\nUse the following methods to interact with `server.events`:\n\n- [`server.event(events)`](#server.event()) - register application events.\n- [`server.events.emit(criteria, data)`](#server.events.emit()) - emit server events.\n- [`server.events.on(criteria, listener, context)`](#server.events.on()) - subscribe to all events.\n- [`server.events.once(criteria, listener, context)`](#server.events.once()) - subscribe to a single event.\n\nOther methods include: `server.events.removeListener(name, listener)`,\n`server.events.removeAllListeners(name)`, and `server.events.hasListeners(name)`.\n\n##### <a name=\"server.events.log\" /> `'log'` Event\n\nThe `'log'` event type emits internal server events generated by the framework as well as\napplication events logged with [`server.log()`](#server.log()).\n\nThe `'log'` event handler uses the function signature `function(event, tags)` where:\n\n- `event` - an object with the following properties:\n    - `timestamp` - the event timestamp.\n    - `tags` - an array of tags identifying the event (e.g. `['error', 'http']`).\n    - `channel` - set to `'internal'` for internally generated events, otherwise `'app'` for events\n      generated by [`server.log()`](#server.log()).\n    - `data` - event-specific information. Available when event data was provided and is not an\n      error. Errors are passed via `error`.\n    - `error` - the error object related to the event if applicable. Cannot appear together with\n      `data`.\n\n- `tags` - an object where each `event.tag` is a key and the value is `true`. Useful for quick\n  identification of events.\n\n```js\nserver.events.on('log', (event, tags) => {\n\n    if (tags.error) {\n        console.log(`Server error: ${event.error ? event.error.message : 'unknown'}`);\n    }\n});\n```\n\nThe internally generated events are (identified by their `tags`):\n\n- `load` - logs the current server load measurements when the server rejects a request due to\n  [high load](#server.options.load). The event data contains the process load metrics.\n\n- `connection` `client` `error` - a `clientError` event was received from the HTTP or HTTPS\n  listener. The event data is the error object received.\n\n##### <a name=\"server.events.cachePolicy\" /> `'cachePolicy'` Event\n\nThe `'cachePolicy'` event type is emitted when a server [cache policy](https://hapi.dev/module/catbox/api#policy)\nis created via [`server.cache()`](#server.cache()) or a [`server.method()`](#server.method()) with caching enabled is registered.\nThe `'cachePolicy'` event handler uses the function signature `function(cachePolicy, cache, segment)` where:\n\n- `cachePolicy` - the catbox [cache policy](https://hapi.dev/module/catbox/api#policy).\n- `cache` - the [cache provision](#server.options.cache) name used when the policy was created or `undefined` if the default cache was used.\n- `segment` - the segment name used when the policy was created.\n\n```js\nserver.events.on('cachePolicy', (cachePolicy, cache, segment) => {\n\n    console.log(`New cache policy created using cache: ${cache === undefined ? 'default' : cache} and segment: ${segment}`);\n});\n```\n\n##### <a name=\"server.events.request\" /> `'request'` Event\n\nThe `'request'` event type emits internal request events generated by the framework as well as\napplication events logged with [`request.log()`](#request.log()).\n\nThe `'request'` event handler uses the function signature `function(request, event, tags)` where:\n\n- `request` - the [request object](#request).\n\n- `event` - an object with the following properties:\n    - `timestamp` - the event timestamp.\n    - `tags` - an array of tags identifying the event (e.g. `['error', 'http']`).\n    - `channel` - one of\n        - `'app'` - events generated by [`request.log()`](#request.log()).\n        - `'error'` - emitted once per request if the response had a `500` status code.\n        - `'internal'` - internally generated events.\n    - `request` - the request [identifier](#request.info.id).\n    - `data` - event-specific information. Available when event data was provided and is not an\n      error. Errors are passed via `error`.\n    - `error` - the error object related to the event if applicable. Cannot appear together with\n      `data`.\n\n- `tags` - an object where each `event.tag` is a key and the value is `true`. Useful for quick\n  identification of events.\n\n```js\nserver.events.on('request', (request, event, tags) => {\n\n    if (tags.error) {\n        console.log(`Request ${event.request} error: ${event.error ? event.error.message : 'unknown'}`);\n    }\n});\n```\n\nTo listen to only one of the channels, use the event criteria object:\n\n```js\nserver.events.on({ name: 'request', channels: 'error' }, (request, event, tags) => {\n\n    console.log(`Request ${event.request} failed`);\n});\n```\n\nThe internally generated events are (identified by their `tags`):\n\n- `accept-encoding` `error` - a request received contains an invalid Accept-Encoding header.\n- `auth` `unauthenticated` - no authentication scheme included with the request.\n- `auth` `unauthenticated` `response` `{strategy}` - the authentication strategy listed returned a non-error response (e.g. a redirect to a login page).\n- `auth` `unauthenticated` `error` `{strategy}` - the request failed to pass the listed authentication strategy (invalid credentials).\n- `auth` `unauthenticated` `missing` `{strategy}` - the request failed to pass the listed authentication strategy (no credentials found).\n- `auth` `unauthenticated` `try` `{strategy}` - the request failed to pass the listed authentication strategy in `'try'` mode and will continue.\n- `auth` `scope` `error` - the request authenticated but failed to meet the scope requirements.\n- `auth` `entity` `user` `error` - the request authenticated but included an application entity when a user entity was required.\n- `auth` `entity` `app` `error` - the request authenticated but included a user entity when an application entity was required.\n- `ext` `error` - an `onPostResponse` extension handler errored.\n- `handler` `error` - the route handler returned an error. Includes the execution duration and the error message.\n- `pre` `error` - a pre method was executed and returned an error. Includes the execution duration, assignment key, and error.\n- `internal` `error` - an HTTP 500 error response was assigned to the request.\n- `internal` `implementation` `error` - an incorrectly implemented [lifecycle method](#lifecycle-methods).\n- `request` `error` `abort` - the request aborted.\n- `request` `error` `close` - the request closed prematurely.\n- `request` `error` - the request stream emitted an error. Includes the error.\n- `request` `server` `timeout` `error` - the request took too long to process by the server. Includes the timeout configuration value and the duration.\n- `state` `error` - the request included an invalid cookie or cookies. Includes the cookies and error details.\n- `state` `response` `error` - the response included an invalid cookie which prevented generating a valid header. Includes the error.\n- `payload` `error` - failed processing the request payload. Includes the error.\n- `response` `error` - failed writing the response to the client. Includes the error.\n- `response` `error` `close` - failed writing the response to the client due to prematurely closed connection.\n- `response` `error` `aborted` - failed writing the response to the client due to prematurely aborted connection.\n- `response` `error` `cleanup` - failed freeing response resources.\n- `validation` `error` `{input}` - input (i.e. payload, query, params, headers) validation failed. Includes the error. Only emitted when `failAction` is set to `'log'`.\n- `validation` `response` `error` - response validation failed. Includes the error message. Only emitted when `failAction` is set to `'log'`.\n\n##### <a name=\"server.events.response\" /> `'response'` Event\n\nThe `'response'` event type is emitted after the response is sent back to the client (or when the\nclient connection closed and no response sent, in which case [`request.response`](#request.response)\nis `null`). A single event is emitted per request. The `'response'` event handler uses the function\nsignature `function(request)` where:\n\n- `request` - the [request object](#request).\n\n```js\nserver.events.on('response', (request) => {\n\n    console.log(`Response sent for request: ${request.info.id}`);\n});\n```\n\n##### <a name=\"server.events.route\" /> `'route'` Event\n\nThe `'route'` event type is emitted when a route is added via [`server.route()`](#server.route()).\nThe `'route'` event handler uses the function signature `function(route)` where:\n\n- `route` - the [route information](#request.route). The `route` object must not be modified.\n\n```js\nserver.events.on('route', (route) => {\n\n    console.log(`New route added: ${route.path}`);\n});\n```\n\n##### <a name=\"server.events.start\" /> `'start'` Event\n\nThe `'start'` event type is emitted when the server is started using [`server.start()`](#server.start()).\nThe `'start'` event handler uses the function signature `function()`.\n\n```js\nserver.events.on('start', () => {\n\n    console.log('Server started');\n});\n```\n\n##### <a name=\"server.events.closing\" /> `'closing'` Event\n\nThe `'closing'` event type is emitted when the server is stopped using [`server.stop()`](#server.stop()). It is triggered when incoming requests are no longer accepted but before all underlying active connections have been closed, and thus before the [`'stop'`](#server.events.stop) event is triggered.\nThe `'closing'` event handler uses the function signature `function()`.\n\n```js\nserver.events.on('closing', () => {\n\n    console.log('Server is closing');\n});\n```\n\n##### <a name=\"server.events.stop\" /> `'stop'` Event\n\nThe `'stop'` event type is emitted when the server is stopped using [`server.stop()`](#server.stop()).\nThe `'stop'` event handler uses the function signature `function()`.\n\n```js\nserver.events.on('stop', () => {\n\n    console.log('Server stopped');\n});\n```\n\n#### <a name=\"server.info\" /> `server.info`\n\nAccess: read only.\n\nAn object containing information about the server where:\n\n- `id` - a unique server identifier (using the format '{hostname}:{pid}:{now base36}').\n\n- `created` - server creation timestamp.\n\n- `started` - server start timestamp (`0` when stopped).\n\n- `port` - the connection port based on the following rules:\n\n    - before the server has been started: the configured [`port`](#server.options.port) value.\n    - after the server has been started: the actual port assigned when no port is configured or was\n      set to `0`.\n\n- `host` - The [`host`](#server.options.host) configuration value.\n\n- `address` - the active IP address the connection was bound to after starting. Set to `undefined`\n  until the server has been started or when using a non TCP port (e.g. UNIX domain socket).\n\n- `protocol` - the protocol used:\n\n    - `'http'` - HTTP.\n    - `'https'` - HTTPS.\n    - `'socket'` - UNIX domain socket or Windows named pipe.\n\n- `uri` - a string representing the connection (e.g. 'http://example.com:8080' or\n  'socket:/unix/domain/socket/path'). Contains the [`uri`](#server.options.uri) value if set,\n  otherwise constructed from the available settings. If no [`port`](#server.options.port) is\n  configured or is set to `0`, the `uri` will not include a port component until the server is\n  started.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({ port: 80 });\n\nconsole.log(server.info.port);            // 80\n```\n\n#### <a name=\"server.listener\" /> `server.listener`\n\nAccess: read only and listener public interface.\n\nThe node HTTP server object.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst SocketIO = require('socket.io');\n\nconst server = Hapi.server({ port: 80 });\n\nconst io = SocketIO.listen(server.listener);\nio.sockets.on('connection', (socket) => {\n\n    socket.emit({ msg: 'welcome' });\n});\n```\n\n#### <a name=\"server.load\" /> `server.load`\n\nAccess: read only.\n\nAn object containing the process load metrics (when [`load.sampleInterval`](#server.options.load)\nis enabled):\n\n- `eventLoopDelay` - event loop delay milliseconds.\n- `eventLoopUtilization` - current event loop utilization value.\n- `heapUsed` - V8 heap usage.\n- `rss` - RSS memory usage.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({ load: { sampleInterval: 1000 } });\n\nconsole.log(server.load.rss);\n```\n\n#### <a name=\"server.methods\" /> `server.methods`\n\nAccess: read only.\n\nServer methods are functions registered with the server and used throughout the application as a\ncommon utility. Their advantage is in the ability to configure them to use the built-in cache and\nshare across multiple request handlers without having to create a common module.\n\n`sever.methods` is an object which provides access to the methods registered via\n[server.method()](#server.method()) where each server method name is an object\nproperty.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server();\n\nserver.method('add', (a, b) => (a + b));\nconst result = server.methods.add(1, 2);    // 3\n```\n\n#### <a name=\"server.mime\" /> `server.mime`\n\nAccess: read only and **mimos** public interface.\n\nProvides access to the server MIME database used for setting content-type information. The object\nmust not be modified directly but only through the [`mime`](#server.options.mime) server setting.\n\n```js\nconst Hapi = require('@hapi/hapi');\n\nconst options = {\n    mime: {\n        override: {\n            'node/module': {\n                source: 'steve',\n                compressible: false,\n                extensions: ['node', 'module', 'npm'],\n                type: 'node/module'\n            }\n        }\n    }\n};\n\nconst server = Hapi.server(options);\nconsole.log(server.mime.path('code.js').type)        // 'application/javascript'\nconsole.log(server.mime.path('file.npm').type)        // 'node/module'\n```\n\n#### <a name=\"server.plugins\" /> `server.plugins`\n\nAccess: read / write.\n\nAn object containing the values exposed by each registered plugin where each key is a plugin name\nand the values are the exposed properties by each plugin using\n[`server.expose()`](#server.expose()). Plugins may set the value of the\n`server.plugins[name]` object directly or via the `server.expose()` method.\n\n```js\nexports.plugin = {\n    name: 'example',\n    register: function (server, options) {\n\n        server.expose('key', 'value');\n        server.plugins.example.other = 'other';\n\n        console.log(server.plugins.example.key);      // 'value'\n        console.log(server.plugins.example.other);    // 'other'\n    }\n};\n```\n\n#### <a name=\"server.realm\" /> `server.realm`\n\nAccess: read only.\n\nThe realm object contains sandboxed server settings specific to each plugin or authentication\nstrategy. When registering a plugin or an authentication scheme, a `server` object reference is\nprovided with a new `server.realm` container specific to that registration. It allows each plugin\nto maintain its own settings without leaking and affecting other plugins.\n\nFor example, a plugin can set a default file path for local resources without breaking other\nplugins' configured paths. When calling [`server.bind()`](#server.bind()), the active realm's\n`settings.bind` property is set which is then used by routes and extensions added at the same level\n(server root or plugin).\n\nThe `server.realm` object contains:\n\n- `modifiers` - when the server object is provided as an argument to the plugin `register()`\n  method, `modifiers` provides the registration preferences passed the\n  [`server.register()`](#server.register()) method and includes:\n\n    - `route` - routes preferences:\n\n        - `prefix` - the route path prefix used by any calls to [`server.route()`](#server.route())\n          from the server. Note that if a prefix is used and the route path is set to `'/'`, the\n          resulting path will not include the trailing slash.\n        - `vhost` - the route virtual host settings used by any calls to\n          [`server.route()`](#server.route()) from the server.\n\n- `parent` - the realm of the parent server object, or `null` for the root server.\n\n- `plugin` - the active plugin name (empty string if at the server root).\n\n- `pluginOptions` - the plugin options passed at registration.\n\n- `plugins` - plugin-specific state to be shared only among activities sharing the same active\n  state. `plugins` is an object where each key is a plugin name and the value is the plugin state.\n\n- `settings` - settings overrides:\n\n    - `files.relativeTo`\n    - `bind`\n\nThe `server.realm` object should be considered read-only and must not be changed directly except\nfor the `plugins` property which can be directly manipulated by each plugin, setting its properties\ninside `plugins[name]`.\n\n```js\nexports.register = function (server, options) {\n\n    console.log(server.realm.modifiers.route.prefix);\n};\n```\n\n#### <a name=\"server.registrations\" /> `server.registrations`\n\nAccess: read only.\n\nAn object of the currently registered plugins where each key is a registered plugin name and the\nvalue is an object containing:\n\n- `version` - the plugin version.\n- `name` - the plugin name.\n- `options` - (optional) options passed to the plugin during registration.\n\n#### <a name=\"server.settings\" /> `server.settings`\n\nAccess: read only.\n\nThe server configuration object after defaults applied.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({\n    app: {\n        key: 'value'\n    }\n});\n\nconsole.log(server.settings.app);   // { key: 'value' }\n```\n\n#### <a name=\"server.states\" /> `server.states`\n\nAccess: read only and **statehood** public interface.\n\nThe server cookies manager.\n\n#### <a name=\"server.states.settings\" /> `server.states.settings`\n\nAccess: read only.\n\nThe server cookies manager settings. The settings are based on the values configured in\n[`server.options.state`](#server.options.state).\n\n#### <a name=\"server.states.cookies\" /> `server.states.cookies`\n\nAccess: read only.\n\nAn object containing the configuration of each cookie added via [`server.state()`](#server.state())\nwhere each key is the cookie name and value is the configuration object.\n\n#### <a name=\"server.states.names\" /> `server.states.names`\n\nAccess: read only.\n\nAn array containing the names of all configured cookies.\n\n#### <a name=\"server.type\" /> `server.type`\n\nAccess: read only.\n\nA string indicating the listener type where:\n- `'socket'` - UNIX domain socket or Windows named pipe.\n- `'tcp'` - an HTTP listener.\n\n#### <a name=\"server.version\" /> `server.version`\n\nAccess: read only.\n\nThe **hapi** module version number.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server();\n\nconsole.log(server.version);        // '17.0.0'\n```\n\n### <a name=\"server.auth.default()\" /> `server.auth.default(options)`\n\nSets a default strategy which is applied to every route where:\n\n- `options` - one of:\n\n    - a string with the default strategy name\n    - an authentication configuration object using the same format as the\n      [route `auth` handler options](#route.options.auth).\n\nReturn value: none.\n\nThe default does not apply when a route config specifies `auth` as `false`, or has an\nauthentication strategy configured (contains the [`strategy`](#route.options.auth.strategy) or\n[`strategies`](#route.options.auth.strategies) authentication settings). Otherwise, the route\nauthentication config is applied to the defaults.\n\nNote that if the route has authentication configured, the default only applies at the time of\nadding the route, not at runtime. This means that calling `server.auth.default()` after adding a\nroute with some authentication config will have no impact on the routes added prior. However, the\ndefault will apply to routes added before `server.auth.default()` is called if those routes lack\nany authentication config.\n\nThe default auth strategy configuration can be accessed via [`server.auth.settings.default`](#server.auth.settings.default).\nTo obtain the active authentication configuration of a route, use `server.auth.lookup(request.route)`.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({ port: 80 });\n\nserver.auth.scheme('custom', scheme);\nserver.auth.strategy('default', 'custom');\nserver.auth.default('default');\n\nserver.route({\n    method: 'GET',\n    path: '/',\n    handler: function (request, h) {\n\n        return request.auth.credentials.user;\n    }\n});\n```\n\n### <a name=\"server.auth.scheme()\" /> `server.auth.scheme(name, scheme)`\n\nRegisters an authentication scheme where:\n\n- `name` - the scheme name.\n- `scheme` - the method implementing the scheme with signature `function(server, options)` where:\n    - `server` - a reference to the server object the scheme is added to. Each auth strategy is given its own [`server.realm`](#server.realm) whose parent is the realm of the `server` in the call to [`server.auth.strategy()`](#server.auth.strategy()).\n    - `options` - (optional) the scheme `options` argument passed to\n      [`server.auth.strategy()`](#server.auth.strategy()) when instantiation a strategy.\n\nReturn value: none.\n\nThe `scheme` function must return an [authentication scheme object](#authentication-scheme) when\ninvoked.\n\n#### Authentication scheme\n\nAn authentication scheme is an object with the following properties:\n\n- `api` - (optional) object which is exposed via the [`server.auth.api`](#server.auth.api) object.\n\n- `async authenticate(request, h)` - (required) a [lifecycle method](#lifecycle-methods) function\n  called for each incoming request configured with the authentication scheme. The method is\n  provided with two special toolkit methods for returning an authenticated or an unauthenticate\n  result:\n    - [`h.authenticated()`](#h.authenticated()) - indicate request authenticated successfully.\n    - [`h.unauthenticated()`](#h.unauthenticated()) - indicate request failed to authenticate.\n\n- `async payload(request, h)` - (optional) a [lifecycle method](#lifecycle-methods) to authenticate\n  the request payload.\n\n- `async response(request, h)` - (optional) a [lifecycle method](#lifecycle-methods) to decorate\n  the response with authentication headers before the response headers or payload is written.\n\n- `async verify(auth)` - (optional) a method used to verify the authentication credentials provided\n  are still valid (e.g. not expired or revoked after the initial authentication) where:\n  - `auth` - the [`request.auth`](#request.auth) object containing the `credentials` and\n    `artifacts` objects returned by the scheme's `authenticate()` method.\n  - the method throws an `Error` when the credentials passed are no longer valid (e.g. expired or\n  revoked). Note that the method does not have access to the original request, only to the\n  credentials and artifacts produced by the `authenticate()` method.\n\n- `options` - (optional) an object with the following keys:\n    - `payload` - if `true`, requires payload validation as part of the scheme and forbids routes\n      from disabling payload auth validation. Defaults to `false`.\n\nWhen the scheme `authenticate()` method implementation throws an error or calls\n[`h.unauthenticated()`](#h.unauthenticated()), the specifics of the error affect whether additional\nauthentication strategies will be attempted (if configured for the route). If the error includes a\nmessage, no additional strategies will be attempted. If the `err` does not include a message but\ndoes include the scheme name (e.g. `Boom.unauthorized(null, 'Custom')`), additional strategies will\nbe attempted in the order of preference (defined in the route configuration). If authentication\nfails, the scheme names will be present in the 'WWW-Authenticate' header.\n\nWhen the scheme `payload()` method throws an error with a message, it means payload validation\nfailed due to bad payload. If the error has no message but includes a scheme name (e.g.\n`Boom.unauthorized(null, 'Custom')`), authentication may still be successful if the route\n[`auth.payload`](#route.options.auth.payload) configuration is set to `'optional'`.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({ port: 80 });\n\nconst scheme = function (server, options) {\n\n    return {\n        authenticate: function (request, h) {\n\n            const req = request.raw.req;\n            const authorization = req.headers.authorization;\n            if (!authorization) {\n                throw Boom.unauthorized(null, 'Custom');\n            }\n\n            return h.authenticated({ credentials: { user: 'john' } });\n        }\n    };\n};\n\nserver.auth.scheme('custom', scheme);\n```\n\n### <a name=\"server.auth.strategy()\" /> `server.auth.strategy(name, scheme, [options])`\n\nRegisters an authentication strategy where:\n\n- `name` - the strategy name.\n- `scheme` - the scheme name (must be previously registered using\n  [`server.auth.scheme()`](#server.auth.scheme())).\n- `options` - scheme options based on the scheme requirements.\n\nReturn value: none.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({ port: 80 });\n\nserver.auth.scheme('custom', scheme);\nserver.auth.strategy('default', 'custom');\n\nserver.route({\n    method: 'GET',\n    path: '/',\n    options: {\n        auth: 'default',\n        handler: function (request, h) {\n\n            return request.auth.credentials.user;\n        }\n    }\n});\n```\n\n### <a name=\"server.auth.test()\" /> `await server.auth.test(strategy, request)`\n\nTests a request against an authentication strategy where:\n\n- `strategy` - the strategy name registered with [`server.auth.strategy()`](#server.auth.strategy()).\n- `request` - the [request object](#request).\n\nReturn value: an object containing the authentication `credentials` and `artifacts` if authentication\nwas successful, otherwise throws an error.\n\nNote that the `test()` method does not take into account the route authentication configuration. It\nalso does not perform payload authentication. It is limited to the basic strategy authentication\nexecution. It does not include verifying scope, entity, or other route properties.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({ port: 80 });\n\nserver.auth.scheme('custom', scheme);\nserver.auth.strategy('default', 'custom');\n\nserver.route({\n    method: 'GET',\n    path: '/',\n    handler: async function (request, h) {\n\n        try {\n            const { credentials, artifacts } = await request.server.auth.test('default', request);\n            return { status: true, user: credentials.name };\n        }\n        catch (err) {\n            return { status: false };\n        }\n    }\n});\n```\n\n\n### <a name=\"server.auth.verify()\" /> `await server.auth.verify(request)`\n\nVerify a request's authentication credentials against an authentication strategy where:\n\n- `request` - the [request object](#request).\n\nReturn value: nothing if verification was successful, otherwise throws an error.\n\nNote that the `verify()` method does not take into account the route authentication configuration\nor any other information from the request other than the `request.auth` object. It also does not\nperform payload authentication. It is limited to verifying that the previously valid credentials\nare still valid (e.g. have not been revoked or expired). It does not include verifying scope,\nentity, or other route properties.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({ port: 80 });\n\nserver.auth.scheme('custom', scheme);\nserver.auth.strategy('default', 'custom');\n\nserver.route({\n    method: 'GET',\n    path: '/',\n    handler: async function (request, h) {\n\n        try {\n            const credentials = await request.server.auth.verify(request);\n            return { status: true, user: credentials.name };\n        }\n        catch (err) {\n            return { status: false };\n        }\n    }\n});\n```\n\n### <a name=\"server.bind()\" /> `server.bind(context)`\n\nSets a global context used as the default bind object when adding a route or an extension where:\n\n- `context` - the object used to bind `this` in [lifecycle methods](#lifecycle-methods) such as\n  the [route handler](#route.options.handler) and [extension methods](#server.ext()). The context\n  is also made available as [`h.context`](#h.context).\n\nReturn value: none.\n\nWhen setting a context inside a plugin, the context is applied only to methods set up by the\nplugin. Note that the context applies only to routes and extensions added after it has been set.\nIgnored if the method being bound is an arrow function.\n\n```js\nconst handler = function (request, h) {\n\n    return this.message;    // Or h.context.message\n};\n\nexports.plugin = {\n    name: 'example',\n    register: function (server, options) {\n\n        const bind = {\n            message: 'hello'\n        };\n\n        server.bind(bind);\n        server.route({ method: 'GET', path: '/', handler });\n    }\n};\n```\n\n### <a name=\"server.cache()\" /> `server.cache(options)`\n\nProvisions a cache segment within the server cache facility where:\n\n- `options` - [**catbox** policy](https://hapi.dev/family/catbox/api#policy) configuration where:\n\n    - `expiresIn` - relative expiration expressed in the number of milliseconds since the item was\n      saved in the cache. Cannot be used together with `expiresAt`.\n\n    - `expiresAt` - time of day expressed in 24h notation using the 'HH:MM' format, at which point\n      all cache records expire. Uses local time. Cannot be used together with `expiresIn`.\n\n    - `generateFunc` - a function used to generate a new cache item if one is not found in the\n      cache when calling `get()`. The method's signature is `async function(id, flags)` where:\n\n          - `id` - the `id` string or object provided to the `get()` method.\n          - `flags` - an object used to pass back additional flags to the cache where:\n              - `ttl` - the cache ttl value in milliseconds. Set to `0` to skip storing in the\n                cache. Defaults to the cache global policy.\n\n    - `staleIn` - number of milliseconds to mark an item stored in cache as stale and attempt to\n      regenerate it when `generateFunc` is provided. Must be less than `expiresIn`.\n\n    - `staleTimeout` - number of milliseconds to wait before checking if an item is stale.\n\n    - `generateTimeout` - number of milliseconds to wait before returning a timeout error when the\n      `generateFunc` function takes too long to return a value. When the value is eventually\n      returned, it is stored in the cache for future requests. Required if `generateFunc` is\n      present. Set to `false` to disable timeouts which may cause all `get()` requests to get stuck\n      forever.\n\n    - `generateOnReadError` - if `false`, an upstream cache read error will stop the `cache.get()`\n      method from calling the generate function and will instead pass back the cache error. Defaults\n      to `true`.\n\n    - `generateIgnoreWriteError` - if `false`, an upstream cache write error when calling\n      `cache.get()` will be passed back with the generated value when calling. Defaults to `true`.\n\n    - `dropOnError` - if `true`, an error or timeout in the `generateFunc` causes the stale value\n      to be evicted from the cache.  Defaults  to `true`.\n\n    - `pendingGenerateTimeout` - number of milliseconds while `generateFunc` call is in progress\n      for a given id, before a subsequent `generateFunc` call is allowed. Defaults to `0` (no\n      blocking of concurrent `generateFunc` calls beyond `staleTimeout`).\n\n    - `cache` - the cache name configured in [`server.cache`](#server.options.cache). Defaults to\n      the default cache.\n\n    - `segment` - string segment name, used to isolate cached items within the cache partition.\n      When called within a plugin, defaults to '!name' where 'name' is the plugin name. When called\n      within a server method, defaults to '#name' where 'name' is the server method name. Required\n      when called outside of a plugin.\n\n    - `shared` - if `true`, allows multiple cache provisions to share the same segment. Default to\n      `false`.\n\nReturn value: a [**catbox** policy](https://hapi.dev/family/catbox/api#policy) object.\n\n```js\nconst Hapi = require('@hapi/hapi');\n\nasync function example() {\n\n    const server = Hapi.server({ port: 80 });\n    const cache = server.cache({ segment: 'countries', expiresIn: 60 * 60 * 1000 });\n    await cache.set('norway', { capital: 'oslo' });\n    const value = await cache.get('norway');\n}\n```\n\n### <a name=\"server.cache.provision()\" /> `await server.cache.provision(options)`\n\nProvisions a server cache as described in [`server.cache`](#server.options.cache"},"items":[{"name":"API.md","path":"API.md","rawUrl":"https://raw.githubusercontent.com/hapijs/hapi/HEAD/API.md","title":"API Interface Contract & Specifications","category":"project-spec","format":"markdown","content":"\n## Server\n\nThe server object is the main application container. The server manages all incoming requests\nalong with all the facilities provided by the framework. Each server supports a single connection\n(e.g. listen to port `80`).\n\n### <a name=\"server()\" /> `server([options])`\n\nCreates a new server object where:\n- `options` - (optional) a [server configuration object](#server.options).\n\n```js\nconst Hapi = require('@hapi/hapi');\n\nconst server = Hapi.server({ load: { sampleInterval: 1000 } });\n```\n\n### <a name=\"server.options\" /> Server options\n\nThe server options control the behavior of the server object. Note that the options object is\ndeeply cloned (with the exception of [`listener`](#server.options.listener) which is shallowly\ncopied) and should not contain any values that are unsafe to perform deep copy on.\n\nAll options are optionals.\n\n#### <a name=\"server.options.address\" /> `server.options.address`\n\nDefault value: `'::'` if IPv6 is available, otherwise `'0.0.0.0'` (i.e. all available network interfaces).\n\nSets the hostname or IP address the server will listen on. If not configured, defaults to\n[`host`](#server.options.host) if present, otherwise to all available network interfaces. Set to\n`'127.0.0.1'`, `'::1'`, or `'localhost'` to restrict the server to only those coming from the same host.\n\n#### <a name=\"server.options.app\" /> `server.options.app`\n\nDefault value: `{}`.\n\nProvides application-specific configuration which can later be accessed via\n[`server.settings.app`](#server.settings). The framework does not interact with this object. It is\nsimply a reference made available anywhere a `server` reference is provided.\n\nNote the difference between `server.settings.app` which is used to store static configuration\nvalues and [`server.app`](#server.app) which is meant for storing run-time state.\n\n#### <a name=\"server.options.autolisten\" /> `server.options.autoListen`\n\nDefault value: `true`.\n\nUsed to disable the automatic initialization of the [`listener`](#server.options.listener). When\n`false`, indicates that the [`listener`](#server.options.listener) will be started manually outside\nthe framework.\n\nCannot be set to `false` along with a [`port`](#server.options.port) value.\n\n#### <a name=\"server.options.cache\" /> `server.options.cache`\n\nDefault value: `{ provider: { constructor: require('@hapi/catbox-memory'), options: { partition: 'hapi-cache' } } }`.\n\nSets up server-side caching providers. Every server includes a default cache for storing\napplication state. By default, a simple memory-based cache is created which has limited capacity\nand capabilities.\n\n**hapi** uses [**catbox**](https://hapi.dev/family/catbox/api) for its cache implementation which\nincludes support for common storage solutions (e.g. Redis, MongoDB, Memcached, Riak, among others).\nCaching is only utilized if [methods](#server.methods) and [plugins](#plugins) explicitly store\ntheir state in the cache.\n\nThe server cache configuration only defines the storage container itself. The configuration can be\nassigned one or more (array):\n\n- a class or prototype function (usually obtained by calling `require()` on a **catbox** strategy\n    such as `require('@hapi/catbox-redis')`). A new **catbox** [client](https://hapi.dev/family/catbox/api#client)\n    will be created internally using this constructor.\n\n- a configuration object with the following:\n\n    - `engine` - a **catbox** engine object instance.\n\n    - `name` - an identifier used later when provisioning or configuring caching for\n        [server methods](#server.methods) or [plugins](#plugins). Each cache name must be unique.\n        A single item may omit the `name` option which defines the default cache. If every cache\n        includes a `name`, a default memory cache is provisioned as well.\n\n    - `provider` - a class, a constructor function, or an object with the following:\n\n        - `constructor` - a class or a prototype function.\n\n        - `options` - (optional) a settings object passed as-is to the `constructor` with the following:\n\n            - `partition` - (optional) string used to isolate cached data. Defaults to `'hapi-cache'`.\n            - other constructor-specific options passed to the `constructor` on instantiation.\n\n    - `shared` - if `true`, allows multiple cache users to share the same segment (e.g.\n        multiple methods using the same cache storage container). Default to `false`.\n\n    - One (and only one) of `engine` or `provider` is required per configuration object.\n\n#### <a name=\"server.options.compression\" /> `server.options.compression`\n\nDefault value: `{ minBytes: 1024 }`.\n\nDefines server handling of content encoding requests. If `false`, response content encoding is\ndisabled and no compression is performed by the server.\n\n##### <a name=\"server.options.compression.minBytes\" /> `server.options.compression.minBytes`\n\nDefault value: '1024'.\n\nSets the minimum response payload size in bytes that is required for content encoding compression.\nIf the payload size is under the limit, no compression is performed.\n\n#### <a name=\"server.options.debug\" /> `server.options.debug`\n\nDefault value: `{ request: ['implementation'] }`.\n\nDetermines which logged events are sent to the console. This should only be used for development\nand does not affect which events are actually logged internally and recorded. Set to `false` to\ndisable all console logging, or to an object with:\n\n- `log` - a string array of server log tags to be displayed via `console.error()` when\n    the events are logged via [`server.log()`](#server.log()) as well as\n    internally generated [server logs](#server-logs). Defaults to no output.\n\n- `request` - a string array of request log tags to be displayed via `console.error()` when\n    the events are logged via [`request.log()`](#request.log()) as well as\n    internally generated [request logs](#request-logs). For example, to display all errors,\n    set the option to `['error']`. To turn off all console debug messages set it to `false`.\n    To display all request logs, set it to `'*'`.\n    Defaults to uncaught errors thrown in external code (these errors are handled\n    automatically and result in an Internal Server Error response) or runtime errors due to\n    developer error.\n\nFor example, to display all errors, set the `log` or `request` to `['error']`. To turn off all\noutput set the `log` or `request` to `false`. To display all server logs, set the `log` or\n`request` to `'*'`. To disable all debug information, set `debug` to `false`.\n\n#### <a name=\"server.options.host\" /> `server.options.host`\n\nDefault value: the operating system hostname and if not available, to `'localhost'`.\n\nThe public hostname or IP address. Used to set [`server.info.host`](#server.info) and\n[`server.info.uri`](#server.info) and as [`address`](#server.options.address) if none is provided.\n\n#### <a name=\"server.options.info.remote\" /> `server.options.info.remote`\n\nDefault value: `false`.\n\nIf `true`, the `request.info.remoteAddress` and `request.info.remotePort` are populated when the request is received which can consume more resource (but is ok if the information is needed, especially for aborted requests). When `false`, the fields are only populated upon demand (but will be `undefined` if accessed after the request is aborted).\n\n#### <a name=\"server.options.listener\" /> `server.options.listener`\n\nDefault value: none.\n\nAn optional node HTTP (or HTTPS) [`http.Server`](https://nodejs.org/api/http.html#http_class_http_server)\nobject (or an object with a compatible interface).\n\nIf the `listener` needs to be manually started, set [`autoListen`](#server.options.autolisten) to\n`false`.\n\nIf the `listener` uses TLS, set [`tls`](#server.options.tls) to `true`.\n\n#### <a name=\"server.options.load\" /> `server.options.load`\n\nDefault value: `{ sampleInterval: 0, maxHeapUsedBytes: 0, maxRssBytes: 0, maxEventLoopDelay: 0, maxEventLoopUtilization: 0 }`.\n\nServer excessive load handling limits where:\n\n- `sampleInterval` - the frequency of sampling in milliseconds. When set to `0`, the other load options are ignored. Defaults to `0` (no sampling).\n\n- `maxHeapUsedBytes` - maximum V8 heap size over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to `0` (no limit).\n\n- `maxRssBytes` - maximum process RSS size over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to `0` (no limit).\n\n- `maxEventLoopDelay` - maximum event loop delay duration in milliseconds over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to `0` (no limit).\n\n- `maxEventLoopUtilization` - maximum event loop utilization value over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to `0` (no limit).\n\n#### <a name=\"server.options.mime\" /> `server.options.mime`\n\nDefault value: none.\n\nOptions passed to the [**mimos**](https://hapi.dev/family/mimos/api) module when generating the mime database used by the server (and accessed via [`server.mime`](#server.mime)):\n\n- `override` - an object hash that is merged into the built in mime information specified [here](https://github.com/jshttp/mime-db). Each key value pair represents a single mime object. Each override value must contain:\n\n    - `key` - the lower-cased mime-type string (e.g. `'application/javascript'`).\n\n    - `value` - an object following the specifications outlined [here](https://github.com/jshttp/mime-db#data-structure). Additional values include:\n\n        - `type` - specify the `type` value of result objects, defaults to `key`.\n\n        - `predicate` - method with signature `function(mime)` when this mime type is found in the database, this function will execute to allows customizations.\n\n```js\nconst options = {\n    mime: {\n        override: {\n            'node/module': {\n                source: 'iana',\n                compressible: true,\n                extensions: ['node', 'module', 'npm'],\n                type: 'node/module'\n            },\n            'application/javascript': {\n                source: 'iana',\n                charset: 'UTF-8',\n                compressible: true,\n                extensions: ['js', 'javascript'],\n                type: 'text/javascript'\n            },\n            'text/html': {\n                predicate: function(mime) {\n                    if (someCondition) {\n                        mime.foo = 'test';\n                    }\n                    else {\n                        mime.foo = 'bar';\n                    }\n                    return mime;\n                }\n            }\n        }\n    }\n};\n```\n\n#### <a name=\"server.options.operations\" /> `server.options.operations`\n\nDefault value: `{ cleanStop: true }`.\n\nDefines server handling of server operations:\n\n- `cleanStop` - if `true`, the server keeps track of open connections and properly closes them\n  when the server is stopped. Under normal load, this should not interfere with server performance.\n  However, under severe load connection monitoring can consume additional resources and aggravate\n  the situation. If the server is never stopped, or if it is forced to stop without waiting for\n  open connection to close, setting this to `false` can save resources that are not being utilized\n  anyway. Defaults to `true`.\n\n#### <a name=\"server.options.plugins\" /> `server.options.plugins`\n\nDefault value: `{}`.\n\nPlugin-specific configuration which can later be accessed via [`server.settings.plugins`](#server.settings).\n`plugins` is an object where each key is a plugin name and the value is the configuration.\nNote the difference between [`server.settings.plugins`](#server.settings) which is used to store\nstatic configuration values and [`server.plugins`](#server.plugins) which is meant for storing\nrun-time state.\n\n#### <a name=\"server.options.port\" /> `server.options.port`\n\nDefault value: `0` (an ephemeral port).\n\nThe TCP port the server will listen to. Defaults the next available port when the server is started\n(and assigned to [`server.info.port`](#server.info)).\n\nIf `port` is a string containing a '/' character, it is used as a UNIX domain socket path.\nIf it starts with '\\\\.\\pipe', it is used as a Windows named pipe.\n\n#### <a name=\"server.options.query\" /> `server.options.query`\n\nDefault value: `{}`.\n\nDefines server handling of the request path query component.\n\n##### <a name=\"server.options.query.parser\" /> `server.options.query.parser`\n\nDefault value: none.\n\nSets a query parameters parser method using the signature `function(query)` where:\n\n- `query` - an object containing the incoming [`request.query`](#request.query) parameters.\n- the method must return an object where each key is a parameter and matching value is the\n  parameter value. If the method throws, the error is used as the response or returned when\n  [`request.setUrl()`](#request.setUrl()) is called.\n\n```js\nconst Qs = require('qs');\n\nconst options = {\n    query: {\n        parser: (query) => Qs.parse(query)\n    }\n};\n```\n\n#### <a name=\"server.options.router\" /> `server.options.router`\n\nDefault value: `{ isCaseSensitive: true, stripTrailingSlash: false }`.\n\nControls how incoming request URIs are matched against the routing table:\n\n- `isCaseSensitive` - determines whether the paths '/example' and '/EXAMPLE' are considered\n  different resources. Defaults to `true`.\n\n- `stripTrailingSlash` - removes trailing slashes on incoming paths. Defaults to `false`.\n\n#### <a name=\"server.options.routes\" /> `server.options.routes`\n\nDefault value: none.\n\nA [route options](#route-options) object used as the default configuration for every route.\n\n#### <a name=\"server.options.state\" /> `server.options.state`\n\nDefault value:\n```js\n{\n    strictHeader: true,\n    ignoreErrors: false,\n    isSecure: true,\n    isHttpOnly: true,\n    isSameSite: 'Strict',\n    isPartitioned: false,\n    encoding: 'none'\n}\n```\n\nSets the default configuration for every state (cookie) set explicitly via\n[`server.state()`](#server.state()) or implicitly (without definition) using the\n[state configuration](#server.state()) object.\n\n#### <a name=\"server.options.tls\" /> `server.options.tls`\n\nDefault value: none.\n\nUsed to create an HTTPS connection. The `tls` object is passed unchanged to the node\nHTTPS server as described in the [node HTTPS documentation](https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener).\n\nSet to `true` when passing a [`listener`](#server.options.listener) object that has been configured\nto use TLS directly.\n\n#### <a name=\"server.options.uri\" /> `server.options.uri`\n\nDefault value: constructed from runtime server information.\n\nThe full public URI without the path (e.g. 'http://example.com:8080'). If present, used as the\nserver [`server.info.uri`](#server.info), otherwise constructed from the server settings.\n\n### Server properties\n\n#### <a name=\"server.app\" /> `server.app`\n\nAccess: read / write.\n\nProvides a safe place to store server-specific run-time application data without potential\nconflicts with the framework internals. The data can be accessed whenever the server is\naccessible. Initialized with an empty object.\n\n```js\nconst server = Hapi.server();\n\nserver.app.key = 'value';\n\nconst handler = function (request, h) {\n\n    return request.server.app.key;        // 'value'\n};\n```\n\n#### <a name=\"server.auth.api\" /> `server.auth.api`\n\nAccess: authentication strategy specific.\n\nAn object where each key is an authentication strategy name and the value is the exposed strategy\nAPI. Available only when the authentication scheme exposes an API by returning an `api` key in the\nobject returned from its implementation function.\n\n```js\nconst server = Hapi.server({ port: 80 });\n\nconst scheme = function (server, options) {\n\n    return {\n        api: {\n            settings: {\n                x: 5\n            }\n        },\n        authenticate: function (request, h) {\n\n            const authorization = request.headers.authorization;\n            if (!authorization) {\n                throw Boom.unauthorized(null, 'Custom');\n            }\n\n            return h.authenticated({ credentials: { user: 'john' } });\n        }\n    };\n};\n\nserver.auth.scheme('custom', scheme);\nserver.auth.strategy('default', 'custom');\n\nconsole.log(server.auth.api.default.settings.x);    // 5\n```\n\n#### <a name=\"server.auth.settings.default\" /> `server.auth.settings.default`\n\nAccess: read only.\n\nContains the default authentication configuration if a default strategy was set via\n[`server.auth.default()`](#server.auth.default()).\n\n#### <a name=\"server.decorations\" /> `server.decorations`\n\nAccess: read only.\n\nProvides access to the decorations already applied to various framework interfaces. The object must\nnot be modified directly, but only through [`server.decorate`](#server.decorate()).\nContains:\n\n- `request` - decorations on the [request object](#request).\n- `response` - decorations on the [response object](#response-object).\n- `toolkit` - decorations on the [response toolkit](#response-toolkit).\n- `server` - decorations on the [server](#server) object.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({ port: 80 });\n\nconst success = function () {\n\n    return this.response({ status: 'ok' });\n};\n\nserver.decorate('toolkit', 'success', success);\nconsole.log(server.decorations.toolkit);            // ['success']\n```\n\n#### <a name=\"server.events\" /> `server.events`\n\nAccess: **podium** public interface.\n\nThe server events emitter. Utilizes the [**podium**](https://hapi.dev/family/podium/api) with support\nfor event criteria validation, channels, and filters.\n\nUse the following methods to interact with `server.events`:\n\n- [`server.event(events)`](#server.event()) - register application events.\n- [`server.events.emit(criteria, data)`](#server.events.emit()) - emit server events.\n- [`server.events.on(criteria, listener, context)`](#server.events.on()) - subscribe to all events.\n- [`server.events.once(criteria, listener, context)`](#server.events.once()) - subscribe to a single event.\n\nOther methods include: `server.events.removeListener(name, listener)`,\n`server.events.removeAllListeners(name)`, and `server.events.hasListeners(name)`.\n\n##### <a name=\"server.events.log\" /> `'log'` Event\n\nThe `'log'` event type emits internal server events generated by the framework as well as\napplication events logged with [`server.log()`](#server.log()).\n\nThe `'log'` event handler uses the function signature `function(event, tags)` where:\n\n- `event` - an object with the following properties:\n    - `timestamp` - the event timestamp.\n    - `tags` - an array of tags identifying the event (e.g. `['error', 'http']`).\n    - `channel` - set to `'internal'` for internally generated events, otherwise `'app'` for events\n      generated by [`server.log()`](#server.log()).\n    - `data` - event-specific information. Available when event data was provided and is not an\n      error. Errors are passed via `error`.\n    - `error` - the error object related to the event if applicable. Cannot appear together with\n      `data`.\n\n- `tags` - an object where each `event.tag` is a key and the value is `true`. Useful for quick\n  identification of events.\n\n```js\nserver.events.on('log', (event, tags) => {\n\n    if (tags.error) {\n        console.log(`Server error: ${event.error ? event.error.message : 'unknown'}`);\n    }\n});\n```\n\nThe internally generated events are (identified by their `tags`):\n\n- `load` - logs the current server load measurements when the server rejects a request due to\n  [high load](#server.options.load). The event data contains the process load metrics.\n\n- `connection` `client` `error` - a `clientError` event was received from the HTTP or HTTPS\n  listener. The event data is the error object received.\n\n##### <a name=\"server.events.cachePolicy\" /> `'cachePolicy'` Event\n\nThe `'cachePolicy'` event type is emitted when a server [cache policy](https://hapi.dev/module/catbox/api#policy)\nis created via [`server.cache()`](#server.cache()) or a [`server.method()`](#server.method()) with caching enabled is registered.\nThe `'cachePolicy'` event handler uses the function signature `function(cachePolicy, cache, segment)` where:\n\n- `cachePolicy` - the catbox [cache policy](https://hapi.dev/module/catbox/api#policy).\n- `cache` - the [cache provision](#server.options.cache) name used when the policy was created or `undefined` if the default cache was used.\n- `segment` - the segment name used when the policy was created.\n\n```js\nserver.events.on('cachePolicy', (cachePolicy, cache, segment) => {\n\n    console.log(`New cache policy created using cache: ${cache === undefined ? 'default' : cache} and segment: ${segment}`);\n});\n```\n\n##### <a name=\"server.events.request\" /> `'request'` Event\n\nThe `'request'` event type emits internal request events generated by the framework as well as\napplication events logged with [`request.log()`](#request.log()).\n\nThe `'request'` event handler uses the function signature `function(request, event, tags)` where:\n\n- `request` - the [request object](#request).\n\n- `event` - an object with the following properties:\n    - `timestamp` - the event timestamp.\n    - `tags` - an array of tags identifying the event (e.g. `['error', 'http']`).\n    - `channel` - one of\n        - `'app'` - events generated by [`request.log()`](#request.log()).\n        - `'error'` - emitted once per request if the response had a `500` status code.\n        - `'internal'` - internally generated events.\n    - `request` - the request [identifier](#request.info.id).\n    - `data` - event-specific information. Available when event data was provided and is not an\n      error. Errors are passed via `error`.\n    - `error` - the error object related to the event if applicable. Cannot appear together with\n      `data`.\n\n- `tags` - an object where each `event.tag` is a key and the value is `true`. Useful for quick\n  identification of events.\n\n```js\nserver.events.on('request', (request, event, tags) => {\n\n    if (tags.error) {\n        console.log(`Request ${event.request} error: ${event.error ? event.error.message : 'unknown'}`);\n    }\n});\n```\n\nTo listen to only one of the channels, use the event criteria object:\n\n```js\nserver.events.on({ name: 'request', channels: 'error' }, (request, event, tags) => {\n\n    console.log(`Request ${event.request} failed`);\n});\n```\n\nThe internally generated events are (identified by their `tags`):\n\n- `accept-encoding` `error` - a request received contains an invalid Accept-Encoding header.\n- `auth` `unauthenticated` - no authentication scheme included with the request.\n- `auth` `unauthenticated` `response` `{strategy}` - the authentication strategy listed returned a non-error response (e.g. a redirect to a login page).\n- `auth` `unauthenticated` `error` `{strategy}` - the request failed to pass the listed authentication strategy (invalid credentials).\n- `auth` `unauthenticated` `missing` `{strategy}` - the request failed to pass the listed authentication strategy (no credentials found).\n- `auth` `unauthenticated` `try` `{strategy}` - the request failed to pass the listed authentication strategy in `'try'` mode and will continue.\n- `auth` `scope` `error` - the request authenticated but failed to meet the scope requirements.\n- `auth` `entity` `user` `error` - the request authenticated but included an application entity when a user entity was required.\n- `auth` `entity` `app` `error` - the request authenticated but included a user entity when an application entity was required.\n- `ext` `error` - an `onPostResponse` extension handler errored.\n- `handler` `error` - the route handler returned an error. Includes the execution duration and the error message.\n- `pre` `error` - a pre method was executed and returned an error. Includes the execution duration, assignment key, and error.\n- `internal` `error` - an HTTP 500 error response was assigned to the request.\n- `internal` `implementation` `error` - an incorrectly implemented [lifecycle method](#lifecycle-methods).\n- `request` `error` `abort` - the request aborted.\n- `request` `error` `close` - the request closed prematurely.\n- `request` `error` - the request stream emitted an error. Includes the error.\n- `request` `server` `timeout` `error` - the request took too long to process by the server. Includes the timeout configuration value and the duration.\n- `state` `error` - the request included an invalid cookie or cookies. Includes the cookies and error details.\n- `state` `response` `error` - the response included an invalid cookie which prevented generating a valid header. Includes the error.\n- `payload` `error` - failed processing the request payload. Includes the error.\n- `response` `error` - failed writing the response to the client. Includes the error.\n- `response` `error` `close` - failed writing the response to the client due to prematurely closed connection.\n- `response` `error` `aborted` - failed writing the response to the client due to prematurely aborted connection.\n- `response` `error` `cleanup` - failed freeing response resources.\n- `validation` `error` `{input}` - input (i.e. payload, query, params, headers) validation failed. Includes the error. Only emitted when `failAction` is set to `'log'`.\n- `validation` `response` `error` - response validation failed. Includes the error message. Only emitted when `failAction` is set to `'log'`.\n\n##### <a name=\"server.events.response\" /> `'response'` Event\n\nThe `'response'` event type is emitted after the response is sent back to the client (or when the\nclient connection closed and no response sent, in which case [`request.response`](#request.response)\nis `null`). A single event is emitted per request. The `'response'` event handler uses the function\nsignature `function(request)` where:\n\n- `request` - the [request object](#request).\n\n```js\nserver.events.on('response', (request) => {\n\n    console.log(`Response sent for request: ${request.info.id}`);\n});\n```\n\n##### <a name=\"server.events.route\" /> `'route'` Event\n\nThe `'route'` event type is emitted when a route is added via [`server.route()`](#server.route()).\nThe `'route'` event handler uses the function signature `function(route)` where:\n\n- `route` - the [route information](#request.route). The `route` object must not be modified.\n\n```js\nserver.events.on('route', (route) => {\n\n    console.log(`New route added: ${route.path}`);\n});\n```\n\n##### <a name=\"server.events.start\" /> `'start'` Event\n\nThe `'start'` event type is emitted when the server is started using [`server.start()`](#server.start()).\nThe `'start'` event handler uses the function signature `function()`.\n\n```js\nserver.events.on('start', () => {\n\n    console.log('Server started');\n});\n```\n\n##### <a name=\"server.events.closing\" /> `'closing'` Event\n\nThe `'closing'` event type is emitted when the server is stopped using [`server.stop()`](#server.stop()). It is triggered when incoming requests are no longer accepted but before all underlying active connections have been closed, and thus before the [`'stop'`](#server.events.stop) event is triggered.\nThe `'closing'` event handler uses the function signature `function()`.\n\n```js\nserver.events.on('closing', () => {\n\n    console.log('Server is closing');\n});\n```\n\n##### <a name=\"server.events.stop\" /> `'stop'` Event\n\nThe `'stop'` event type is emitted when the server is stopped using [`server.stop()`](#server.stop()).\nThe `'stop'` event handler uses the function signature `function()`.\n\n```js\nserver.events.on('stop', () => {\n\n    console.log('Server stopped');\n});\n```\n\n#### <a name=\"server.info\" /> `server.info`\n\nAccess: read only.\n\nAn object containing information about the server where:\n\n- `id` - a unique server identifier (using the format '{hostname}:{pid}:{now base36}').\n\n- `created` - server creation timestamp.\n\n- `started` - server start timestamp (`0` when stopped).\n\n- `port` - the connection port based on the following rules:\n\n    - before the server has been started: the configured [`port`](#server.options.port) value.\n    - after the server has been started: the actual port assigned when no port is configured or was\n      set to `0`.\n\n- `host` - The [`host`](#server.options.host) configuration value.\n\n- `address` - the active IP address the connection was bound to after starting. Set to `undefined`\n  until the server has been started or when using a non TCP port (e.g. UNIX domain socket).\n\n- `protocol` - the protocol used:\n\n    - `'http'` - HTTP.\n    - `'https'` - HTTPS.\n    - `'socket'` - UNIX domain socket or Windows named pipe.\n\n- `uri` - a string representing the connection (e.g. 'http://example.com:8080' or\n  'socket:/unix/domain/socket/path'). Contains the [`uri`](#server.options.uri) value if set,\n  otherwise constructed from the available settings. If no [`port`](#server.options.port) is\n  configured or is set to `0`, the `uri` will not include a port component until the server is\n  started.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({ port: 80 });\n\nconsole.log(server.info.port);            // 80\n```\n\n#### <a name=\"server.listener\" /> `server.listener`\n\nAccess: read only and listener public interface.\n\nThe node HTTP server object.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst SocketIO = require('socket.io');\n\nconst server = Hapi.server({ port: 80 });\n\nconst io = SocketIO.listen(server.listener);\nio.sockets.on('connection', (socket) => {\n\n    socket.emit({ msg: 'welcome' });\n});\n```\n\n#### <a name=\"server.load\" /> `server.load`\n\nAccess: read only.\n\nAn object containing the process load metrics (when [`load.sampleInterval`](#server.options.load)\nis enabled):\n\n- `eventLoopDelay` - event loop delay milliseconds.\n- `eventLoopUtilization` - current event loop utilization value.\n- `heapUsed` - V8 heap usage.\n- `rss` - RSS memory usage.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({ load: { sampleInterval: 1000 } });\n\nconsole.log(server.load.rss);\n```\n\n#### <a name=\"server.methods\" /> `server.methods`\n\nAccess: read only.\n\nServer methods are functions registered with the server and used throughout the application as a\ncommon utility. Their advantage is in the ability to configure them to use the built-in cache and\nshare across multiple request handlers without having to create a common module.\n\n`sever.methods` is an object which provides access to the methods registered via\n[server.method()](#server.method()) where each server method name is an object\nproperty.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server();\n\nserver.method('add', (a, b) => (a + b));\nconst result = server.methods.add(1, 2);    // 3\n```\n\n#### <a name=\"server.mime\" /> `server.mime`\n\nAccess: read only and **mimos** public interface.\n\nProvides access to the server MIME database used for setting content-type information. The object\nmust not be modified directly but only through the [`mime`](#server.options.mime) server setting.\n\n```js\nconst Hapi = require('@hapi/hapi');\n\nconst options = {\n    mime: {\n        override: {\n            'node/module': {\n                source: 'steve',\n                compressible: false,\n                extensions: ['node', 'module', 'npm'],\n                type: 'node/module'\n            }\n        }\n    }\n};\n\nconst server = Hapi.server(options);\nconsole.log(server.mime.path('code.js').type)        // 'application/javascript'\nconsole.log(server.mime.path('file.npm').type)        // 'node/module'\n```\n\n#### <a name=\"server.plugins\" /> `server.plugins`\n\nAccess: read / write.\n\nAn object containing the values exposed by each registered plugin where each key is a plugin name\nand the values are the exposed properties by each plugin using\n[`server.expose()`](#server.expose()). Plugins may set the value of the\n`server.plugins[name]` object directly or via the `server.expose()` method.\n\n```js\nexports.plugin = {\n    name: 'example',\n    register: function (server, options) {\n\n        server.expose('key', 'value');\n        server.plugins.example.other = 'other';\n\n        console.log(server.plugins.example.key);      // 'value'\n        console.log(server.plugins.example.other);    // 'other'\n    }\n};\n```\n\n#### <a name=\"server.realm\" /> `server.realm`\n\nAccess: read only.\n\nThe realm object contains sandboxed server settings specific to each plugin or authentication\nstrategy. When registering a plugin or an authentication scheme, a `server` object reference is\nprovided with a new `server.realm` container specific to that registration. It allows each plugin\nto maintain its own settings without leaking and affecting other plugins.\n\nFor example, a plugin can set a default file path for local resources without breaking other\nplugins' configured paths. When calling [`server.bind()`](#server.bind()), the active realm's\n`settings.bind` property is set which is then used by routes and extensions added at the same level\n(server root or plugin).\n\nThe `server.realm` object contains:\n\n- `modifiers` - when the server object is provided as an argument to the plugin `register()`\n  method, `modifiers` provides the registration preferences passed the\n  [`server.register()`](#server.register()) method and includes:\n\n    - `route` - routes preferences:\n\n        - `prefix` - the route path prefix used by any calls to [`server.route()`](#server.route())\n          from the server. Note that if a prefix is used and the route path is set to `'/'`, the\n          resulting path will not include the trailing slash.\n        - `vhost` - the route virtual host settings used by any calls to\n          [`server.route()`](#server.route()) from the server.\n\n- `parent` - the realm of the parent server object, or `null` for the root server.\n\n- `plugin` - the active plugin name (empty string if at the server root).\n\n- `pluginOptions` - the plugin options passed at registration.\n\n- `plugins` - plugin-specific state to be shared only among activities sharing the same active\n  state. `plugins` is an object where each key is a plugin name and the value is the plugin state.\n\n- `settings` - settings overrides:\n\n    - `files.relativeTo`\n    - `bind`\n\nThe `server.realm` object should be considered read-only and must not be changed directly except\nfor the `plugins` property which can be directly manipulated by each plugin, setting its properties\ninside `plugins[name]`.\n\n```js\nexports.register = function (server, options) {\n\n    console.log(server.realm.modifiers.route.prefix);\n};\n```\n\n#### <a name=\"server.registrations\" /> `server.registrations`\n\nAccess: read only.\n\nAn object of the currently registered plugins where each key is a registered plugin name and the\nvalue is an object containing:\n\n- `version` - the plugin version.\n- `name` - the plugin name.\n- `options` - (optional) options passed to the plugin during registration.\n\n#### <a name=\"server.settings\" /> `server.settings`\n\nAccess: read only.\n\nThe server configuration object after defaults applied.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({\n    app: {\n        key: 'value'\n    }\n});\n\nconsole.log(server.settings.app);   // { key: 'value' }\n```\n\n#### <a name=\"server.states\" /> `server.states`\n\nAccess: read only and **statehood** public interface.\n\nThe server cookies manager.\n\n#### <a name=\"server.states.settings\" /> `server.states.settings`\n\nAccess: read only.\n\nThe server cookies manager settings. The settings are based on the values configured in\n[`server.options.state`](#server.options.state).\n\n#### <a name=\"server.states.cookies\" /> `server.states.cookies`\n\nAccess: read only.\n\nAn object containing the configuration of each cookie added via [`server.state()`](#server.state())\nwhere each key is the cookie name and value is the configuration object.\n\n#### <a name=\"server.states.names\" /> `server.states.names`\n\nAccess: read only.\n\nAn array containing the names of all configured cookies.\n\n#### <a name=\"server.type\" /> `server.type`\n\nAccess: read only.\n\nA string indicating the listener type where:\n- `'socket'` - UNIX domain socket or Windows named pipe.\n- `'tcp'` - an HTTP listener.\n\n#### <a name=\"server.version\" /> `server.version`\n\nAccess: read only.\n\nThe **hapi** module version number.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server();\n\nconsole.log(server.version);        // '17.0.0'\n```\n\n### <a name=\"server.auth.default()\" /> `server.auth.default(options)`\n\nSets a default strategy which is applied to every route where:\n\n- `options` - one of:\n\n    - a string with the default strategy name\n    - an authentication configuration object using the same format as the\n      [route `auth` handler options](#route.options.auth).\n\nReturn value: none.\n\nThe default does not apply when a route config specifies `auth` as `false`, or has an\nauthentication strategy configured (contains the [`strategy`](#route.options.auth.strategy) or\n[`strategies`](#route.options.auth.strategies) authentication settings). Otherwise, the route\nauthentication config is applied to the defaults.\n\nNote that if the route has authentication configured, the default only applies at the time of\nadding the route, not at runtime. This means that calling `server.auth.default()` after adding a\nroute with some authentication config will have no impact on the routes added prior. However, the\ndefault will apply to routes added before `server.auth.default()` is called if those routes lack\nany authentication config.\n\nThe default auth strategy configuration can be accessed via [`server.auth.settings.default`](#server.auth.settings.default).\nTo obtain the active authentication configuration of a route, use `server.auth.lookup(request.route)`.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({ port: 80 });\n\nserver.auth.scheme('custom', scheme);\nserver.auth.strategy('default', 'custom');\nserver.auth.default('default');\n\nserver.route({\n    method: 'GET',\n    path: '/',\n    handler: function (request, h) {\n\n        return request.auth.credentials.user;\n    }\n});\n```\n\n### <a name=\"server.auth.scheme()\" /> `server.auth.scheme(name, scheme)`\n\nRegisters an authentication scheme where:\n\n- `name` - the scheme name.\n- `scheme` - the method implementing the scheme with signature `function(server, options)` where:\n    - `server` - a reference to the server object the scheme is added to. Each auth strategy is given its own [`server.realm`](#server.realm) whose parent is the realm of the `server` in the call to [`server.auth.strategy()`](#server.auth.strategy()).\n    - `options` - (optional) the scheme `options` argument passed to\n      [`server.auth.strategy()`](#server.auth.strategy()) when instantiation a strategy.\n\nReturn value: none.\n\nThe `scheme` function must return an [authentication scheme object](#authentication-scheme) when\ninvoked.\n\n#### Authentication scheme\n\nAn authentication scheme is an object with the following properties:\n\n- `api` - (optional) object which is exposed via the [`server.auth.api`](#server.auth.api) object.\n\n- `async authenticate(request, h)` - (required) a [lifecycle method](#lifecycle-methods) function\n  called for each incoming request configured with the authentication scheme. The method is\n  provided with two special toolkit methods for returning an authenticated or an unauthenticate\n  result:\n    - [`h.authenticated()`](#h.authenticated()) - indicate request authenticated successfully.\n    - [`h.unauthenticated()`](#h.unauthenticated()) - indicate request failed to authenticate.\n\n- `async payload(request, h)` - (optional) a [lifecycle method](#lifecycle-methods) to authenticate\n  the request payload.\n\n- `async response(request, h)` - (optional) a [lifecycle method](#lifecycle-methods) to decorate\n  the response with authentication headers before the response headers or payload is written.\n\n- `async verify(auth)` - (optional) a method used to verify the authentication credentials provided\n  are still valid (e.g. not expired or revoked after the initial authentication) where:\n  - `auth` - the [`request.auth`](#request.auth) object containing the `credentials` and\n    `artifacts` objects returned by the scheme's `authenticate()` method.\n  - the method throws an `Error` when the credentials passed are no longer valid (e.g. expired or\n  revoked). Note that the method does not have access to the original request, only to the\n  credentials and artifacts produced by the `authenticate()` method.\n\n- `options` - (optional) an object with the following keys:\n    - `payload` - if `true`, requires payload validation as part of the scheme and forbids routes\n      from disabling payload auth validation. Defaults to `false`.\n\nWhen the scheme `authenticate()` method implementation throws an error or calls\n[`h.unauthenticated()`](#h.unauthenticated()), the specifics of the error affect whether additional\nauthentication strategies will be attempted (if configured for the route). If the error includes a\nmessage, no additional strategies will be attempted. If the `err` does not include a message but\ndoes include the scheme name (e.g. `Boom.unauthorized(null, 'Custom')`), additional strategies will\nbe attempted in the order of preference (defined in the route configuration). If authentication\nfails, the scheme names will be present in the 'WWW-Authenticate' header.\n\nWhen the scheme `payload()` method throws an error with a message, it means payload validation\nfailed due to bad payload. If the error has no message but includes a scheme name (e.g.\n`Boom.unauthorized(null, 'Custom')`), authentication may still be successful if the route\n[`auth.payload`](#route.options.auth.payload) configuration is set to `'optional'`.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({ port: 80 });\n\nconst scheme = function (server, options) {\n\n    return {\n        authenticate: function (request, h) {\n\n            const req = request.raw.req;\n            const authorization = req.headers.authorization;\n            if (!authorization) {\n                throw Boom.unauthorized(null, 'Custom');\n            }\n\n            return h.authenticated({ credentials: { user: 'john' } });\n        }\n    };\n};\n\nserver.auth.scheme('custom', scheme);\n```\n\n### <a name=\"server.auth.strategy()\" /> `server.auth.strategy(name, scheme, [options])`\n\nRegisters an authentication strategy where:\n\n- `name` - the strategy name.\n- `scheme` - the scheme name (must be previously registered using\n  [`server.auth.scheme()`](#server.auth.scheme())).\n- `options` - scheme options based on the scheme requirements.\n\nReturn value: none.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({ port: 80 });\n\nserver.auth.scheme('custom', scheme);\nserver.auth.strategy('default', 'custom');\n\nserver.route({\n    method: 'GET',\n    path: '/',\n    options: {\n        auth: 'default',\n        handler: function (request, h) {\n\n            return request.auth.credentials.user;\n        }\n    }\n});\n```\n\n### <a name=\"server.auth.test()\" /> `await server.auth.test(strategy, request)`\n\nTests a request against an authentication strategy where:\n\n- `strategy` - the strategy name registered with [`server.auth.strategy()`](#server.auth.strategy()).\n- `request` - the [request object](#request).\n\nReturn value: an object containing the authentication `credentials` and `artifacts` if authentication\nwas successful, otherwise throws an error.\n\nNote that the `test()` method does not take into account the route authentication configuration. It\nalso does not perform payload authentication. It is limited to the basic strategy authentication\nexecution. It does not include verifying scope, entity, or other route properties.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({ port: 80 });\n\nserver.auth.scheme('custom', scheme);\nserver.auth.strategy('default', 'custom');\n\nserver.route({\n    method: 'GET',\n    path: '/',\n    handler: async function (request, h) {\n\n        try {\n            const { credentials, artifacts } = await request.server.auth.test('default', request);\n            return { status: true, user: credentials.name };\n        }\n        catch (err) {\n            return { status: false };\n        }\n    }\n});\n```\n\n\n### <a name=\"server.auth.verify()\" /> `await server.auth.verify(request)`\n\nVerify a request's authentication credentials against an authentication strategy where:\n\n- `request` - the [request object](#request).\n\nReturn value: nothing if verification was successful, otherwise throws an error.\n\nNote that the `verify()` method does not take into account the route authentication configuration\nor any other information from the request other than the `request.auth` object. It also does not\nperform payload authentication. It is limited to verifying that the previously valid credentials\nare still valid (e.g. have not been revoked or expired). It does not include verifying scope,\nentity, or other route properties.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({ port: 80 });\n\nserver.auth.scheme('custom', scheme);\nserver.auth.strategy('default', 'custom');\n\nserver.route({\n    method: 'GET',\n    path: '/',\n    handler: async function (request, h) {\n\n        try {\n            const credentials = await request.server.auth.verify(request);\n            return { status: true, user: credentials.name };\n        }\n        catch (err) {\n            return { status: false };\n        }\n    }\n});\n```\n\n### <a name=\"server.bind()\" /> `server.bind(context)`\n\nSets a global context used as the default bind object when adding a route or an extension where:\n\n- `context` - the object used to bind `this` in [lifecycle methods](#lifecycle-methods) such as\n  the [route handler](#route.options.handler) and [extension methods](#server.ext()). The context\n  is also made available as [`h.context`](#h.context).\n\nReturn value: none.\n\nWhen setting a context inside a plugin, the context is applied only to methods set up by the\nplugin. Note that the context applies only to routes and extensions added after it has been set.\nIgnored if the method being bound is an arrow function.\n\n```js\nconst handler = function (request, h) {\n\n    return this.message;    // Or h.context.message\n};\n\nexports.plugin = {\n    name: 'example',\n    register: function (server, options) {\n\n        const bind = {\n            message: 'hello'\n        };\n\n        server.bind(bind);\n        server.route({ method: 'GET', path: '/', handler });\n    }\n};\n```\n\n### <a name=\"server.cache()\" /> `server.cache(options)`\n\nProvisions a cache segment within the server cache facility where:\n\n- `options` - [**catbox** policy](https://hapi.dev/family/catbox/api#policy) configuration where:\n\n    - `expiresIn` - relative expiration expressed in the number of milliseconds since the item was\n      saved in the cache. Cannot be used together with `expiresAt`.\n\n    - `expiresAt` - time of day expressed in 24h notation using the 'HH:MM' format, at which point\n      all cache records expire. Uses local time. Cannot be used together with `expiresIn`.\n\n    - `generateFunc` - a function used to generate a new cache item if one is not found in the\n      cache when calling `get()`. The method's signature is `async function(id, flags)` where:\n\n          - `id` - the `id` string or object provided to the `get()` method.\n          - `flags` - an object used to pass back additional flags to the cache where:\n              - `ttl` - the cache ttl value in milliseconds. Set to `0` to skip storing in the\n                cache. Defaults to the cache global policy.\n\n    - `staleIn` - number of milliseconds to mark an item stored in cache as stale and attempt to\n      regenerate it when `generateFunc` is provided. Must be less than `expiresIn`.\n\n    - `staleTimeout` - number of milliseconds to wait before checking if an item is stale.\n\n    - `generateTimeout` - number of milliseconds to wait before returning a timeout error when the\n      `generateFunc` function takes too long to return a value. When the value is eventually\n      returned, it is stored in the cache for future requests. Required if `generateFunc` is\n      present. Set to `false` to disable timeouts which may cause all `get()` requests to get stuck\n      forever.\n\n    - `generateOnReadError` - if `false`, an upstream cache read error will stop the `cache.get()`\n      method from calling the generate function and will instead pass back the cache error. Defaults\n      to `true`.\n\n    - `generateIgnoreWriteError` - if `false`, an upstream cache write error when calling\n      `cache.get()` will be passed back with the generated value when calling. Defaults to `true`.\n\n    - `dropOnError` - if `true`, an error or timeout in the `generateFunc` causes the stale value\n      to be evicted from the cache.  Defaults  to `true`.\n\n    - `pendingGenerateTimeout` - number of milliseconds while `generateFunc` call is in progress\n      for a given id, before a subsequent `generateFunc` call is allowed. Defaults to `0` (no\n      blocking of concurrent `generateFunc` calls beyond `staleTimeout`).\n\n    - `cache` - the cache name configured in [`server.cache`](#server.options.cache). Defaults to\n      the default cache.\n\n    - `segment` - string segment name, used to isolate cached items within the cache partition.\n      When called within a plugin, defaults to '!name' where 'name' is the plugin name. When called\n      within a server method, defaults to '#name' where 'name' is the server method name. Required\n      when called outside of a plugin.\n\n    - `shared` - if `true`, allows multiple cache provisions to share the same segment. Default to\n      `false`.\n\nReturn value: a [**catbox** policy](https://hapi.dev/family/catbox/api#policy) object.\n\n```js\nconst Hapi = require('@hapi/hapi');\n\nasync function example() {\n\n    const server = Hapi.server({ port: 80 });\n    const cache = server.cache({ segment: 'countries', expiresIn: 60 * 60 * 1000 });\n    await cache.set('norway', { capital: 'oslo' });\n    const value = await cache.get('norway');\n}\n```\n\n### <a name=\"server.cache.provision()\" /> `await server.cache.provision(options)`\n\nProvisions a server cache as described in [`server.cache`](#server.options.cache","isInternal":false,"tokens":11326,"sizeBytes":50000}],"systemPromptSnippet":"<yakaai_skills repo=\"hapijs/hapi\">\n<!-- File: API.md (Tokens: ~11326 | Category: project-spec) -->\n## Server\n\nThe server object is the main application container. The server manages all incoming requests\nalong with all the facilities provided by the framework. Each server supports a single connection\n(e.g. listen to port `80`).\n\n### <a name=\"server()\" /> `server([options])`\n\nCreates a new server object where:\n- `options` - (optional) a [server configuration object](#server.options).\n\n```js\nconst Hapi = require('@hapi/hapi');\n\nconst server = Hapi.server({ load: { sampleInterval: 1000 } });\n```\n\n### <a name=\"server.options\" /> Server options\n\nThe server options control the behavior of the server object. Note that the options object is\ndeeply cloned (with the exception of [`listener`](#server.options.listener) which is shallowly\ncopied) and should not contain any values that are unsafe to perform deep copy on.\n\nAll options are optionals.\n\n#### <a name=\"server.options.address\" /> `server.options.address`\n\nDefault value: `'::'` if IPv6 is available, otherwise `'0.0.0.0'` (i.e. all available network interfaces).\n\nSets the hostname or IP address the server will listen on. If not configured, defaults to\n[`host`](#server.options.host) if present, otherwise to all available network interfaces. Set to\n`'127.0.0.1'`, `'::1'`, or `'localhost'` to restrict the server to only those coming from the same host.\n\n#### <a name=\"server.options.app\" /> `server.options.app`\n\nDefault value: `{}`.\n\nProvides application-specific configuration which can later be accessed via\n[`server.settings.app`](#server.settings). The framework does not interact with this object. It is\nsimply a reference made available anywhere a `server` reference is provided.\n\nNote the difference between `server.settings.app` which is used to store static configuration\nvalues and [`server.app`](#server.app) which is meant for storing run-time state.\n\n#### <a name=\"server.options.autolisten\" /> `server.options.autoListen`\n\nDefault value: `true`.\n\nUsed to disable the automatic initialization of the [`listener`](#server.options.listener). When\n`false`, indicates that the [`listener`](#server.options.listener) will be started manually outside\nthe framework.\n\nCannot be set to `false` along with a [`port`](#server.options.port) value.\n\n#### <a name=\"server.options.cache\" /> `server.options.cache`\n\nDefault value: `{ provider: { constructor: require('@hapi/catbox-memory'), options: { partition: 'hapi-cache' } } }`.\n\nSets up server-side caching providers. Every server includes a default cache for storing\napplication state. By default, a simple memory-based cache is created which has limited capacity\nand capabilities.\n\n**hapi** uses [**catbox**](https://hapi.dev/family/catbox/api) for its cache implementation which\nincludes support for common storage solutions (e.g. Redis, MongoDB, Memcached, Riak, among others).\nCaching is only utilized if [methods](#server.methods) and [plugins](#plugins) explicitly store\ntheir state in the cache.\n\nThe server cache configuration only defines the storage container itself. The configuration can be\nassigned one or more (array):\n\n- a class or prototype function (usually obtained by calling `require()` on a **catbox** strategy\n    such as `require('@hapi/catbox-redis')`). A new **catbox** [client](https://hapi.dev/family/catbox/api#client)\n    will be created internally using this constructor.\n\n- a configuration object with the following:\n\n    - `engine` - a **catbox** engine object instance.\n\n    - `name` - an identifier used later when provisioning or configuring caching for\n        [server methods](#server.methods) or [plugins](#plugins). Each cache name must be unique.\n        A single item may omit the `name` option which defines the default cache. If every cache\n        includes a `name`, a default memory cache is provisioned as well.\n\n    - `provider` - a class, a constructor function, or an object with the following:\n\n        - `constructor` - a class or a prototype function.\n\n        - `options` - (optional) a settings object passed as-is to the `constructor` with the following:\n\n            - `partition` - (optional) string used to isolate cached data. Defaults to `'hapi-cache'`.\n            - other constructor-specific options passed to the `constructor` on instantiation.\n\n    - `shared` - if `true`, allows multiple cache users to share the same segment (e.g.\n        multiple methods using the same cache storage container). Default to `false`.\n\n    - One (and only one) of `engine` or `provider` is required per configuration object.\n\n#### <a name=\"server.options.compression\" /> `server.options.compression`\n\nDefault value: `{ minBytes: 1024 }`.\n\nDefines server handling of content encoding requests. If `false`, response content encoding is\ndisabled and no compression is performed by the server.\n\n##### <a name=\"server.options.compression.minBytes\" /> `server.options.compression.minBytes`\n\nDefault value: '1024'.\n\nSets the minimum response payload size in bytes that is required for content encoding compression.\nIf the payload size is under the limit, no compression is performed.\n\n#### <a name=\"server.options.debug\" /> `server.options.debug`\n\nDefault value: `{ request: ['implementation'] }`.\n\nDetermines which logged events are sent to the console. This should only be used for development\nand does not affect which events are actually logged internally and recorded. Set to `false` to\ndisable all console logging, or to an object with:\n\n- `log` - a string array of server log tags to be displayed via `console.error()` when\n    the events are logged via [`server.log()`](#server.log()) as well as\n    internally generated [server logs](#server-logs). Defaults to no output.\n\n- `request` - a string array of request log tags to be displayed via `console.error()` when\n    the events are logged via [`request.log()`](#request.log()) as well as\n    internally generated [request logs](#request-logs). For example, to display all errors,\n    set the option to `['error']`. To turn off all console debug messages set it to `false`.\n    To display all request logs, set it to `'*'`.\n    Defaults to uncaught errors thrown in external code (these errors are handled\n    automatically and result in an Internal Server Error response) or runtime errors due to\n    developer error.\n\nFor example, to display all errors, set the `log` or `request` to `['error']`. To turn off all\noutput set the `log` or `request` to `false`. To display all server logs, set the `log` or\n`request` to `'*'`. To disable all debug information, set `debug` to `false`.\n\n#### <a name=\"server.options.host\" /> `server.options.host`\n\nDefault value: the operating system hostname and if not available, to `'localhost'`.\n\nThe public hostname or IP address. Used to set [`server.info.host`](#server.info) and\n[`server.info.uri`](#server.info) and as [`address`](#server.options.address) if none is provided.\n\n#### <a name=\"server.options.info.remote\" /> `server.options.info.remote`\n\nDefault value: `false`.\n\nIf `true`, the `request.info.remoteAddress` and `request.info.remotePort` are populated when the request is received which can consume more resource (but is ok if the information is needed, especially for aborted requests). When `false`, the fields are only populated upon demand (but will be `undefined` if accessed after the request is aborted).\n\n#### <a name=\"server.options.listener\" /> `server.options.listener`\n\nDefault value: none.\n\nAn optional node HTTP (or HTTPS) [`http.Server`](https://nodejs.org/api/http.html#http_class_http_server)\nobject (or an object with a compatible interface).\n\nIf the `listener` needs to be manually started, set [`autoListen`](#server.options.autolisten) to\n`false`.\n\nIf the `listener` uses TLS, set [`tls`](#server.options.tls) to `true`.\n\n#### <a name=\"server.options.load\" /> `server.options.load`\n\nDefault value: `{ sampleInterval: 0, maxHeapUsedBytes: 0, maxRssBytes: 0, maxEventLoopDelay: 0, maxEventLoopUtilization: 0 }`.\n\nServer excessive load handling limits where:\n\n- `sampleInterval` - the frequency of sampling in milliseconds. When set to `0`, the other load options are ignored. Defaults to `0` (no sampling).\n\n- `maxHeapUsedBytes` - maximum V8 heap size over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to `0` (no limit).\n\n- `maxRssBytes` - maximum process RSS size over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to `0` (no limit).\n\n- `maxEventLoopDelay` - maximum event loop delay duration in milliseconds over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to `0` (no limit).\n\n- `maxEventLoopUtilization` - maximum event loop utilization value over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to `0` (no limit).\n\n#### <a name=\"server.options.mime\" /> `server.options.mime`\n\nDefault value: none.\n\nOptions passed to the [**mimos**](https://hapi.dev/family/mimos/api) module when generating the mime database used by the server (and accessed via [`server.mime`](#server.mime)):\n\n- `override` - an object hash that is merged into the built in mime information specified [here](https://github.com/jshttp/mime-db). Each key value pair represents a single mime object. Each override value must contain:\n\n    - `key` - the lower-cased mime-type string (e.g. `'application/javascript'`).\n\n    - `value` - an object following the specifications outlined [here](https://github.com/jshttp/mime-db#data-structure). Additional values include:\n\n        - `type` - specify the `type` value of result objects, defaults to `key`.\n\n        - `predicate` - method with signature `function(mime)` when this mime type is found in the database, this function will execute to allows customizations.\n\n```js\nconst options = {\n    mime: {\n        override: {\n            'node/module': {\n                source: 'iana',\n                compressible: true,\n                extensions: ['node', 'module', 'npm'],\n                type: 'node/module'\n            },\n            'application/javascript': {\n                source: 'iana',\n                charset: 'UTF-8',\n                compressible: true,\n                extensions: ['js', 'javascript'],\n                type: 'text/javascript'\n            },\n            'text/html': {\n                predicate: function(mime) {\n                    if (someCondition) {\n                        mime.foo = 'test';\n                    }\n                    else {\n                        mime.foo = 'bar';\n                    }\n                    return mime;\n                }\n            }\n        }\n    }\n};\n```\n\n#### <a name=\"server.options.operations\" /> `server.options.operations`\n\nDefault value: `{ cleanStop: true }`.\n\nDefines server handling of server operations:\n\n- `cleanStop` - if `true`, the server keeps track of open connections and properly closes them\n  when the server is stopped. Under normal load, this should not interfere with server performance.\n  However, under severe load connection monitoring can consume additional resources and aggravate\n  the situation. If the server is never stopped, or if it is forced to stop without waiting for\n  open connection to close, setting this to `false` can save resources that are not being utilized\n  anyway. Defaults to `true`.\n\n#### <a name=\"server.options.plugins\" /> `server.options.plugins`\n\nDefault value: `{}`.\n\nPlugin-specific configuration which can later be accessed via [`server.settings.plugins`](#server.settings).\n`plugins` is an object where each key is a plugin name and the value is the configuration.\nNote the difference between [`server.settings.plugins`](#server.settings) which is used to store\nstatic configuration values and [`server.plugins`](#server.plugins) which is meant for storing\nrun-time state.\n\n#### <a name=\"server.options.port\" /> `server.options.port`\n\nDefault value: `0` (an ephemeral port).\n\nThe TCP port the server will listen to. Defaults the next available port when the server is started\n(and assigned to [`server.info.port`](#server.info)).\n\nIf `port` is a string containing a '/' character, it is used as a UNIX domain socket path.\nIf it starts with '\\\\.\\pipe', it is used as a Windows named pipe.\n\n#### <a name=\"server.options.query\" /> `server.options.query`\n\nDefault value: `{}`.\n\nDefines server handling of the request path query component.\n\n##### <a name=\"server.options.query.parser\" /> `server.options.query.parser`\n\nDefault value: none.\n\nSets a query parameters parser method using the signature `function(query)` where:\n\n- `query` - an object containing the incoming [`request.query`](#request.query) parameters.\n- the method must return an object where each key is a parameter and matching value is the\n  parameter value. If the method throws, the error is used as the response or returned when\n  [`request.setUrl()`](#request.setUrl()) is called.\n\n```js\nconst Qs = require('qs');\n\nconst options = {\n    query: {\n        parser: (query) => Qs.parse(query)\n    }\n};\n```\n\n#### <a name=\"server.options.router\" /> `server.options.router`\n\nDefault value: `{ isCaseSensitive: true, stripTrailingSlash: false }`.\n\nControls how incoming request URIs are matched against the routing table:\n\n- `isCaseSensitive` - determines whether the paths '/example' and '/EXAMPLE' are considered\n  different resources. Defaults to `true`.\n\n- `stripTrailingSlash` - removes trailing slashes on incoming paths. Defaults to `false`.\n\n#### <a name=\"server.options.routes\" /> `server.options.routes`\n\nDefault value: none.\n\nA [route options](#route-options) object used as the default configuration for every route.\n\n#### <a name=\"server.options.state\" /> `server.options.state`\n\nDefault value:\n```js\n{\n    strictHeader: true,\n    ignoreErrors: false,\n    isSecure: true,\n    isHttpOnly: true,\n    isSameSite: 'Strict',\n    isPartitioned: false,\n    encoding: 'none'\n}\n```\n\nSets the default configuration for every state (cookie) set explicitly via\n[`server.state()`](#server.state()) or implicitly (without definition) using the\n[state configuration](#server.state()) object.\n\n#### <a name=\"server.options.tls\" /> `server.options.tls`\n\nDefault value: none.\n\nUsed to create an HTTPS connection. The `tls` object is passed unchanged to the node\nHTTPS server as described in the [node HTTPS documentation](https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener).\n\nSet to `true` when passing a [`listener`](#server.options.listener) object that has been configured\nto use TLS directly.\n\n#### <a name=\"server.options.uri\" /> `server.options.uri`\n\nDefault value: constructed from runtime server information.\n\nThe full public URI without the path (e.g. 'http://example.com:8080'). If present, used as the\nserver [`server.info.uri`](#server.info), otherwise constructed from the server settings.\n\n### Server properties\n\n#### <a name=\"server.app\" /> `server.app`\n\nAccess: read / write.\n\nProvides a safe place to store server-specific run-time application data without potential\nconflicts with the framework internals. The data can be accessed whenever the server is\naccessible. Initialized with an empty object.\n\n```js\nconst server = Hapi.server();\n\nserver.app.key = 'value';\n\nconst handler = function (request, h) {\n\n    return request.server.app.key;        // 'value'\n};\n```\n\n#### <a name=\"server.auth.api\" /> `server.auth.api`\n\nAccess: authentication strategy specific.\n\nAn object where each key is an authentication strategy name and the value is the exposed strategy\nAPI. Available only when the authentication scheme exposes an API by returning an `api` key in the\nobject returned from its implementation function.\n\n```js\nconst server = Hapi.server({ port: 80 });\n\nconst scheme = function (server, options) {\n\n    return {\n        api: {\n            settings: {\n                x: 5\n            }\n        },\n        authenticate: function (request, h) {\n\n            const authorization = request.headers.authorization;\n            if (!authorization) {\n                throw Boom.unauthorized(null, 'Custom');\n            }\n\n            return h.authenticated({ credentials: { user: 'john' } });\n        }\n    };\n};\n\nserver.auth.scheme('custom', scheme);\nserver.auth.strategy('default', 'custom');\n\nconsole.log(server.auth.api.default.settings.x);    // 5\n```\n\n#### <a name=\"server.auth.settings.default\" /> `server.auth.settings.default`\n\nAccess: read only.\n\nContains the default authentication configuration if a default strategy was set via\n[`server.auth.default()`](#server.auth.default()).\n\n#### <a name=\"server.decorations\" /> `server.decorations`\n\nAccess: read only.\n\nProvides access to the decorations already applied to various framework interfaces. The object must\nnot be modified directly, but only through [`server.decorate`](#server.decorate()).\nContains:\n\n- `request` - decorations on the [request object](#request).\n- `response` - decorations on the [response object](#response-object).\n- `toolkit` - decorations on the [response toolkit](#response-toolkit).\n- `server` - decorations on the [server](#server) object.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({ port: 80 });\n\nconst success = function () {\n\n    return this.response({ status: 'ok' });\n};\n\nserver.decorate('toolkit', 'success', success);\nconsole.log(server.decorations.toolkit);            // ['success']\n```\n\n#### <a name=\"server.events\" /> `server.events`\n\nAccess: **podium** public interface.\n\nThe server events emitter. Utilizes the [**podium**](https://hapi.dev/family/podium/api) with support\nfor event criteria validation, channels, and filters.\n\nUse the following methods to interact with `server.events`:\n\n- [`server.event(events)`](#server.event()) - register application events.\n- [`server.events.emit(criteria, data)`](#server.events.emit()) - emit server events.\n- [`server.events.on(criteria, listener, context)`](#server.events.on()) - subscribe to all events.\n- [`server.events.once(criteria, listener, context)`](#server.events.once()) - subscribe to a single event.\n\nOther methods include: `server.events.removeListener(name, listener)`,\n`server.events.removeAllListeners(name)`, and `server.events.hasListeners(name)`.\n\n##### <a name=\"server.events.log\" /> `'log'` Event\n\nThe `'log'` event type emits internal server events generated by the framework as well as\napplication events logged with [`server.log()`](#server.log()).\n\nThe `'log'` event handler uses the function signature `function(event, tags)` where:\n\n- `event` - an object with the following properties:\n    - `timestamp` - the event timestamp.\n    - `tags` - an array of tags identifying the event (e.g. `['error', 'http']`).\n    - `channel` - set to `'internal'` for internally generated events, otherwise `'app'` for events\n      generated by [`server.log()`](#server.log()).\n    - `data` - event-specific information. Available when event data was provided and is not an\n      error. Errors are passed via `error`.\n    - `error` - the error object related to the event if applicable. Cannot appear together with\n      `data`.\n\n- `tags` - an object where each `event.tag` is a key and the value is `true`. Useful for quick\n  identification of events.\n\n```js\nserver.events.on('log', (event, tags) => {\n\n    if (tags.error) {\n        console.log(`Server error: ${event.error ? event.error.message : 'unknown'}`);\n    }\n});\n```\n\nThe internally generated events are (identified by their `tags`):\n\n- `load` - logs the current server load measurements when the server rejects a request due to\n  [high load](#server.options.load). The event data contains the process load metrics.\n\n- `connection` `client` `error` - a `clientError` event was received from the HTTP or HTTPS\n  listener. The event data is the error object received.\n\n##### <a name=\"server.events.cachePolicy\" /> `'cachePolicy'` Event\n\nThe `'cachePolicy'` event type is emitted when a server [cache policy](https://hapi.dev/module/catbox/api#policy)\nis created via [`server.cache()`](#server.cache()) or a [`server.method()`](#server.method()) with caching enabled is registered.\nThe `'cachePolicy'` event handler uses the function signature `function(cachePolicy, cache, segment)` where:\n\n- `cachePolicy` - the catbox [cache policy](https://hapi.dev/module/catbox/api#policy).\n- `cache` - the [cache provision](#server.options.cache) name used when the policy was created or `undefined` if the default cache was used.\n- `segment` - the segment name used when the policy was created.\n\n```js\nserver.events.on('cachePolicy', (cachePolicy, cache, segment) => {\n\n    console.log(`New cache policy created using cache: ${cache === undefined ? 'default' : cache} and segment: ${segment}`);\n});\n```\n\n##### <a name=\"server.events.request\" /> `'request'` Event\n\nThe `'request'` event type emits internal request events generated by the framework as well as\napplication events logged with [`request.log()`](#request.log()).\n\nThe `'request'` event handler uses the function signature `function(request, event, tags)` where:\n\n- `request` - the [request object](#request).\n\n- `event` - an object with the following properties:\n    - `timestamp` - the event timestamp.\n    - `tags` - an array of tags identifying the event (e.g. `['error', 'http']`).\n    - `channel` - one of\n        - `'app'` - events generated by [`request.log()`](#request.log()).\n        - `'error'` - emitted once per request if the response had a `500` status code.\n        - `'internal'` - internally generated events.\n    - `request` - the request [identifier](#request.info.id).\n    - `data` - event-specific information. Available when event data was provided and is not an\n      error. Errors are passed via `error`.\n    - `error` - the error object related to the event if applicable. Cannot appear together with\n      `data`.\n\n- `tags` - an object where each `event.tag` is a key and the value is `true`. Useful for quick\n  identification of events.\n\n```js\nserver.events.on('request', (request, event, tags) => {\n\n    if (tags.error) {\n        console.log(`Request ${event.request} error: ${event.error ? event.error.message : 'unknown'}`);\n    }\n});\n```\n\nTo listen to only one of the channels, use the event criteria object:\n\n```js\nserver.events.on({ name: 'request', channels: 'error' }, (request, event, tags) => {\n\n    console.log(`Request ${event.request} failed`);\n});\n```\n\nThe internally generated events are (identified by their `tags`):\n\n- `accept-encoding` `error` - a request received contains an invalid Accept-Encoding header.\n- `auth` `unauthenticated` - no authentication scheme included with the request.\n- `auth` `unauthenticated` `response` `{strategy}` - the authentication strategy listed returned a non-error response (e.g. a redirect to a login page).\n- `auth` `unauthenticated` `error` `{strategy}` - the request failed to pass the listed authentication strategy (invalid credentials).\n- `auth` `unauthenticated` `missing` `{strategy}` - the request failed to pass the listed authentication strategy (no credentials found).\n- `auth` `unauthenticated` `try` `{strategy}` - the request failed to pass the listed authentication strategy in `'try'` mode and will continue.\n- `auth` `scope` `error` - the request authenticated but failed to meet the scope requirements.\n- `auth` `entity` `user` `error` - the request authenticated but included an application entity when a user entity was required.\n- `auth` `entity` `app` `error` - the request authenticated but included a user entity when an application entity was required.\n- `ext` `error` - an `onPostResponse` extension handler errored.\n- `handler` `error` - the route handler returned an error. Includes the execution duration and the error message.\n- `pre` `error` - a pre method was executed and returned an error. Includes the execution duration, assignment key, and error.\n- `internal` `error` - an HTTP 500 error response was assigned to the request.\n- `internal` `implementation` `error` - an incorrectly implemented [lifecycle method](#lifecycle-methods).\n- `request` `error` `abort` - the request aborted.\n- `request` `error` `close` - the request closed prematurely.\n- `request` `error` - the request stream emitted an error. Includes the error.\n- `request` `server` `timeout` `error` - the request took too long to process by the server. Includes the timeout configuration value and the duration.\n- `state` `error` - the request included an invalid cookie or cookies. Includes the cookies and error details.\n- `state` `response` `error` - the response included an invalid cookie which prevented generating a valid header. Includes the error.\n- `payload` `error` - failed processing the request payload. Includes the error.\n- `response` `error` - failed writing the response to the client. Includes the error.\n- `response` `error` `close` - failed writing the response to the client due to prematurely closed connection.\n- `response` `error` `aborted` - failed writing the response to the client due to prematurely aborted connection.\n- `response` `error` `cleanup` - failed freeing response resources.\n- `validation` `error` `{input}` - input (i.e. payload, query, params, headers) validation failed. Includes the error. Only emitted when `failAction` is set to `'log'`.\n- `validation` `response` `error` - response validation failed. Includes the error message. Only emitted when `failAction` is set to `'log'`.\n\n##### <a name=\"server.events.response\" /> `'response'` Event\n\nThe `'response'` event type is emitted after the response is sent back to the client (or when the\nclient connection closed and no response sent, in which case [`request.response`](#request.response)\nis `null`). A single event is emitted per request. The `'response'` event handler uses the function\nsignature `function(request)` where:\n\n- `request` - the [request object](#request).\n\n```js\nserver.events.on('response', (request) => {\n\n    console.log(`Response sent for request: ${request.info.id}`);\n});\n```\n\n##### <a name=\"server.events.route\" /> `'route'` Event\n\nThe `'route'` event type is emitted when a route is added via [`server.route()`](#server.route()).\nThe `'route'` event handler uses the function signature `function(route)` where:\n\n- `route` - the [route information](#request.route). The `route` object must not be modified.\n\n```js\nserver.events.on('route', (route) => {\n\n    console.log(`New route added: ${route.path}`);\n});\n```\n\n##### <a name=\"server.events.start\" /> `'start'` Event\n\nThe `'start'` event type is emitted when the server is started using [`server.start()`](#server.start()).\nThe `'start'` event handler uses the function signature `function()`.\n\n```js\nserver.events.on('start', () => {\n\n    console.log('Server started');\n});\n```\n\n##### <a name=\"server.events.closing\" /> `'closing'` Event\n\nThe `'closing'` event type is emitted when the server is stopped using [`server.stop()`](#server.stop()). It is triggered when incoming requests are no longer accepted but before all underlying active connections have been closed, and thus before the [`'stop'`](#server.events.stop) event is triggered.\nThe `'closing'` event handler uses the function signature `function()`.\n\n```js\nserver.events.on('closing', () => {\n\n    console.log('Server is closing');\n});\n```\n\n##### <a name=\"server.events.stop\" /> `'stop'` Event\n\nThe `'stop'` event type is emitted when the server is stopped using [`server.stop()`](#server.stop()).\nThe `'stop'` event handler uses the function signature `function()`.\n\n```js\nserver.events.on('stop', () => {\n\n    console.log('Server stopped');\n});\n```\n\n#### <a name=\"server.info\" /> `server.info`\n\nAccess: read only.\n\nAn object containing information about the server where:\n\n- `id` - a unique server identifier (using the format '{hostname}:{pid}:{now base36}').\n\n- `created` - server creation timestamp.\n\n- `started` - server start timestamp (`0` when stopped).\n\n- `port` - the connection port based on the following rules:\n\n    - before the server has been started: the configured [`port`](#server.options.port) value.\n    - after the server has been started: the actual port assigned when no port is configured or was\n      set to `0`.\n\n- `host` - The [`host`](#server.options.host) configuration value.\n\n- `address` - the active IP address the connection was bound to after starting. Set to `undefined`\n  until the server has been started or when using a non TCP port (e.g. UNIX domain socket).\n\n- `protocol` - the protocol used:\n\n    - `'http'` - HTTP.\n    - `'https'` - HTTPS.\n    - `'socket'` - UNIX domain socket or Windows named pipe.\n\n- `uri` - a string representing the connection (e.g. 'http://example.com:8080' or\n  'socket:/unix/domain/socket/path'). Contains the [`uri`](#server.options.uri) value if set,\n  otherwise constructed from the available settings. If no [`port`](#server.options.port) is\n  configured or is set to `0`, the `uri` will not include a port component until the server is\n  started.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({ port: 80 });\n\nconsole.log(server.info.port);            // 80\n```\n\n#### <a name=\"server.listener\" /> `server.listener`\n\nAccess: read only and listener public interface.\n\nThe node HTTP server object.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst SocketIO = require('socket.io');\n\nconst server = Hapi.server({ port: 80 });\n\nconst io = SocketIO.listen(server.listener);\nio.sockets.on('connection', (socket) => {\n\n    socket.emit({ msg: 'welcome' });\n});\n```\n\n#### <a name=\"server.load\" /> `server.load`\n\nAccess: read only.\n\nAn object containing the process load metrics (when [`load.sampleInterval`](#server.options.load)\nis enabled):\n\n- `eventLoopDelay` - event loop delay milliseconds.\n- `eventLoopUtilization` - current event loop utilization value.\n- `heapUsed` - V8 heap usage.\n- `rss` - RSS memory usage.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({ load: { sampleInterval: 1000 } });\n\nconsole.log(server.load.rss);\n```\n\n#### <a name=\"server.methods\" /> `server.methods`\n\nAccess: read only.\n\nServer methods are functions registered with the server and used throughout the application as a\ncommon utility. Their advantage is in the ability to configure them to use the built-in cache and\nshare across multiple request handlers without having to create a common module.\n\n`sever.methods` is an object which provides access to the methods registered via\n[server.method()](#server.method()) where each server method name is an object\nproperty.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server();\n\nserver.method('add', (a, b) => (a + b));\nconst result = server.methods.add(1, 2);    // 3\n```\n\n#### <a name=\"server.mime\" /> `server.mime`\n\nAccess: read only and **mimos** public interface.\n\nProvides access to the server MIME database used for setting content-type information. The object\nmust not be modified directly but only through the [`mime`](#server.options.mime) server setting.\n\n```js\nconst Hapi = require('@hapi/hapi');\n\nconst options = {\n    mime: {\n        override: {\n            'node/module': {\n                source: 'steve',\n                compressible: false,\n                extensions: ['node', 'module', 'npm'],\n                type: 'node/module'\n            }\n        }\n    }\n};\n\nconst server = Hapi.server(options);\nconsole.log(server.mime.path('code.js').type)        // 'application/javascript'\nconsole.log(server.mime.path('file.npm').type)        // 'node/module'\n```\n\n#### <a name=\"server.plugins\" /> `server.plugins`\n\nAccess: read / write.\n\nAn object containing the values exposed by each registered plugin where each key is a plugin name\nand the values are the exposed properties by each plugin using\n[`server.expose()`](#server.expose()). Plugins may set the value of the\n`server.plugins[name]` object directly or via the `server.expose()` method.\n\n```js\nexports.plugin = {\n    name: 'example',\n    register: function (server, options) {\n\n        server.expose('key', 'value');\n        server.plugins.example.other = 'other';\n\n        console.log(server.plugins.example.key);      // 'value'\n        console.log(server.plugins.example.other);    // 'other'\n    }\n};\n```\n\n#### <a name=\"server.realm\" /> `server.realm`\n\nAccess: read only.\n\nThe realm object contains sandboxed server settings specific to each plugin or authentication\nstrategy. When registering a plugin or an authentication scheme, a `server` object reference is\nprovided with a new `server.realm` container specific to that registration. It allows each plugin\nto maintain its own settings without leaking and affecting other plugins.\n\nFor example, a plugin can set a default file path for local resources without breaking other\nplugins' configured paths. When calling [`server.bind()`](#server.bind()), the active realm's\n`settings.bind` property is set which is then used by routes and extensions added at the same level\n(server root or plugin).\n\nThe `server.realm` object contains:\n\n- `modifiers` - when the server object is provided as an argument to the plugin `register()`\n  method, `modifiers` provides the registration preferences passed the\n  [`server.register()`](#server.register()) method and includes:\n\n    - `route` - routes preferences:\n\n        - `prefix` - the route path prefix used by any calls to [`server.route()`](#server.route())\n          from the server. Note that if a prefix is used and the route path is set to `'/'`, the\n          resulting path will not include the trailing slash.\n        - `vhost` - the route virtual host settings used by any calls to\n          [`server.route()`](#server.route()) from the server.\n\n- `parent` - the realm of the parent server object, or `null` for the root server.\n\n- `plugin` - the active plugin name (empty string if at the server root).\n\n- `pluginOptions` - the plugin options passed at registration.\n\n- `plugins` - plugin-specific state to be shared only among activities sharing the same active\n  state. `plugins` is an object where each key is a plugin name and the value is the plugin state.\n\n- `settings` - settings overrides:\n\n    - `files.relativeTo`\n    - `bind`\n\nThe `server.realm` object should be considered read-only and must not be changed directly except\nfor the `plugins` property which can be directly manipulated by each plugin, setting its properties\ninside `plugins[name]`.\n\n```js\nexports.register = function (server, options) {\n\n    console.log(server.realm.modifiers.route.prefix);\n};\n```\n\n#### <a name=\"server.registrations\" /> `server.registrations`\n\nAccess: read only.\n\nAn object of the currently registered plugins where each key is a registered plugin name and the\nvalue is an object containing:\n\n- `version` - the plugin version.\n- `name` - the plugin name.\n- `options` - (optional) options passed to the plugin during registration.\n\n#### <a name=\"server.settings\" /> `server.settings`\n\nAccess: read only.\n\nThe server configuration object after defaults applied.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({\n    app: {\n        key: 'value'\n    }\n});\n\nconsole.log(server.settings.app);   // { key: 'value' }\n```\n\n#### <a name=\"server.states\" /> `server.states`\n\nAccess: read only and **statehood** public interface.\n\nThe server cookies manager.\n\n#### <a name=\"server.states.settings\" /> `server.states.settings`\n\nAccess: read only.\n\nThe server cookies manager settings. The settings are based on the values configured in\n[`server.options.state`](#server.options.state).\n\n#### <a name=\"server.states.cookies\" /> `server.states.cookies`\n\nAccess: read only.\n\nAn object containing the configuration of each cookie added via [`server.state()`](#server.state())\nwhere each key is the cookie name and value is the configuration object.\n\n#### <a name=\"server.states.names\" /> `server.states.names`\n\nAccess: read only.\n\nAn array containing the names of all configured cookies.\n\n#### <a name=\"server.type\" /> `server.type`\n\nAccess: read only.\n\nA string indicating the listener type where:\n- `'socket'` - UNIX domain socket or Windows named pipe.\n- `'tcp'` - an HTTP listener.\n\n#### <a name=\"server.version\" /> `server.version`\n\nAccess: read only.\n\nThe **hapi** module version number.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server();\n\nconsole.log(server.version);        // '17.0.0'\n```\n\n### <a name=\"server.auth.default()\" /> `server.auth.default(options)`\n\nSets a default strategy which is applied to every route where:\n\n- `options` - one of:\n\n    - a string with the default strategy name\n    - an authentication configuration object using the same format as the\n      [route `auth` handler options](#route.options.auth).\n\nReturn value: none.\n\nThe default does not apply when a route config specifies `auth` as `false`, or has an\nauthentication strategy configured (contains the [`strategy`](#route.options.auth.strategy) or\n[`strategies`](#route.options.auth.strategies) authentication settings). Otherwise, the route\nauthentication config is applied to the defaults.\n\nNote that if the route has authentication configured, the default only applies at the time of\nadding the route, not at runtime. This means that calling `server.auth.default()` after adding a\nroute with some authentication config will have no impact on the routes added prior. However, the\ndefault will apply to routes added before `server.auth.default()` is called if those routes lack\nany authentication config.\n\nThe default auth strategy configuration can be accessed via [`server.auth.settings.default`](#server.auth.settings.default).\nTo obtain the active authentication configuration of a route, use `server.auth.lookup(request.route)`.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({ port: 80 });\n\nserver.auth.scheme('custom', scheme);\nserver.auth.strategy('default', 'custom');\nserver.auth.default('default');\n\nserver.route({\n    method: 'GET',\n    path: '/',\n    handler: function (request, h) {\n\n        return request.auth.credentials.user;\n    }\n});\n```\n\n### <a name=\"server.auth.scheme()\" /> `server.auth.scheme(name, scheme)`\n\nRegisters an authentication scheme where:\n\n- `name` - the scheme name.\n- `scheme` - the method implementing the scheme with signature `function(server, options)` where:\n    - `server` - a reference to the server object the scheme is added to. Each auth strategy is given its own [`server.realm`](#server.realm) whose parent is the realm of the `server` in the call to [`server.auth.strategy()`](#server.auth.strategy()).\n    - `options` - (optional) the scheme `options` argument passed to\n      [`server.auth.strategy()`](#server.auth.strategy()) when instantiation a strategy.\n\nReturn value: none.\n\nThe `scheme` function must return an [authentication scheme object](#authentication-scheme) when\ninvoked.\n\n#### Authentication scheme\n\nAn authentication scheme is an object with the following properties:\n\n- `api` - (optional) object which is exposed via the [`server.auth.api`](#server.auth.api) object.\n\n- `async authenticate(request, h)` - (required) a [lifecycle method](#lifecycle-methods) function\n  called for each incoming request configured with the authentication scheme. The method is\n  provided with two special toolkit methods for returning an authenticated or an unauthenticate\n  result:\n    - [`h.authenticated()`](#h.authenticated()) - indicate request authenticated successfully.\n    - [`h.unauthenticated()`](#h.unauthenticated()) - indicate request failed to authenticate.\n\n- `async payload(request, h)` - (optional) a [lifecycle method](#lifecycle-methods) to authenticate\n  the request payload.\n\n- `async response(request, h)` - (optional) a [lifecycle method](#lifecycle-methods) to decorate\n  the response with authentication headers before the response headers or payload is written.\n\n- `async verify(auth)` - (optional) a method used to verify the authentication credentials provided\n  are still valid (e.g. not expired or revoked after the initial authentication) where:\n  - `auth` - the [`request.auth`](#request.auth) object containing the `credentials` and\n    `artifacts` objects returned by the scheme's `authenticate()` method.\n  - the method throws an `Error` when the credentials passed are no longer valid (e.g. expired or\n  revoked). Note that the method does not have access to the original request, only to the\n  credentials and artifacts produced by the `authenticate()` method.\n\n- `options` - (optional) an object with the following keys:\n    - `payload` - if `true`, requires payload validation as part of the scheme and forbids routes\n      from disabling payload auth validation. Defaults to `false`.\n\nWhen the scheme `authenticate()` method implementation throws an error or calls\n[`h.unauthenticated()`](#h.unauthenticated()), the specifics of the error affect whether additional\nauthentication strategies will be attempted (if configured for the route). If the error includes a\nmessage, no additional strategies will be attempted. If the `err` does not include a message but\ndoes include the scheme name (e.g. `Boom.unauthorized(null, 'Custom')`), additional strategies will\nbe attempted in the order of preference (defined in the route configuration). If authentication\nfails, the scheme names will be present in the 'WWW-Authenticate' header.\n\nWhen the scheme `payload()` method throws an error with a message, it means payload validation\nfailed due to bad payload. If the error has no message but includes a scheme name (e.g.\n`Boom.unauthorized(null, 'Custom')`), authentication may still be successful if the route\n[`auth.payload`](#route.options.auth.payload) configuration is set to `'optional'`.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({ port: 80 });\n\nconst scheme = function (server, options) {\n\n    return {\n        authenticate: function (request, h) {\n\n            const req = request.raw.req;\n            const authorization = req.headers.authorization;\n            if (!authorization) {\n                throw Boom.unauthorized(null, 'Custom');\n            }\n\n            return h.authenticated({ credentials: { user: 'john' } });\n        }\n    };\n};\n\nserver.auth.scheme('custom', scheme);\n```\n\n### <a name=\"server.auth.strategy()\" /> `server.auth.strategy(name, scheme, [options])`\n\nRegisters an authentication strategy where:\n\n- `name` - the strategy name.\n- `scheme` - the scheme name (must be previously registered using\n  [`server.auth.scheme()`](#server.auth.scheme())).\n- `options` - scheme options based on the scheme requirements.\n\nReturn value: none.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({ port: 80 });\n\nserver.auth.scheme('custom', scheme);\nserver.auth.strategy('default', 'custom');\n\nserver.route({\n    method: 'GET',\n    path: '/',\n    options: {\n        auth: 'default',\n        handler: function (request, h) {\n\n            return request.auth.credentials.user;\n        }\n    }\n});\n```\n\n### <a name=\"server.auth.test()\" /> `await server.auth.test(strategy, request)`\n\nTests a request against an authentication strategy where:\n\n- `strategy` - the strategy name registered with [`server.auth.strategy()`](#server.auth.strategy()).\n- `request` - the [request object](#request).\n\nReturn value: an object containing the authentication `credentials` and `artifacts` if authentication\nwas successful, otherwise throws an error.\n\nNote that the `test()` method does not take into account the route authentication configuration. It\nalso does not perform payload authentication. It is limited to the basic strategy authentication\nexecution. It does not include verifying scope, entity, or other route properties.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({ port: 80 });\n\nserver.auth.scheme('custom', scheme);\nserver.auth.strategy('default', 'custom');\n\nserver.route({\n    method: 'GET',\n    path: '/',\n    handler: async function (request, h) {\n\n        try {\n            const { credentials, artifacts } = await request.server.auth.test('default', request);\n            return { status: true, user: credentials.name };\n        }\n        catch (err) {\n            return { status: false };\n        }\n    }\n});\n```\n\n\n### <a name=\"server.auth.verify()\" /> `await server.auth.verify(request)`\n\nVerify a request's authentication credentials against an authentication strategy where:\n\n- `request` - the [request object](#request).\n\nReturn value: nothing if verification was successful, otherwise throws an error.\n\nNote that the `verify()` method does not take into account the route authentication configuration\nor any other information from the request other than the `request.auth` object. It also does not\nperform payload authentication. It is limited to verifying that the previously valid credentials\nare still valid (e.g. have not been revoked or expired). It does not include verifying scope,\nentity, or other route properties.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst server = Hapi.server({ port: 80 });\n\nserver.auth.scheme('custom', scheme);\nserver.auth.strategy('default', 'custom');\n\nserver.route({\n    method: 'GET',\n    path: '/',\n    handler: async function (request, h) {\n\n        try {\n            const credentials = await request.server.auth.verify(request);\n            return { status: true, user: credentials.name };\n        }\n        catch (err) {\n            return { status: false };\n        }\n    }\n});\n```\n\n### <a name=\"server.bind()\" /> `server.bind(context)`\n\nSets a global context used as the default bind object when adding a route or an extension where:\n\n- `context` - the object used to bind `this` in [lifecycle methods](#lifecycle-methods) such as\n  the [route handler](#route.options.handler) and [extension methods](#server.ext()). The context\n  is also made available as [`h.context`](#h.context).\n\nReturn value: none.\n\nWhen setting a context inside a plugin, the context is applied only to methods set up by the\nplugin. Note that the context applies only to routes and extensions added after it has been set.\nIgnored if the method being bound is an arrow function.\n\n```js\nconst handler = function (request, h) {\n\n    return this.message;    // Or h.context.message\n};\n\nexports.plugin = {\n    name: 'example',\n    register: function (server, options) {\n\n        const bind = {\n            message: 'hello'\n        };\n\n        server.bind(bind);\n        server.route({ method: 'GET', path: '/', handler });\n    }\n};\n```\n\n### <a name=\"server.cache()\" /> `server.cache(options)`\n\nProvisions a cache segment within the server cache facility where:\n\n- `options` - [**catbox** policy](https://hapi.dev/family/catbox/api#policy) configuration where:\n\n    - `expiresIn` - relative expiration expressed in the number of milliseconds since the item was\n      saved in the cache. Cannot be used together with `expiresAt`.\n\n    - `expiresAt` - time of day expressed in 24h notation using the 'HH:MM' format, at which point\n      all cache records expire. Uses local time. Cannot be used together with `expiresIn`.\n\n    - `generateFunc` - a function used to generate a new cache item if one is not found in the\n      cache when calling `get()`. The method's signature is `async function(id, flags)` where:\n\n          - `id` - the `id` string or object provided to the `get()` method.\n          - `flags` - an object used to pass back additional flags to the cache where:\n              - `ttl` - the cache ttl value in milliseconds. Set to `0` to skip storing in the\n                cache. Defaults to the cache global policy.\n\n    - `staleIn` - number of milliseconds to mark an item stored in cache as stale and attempt to\n      regenerate it when `generateFunc` is provided. Must be less than `expiresIn`.\n\n    - `staleTimeout` - number of milliseconds to wait before checking if an item is stale.\n\n    - `generateTimeout` - number of milliseconds to wait before returning a timeout error when the\n      `generateFunc` function takes too long to return a value. When the value is eventually\n      returned, it is stored in the cache for future requests. Required if `generateFunc` is\n      present. Set to `false` to disable timeouts which may cause all `get()` requests to get stuck\n      forever.\n\n    - `generateOnReadError` - if `false`, an upstream cache read error will stop the `cache.get()`\n      method from calling the generate function and will instead pass back the cache error. Defaults\n      to `true`.\n\n    - `generateIgnoreWriteError` - if `false`, an upstream cache write error when calling\n      `cache.get()` will be passed back with the generated value when calling. Defaults to `true`.\n\n    - `dropOnError` - if `true`, an error or timeout in the `generateFunc` causes the stale value\n      to be evicted from the cache.  Defaults  to `true`.\n\n    - `pendingGenerateTimeout` - number of milliseconds while `generateFunc` call is in progress\n      for a given id, before a subsequent `generateFunc` call is allowed. Defaults to `0` (no\n      blocking of concurrent `generateFunc` calls beyond `staleTimeout`).\n\n    - `cache` - the cache name configured in [`server.cache`](#server.options.cache). Defaults to\n      the default cache.\n\n    - `segment` - string segment name, used to isolate cached items within the cache partition.\n      When called within a plugin, defaults to '!name' where 'name' is the plugin name. When called\n      within a server method, defaults to '#name' where 'name' is the server method name. Required\n      when called outside of a plugin.\n\n    - `shared` - if `true`, allows multiple cache provisions to share the same segment. Default to\n      `false`.\n\nReturn value: a [**catbox** policy](https://hapi.dev/family/catbox/api#policy) object.\n\n```js\nconst Hapi = require('@hapi/hapi');\n\nasync function example() {\n\n    const server = Hapi.server({ port: 80 });\n    const cache = server.cache({ segment: 'countries', expiresIn: 60 * 60 * 1000 });\n    await cache.set('norway', { capital: 'oslo' });\n    const value = await cache.get('norway');\n}\n```\n\n### <a name=\"server.cache.provision()\" /> `await server.cache.provision(options)`\n\nProvisions a server cache as described in [`server.cache`](#server.options.cache\n</yakaai_skills>"}