From c6b0e0928eda8bdf60168993e2a023e58a3df914 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Mon, 25 Nov 2024 14:54:47 +0000 Subject: [PATCH] chore: apply automated updates --- docs/2.utils/1.request.md | 14 ++++++++------ docs/2.utils/2.response.md | 6 +++--- docs/2.utils/98.advanced.md | 2 +- src/utils/request.ts | 2 +- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/docs/2.utils/1.request.md b/docs/2.utils/1.request.md index 68a53221..0ac4d7a8 100644 --- a/docs/2.utils/1.request.md +++ b/docs/2.utils/1.request.md @@ -53,7 +53,7 @@ export default defineEventHandler((event) => { ### `getQuery(event)` -Get query the params object from the request URL parsed with [unjs/ufo](https://ufo.unjs.io). +Get the query params object from the request URL parsed with [unjs/ufo](https://ufo.unjs.io). **Example:** @@ -105,11 +105,13 @@ export default defineEventHandler((event) => { }); ``` -### `getRequestIP(event)` +### `getRequestIP(event, opts: { xForwardedFor? })` Try to get the client IP address from the incoming request. -If `xForwardedFor` is `true`, it will use the `x-forwarded-for` header if it exists. +If `xForwardedFor` is `true`, it will use the `x-forwarded-for` header set by proxies if it exists. + +Note: Make sure that this header can be trusted (your application running behind a CDN or reverse proxy) before enabling. If IP cannot be determined, it will default to `undefined`. @@ -139,7 +141,7 @@ export default defineEventHandler((event) => { ### `getRequestURL(event, opts: { xForwardedHost?, xForwardedProto? })` -Generated the full incoming request URL using `getRequestProtocol`, `getRequestHost` and `event.path`. +Generate the full incoming request URL using `getRequestProtocol`, `getRequestHost` and `event.path`. If `xForwardedHost` is `true`, it will use the `x-forwarded-host` header if it exists. @@ -183,7 +185,7 @@ export default defineEventHandler((event) => { ### `getValidatedQuery(event, validate)` -Get the query param from the request URL parsed with [unjs/ufo](https://ufo.unjs.io) and validated with validate function. +Get the query params object from the request URL parsed with [unjs/ufo](https://ufo.unjs.io) and validated with validate function. You can use a simple function to validate the query object or a library like `zod` to define a schema. @@ -315,7 +317,7 @@ export default defineEventHandler(async (event) => { ### `readMultipartFormData(event)` -Tries to read and parse the body of a an H3Event as multipart form. +Tries to read and parse the body of an H3Event as multipart form. **Example:** diff --git a/docs/2.utils/2.response.md b/docs/2.utils/2.response.md index 6f971a26..e11453c9 100644 --- a/docs/2.utils/2.response.md +++ b/docs/2.utils/2.response.md @@ -80,7 +80,7 @@ Set the response status code and message. ### `getResponseHeader(event, name)` -Alias for `getResponseHeaders`. +Get a response header by name. **Example:** @@ -130,7 +130,7 @@ export default defineEventHandler((event) => { ### `isStream(data)` -Checks if the data is a stream. (Node.js Readable Stream, React Pipeable Stream, or Web Stream) +Checks if the data is a stream (Node.js Readable Stream, React Pipeable Stream, or Web Stream). ### `isWebResponse(data)` @@ -187,7 +187,7 @@ async function delay(ms) { ### `sendNoContent(event, code?)` -Respond with an empty payload.
+Respond with an empty payload. Note that calling this function will close the connection and no other data can be sent to the client afterwards. diff --git a/docs/2.utils/98.advanced.md b/docs/2.utils/98.advanced.md index 7db3d840..cd7b5864 100644 --- a/docs/2.utils/98.advanced.md +++ b/docs/2.utils/98.advanced.md @@ -50,7 +50,7 @@ Get a cookie value by name. ### `parseCookies(event)` -Parse the request to get HTTP Cookie header string and returning an object of all cookie name-value pairs. +Parse the request to get HTTP Cookie header string and return an object of all cookie name-value pairs. ### `setCookie(event, name, value, serializeOptions?)` diff --git a/src/utils/request.ts b/src/utils/request.ts index 48aa0458..4877695e 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -377,7 +377,7 @@ export function toWebRequest(event: H3Event) { */ export function getRequestIP( event: H3Event, - opts: { xForwardedFor?: boolean; } = {}, + opts: { xForwardedFor?: boolean } = {}, ): string | undefined { if (event.context.clientAddress) { return event.context.clientAddress;