Skip to content

Commit

Permalink
chore: apply automated updates
Browse files Browse the repository at this point in the history
  • Loading branch information
autofix-ci[bot] committed Feb 25, 2024
1 parent 272e1be commit 96eda87
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/2.utils/1.request.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ icon: material-symbols-light:input
### `assertMethod(event, expected, allowHead?)`

Asserts that the incoming request method is of the expected type using `isMethod`.

If the method is not allowed, it will throw a 405 error with the message "HTTP method is not allowed".

### `getHeader(event, name)`
Expand All @@ -20,6 +21,7 @@ Get a request header by name.
### `getHeaders(event)`

Get the request headers object.

Array headers are joined with a comma.

### `getQuery(event)`
Expand All @@ -33,29 +35,37 @@ Get a request header by name.
### `getRequestHeaders(event)`

Get the request headers object.

Array headers are joined with a comma.

### `getRequestHost(event, opts: { xForwardedHost? })`

Get the request hostname.

If `xForwardedHost` is `true`, it will use the `x-forwarded-host` header if it exists.

If no host header is found, it will default to "localhost".

### `getRequestIP(event)`

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.

### `getRequestProtocol(event, opts: { xForwardedProto? })`

Get the request protocol.

If `x-forwarded-proto` header is set to "https", it will return "https". You can disable this behavior by setting `xForwardedProto` to `false`.

If protocol cannot be determined, it will default to "http".

### `getRequestURL(event, opts: { xForwardedHost?, xForwardedProto? })`

Generated 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.

If `xForwardedProto` is `false`, it will not use the `x-forwarded-proto` header.

### `getRouterParam(event, name, opts: { decode? })`
Expand All @@ -65,6 +75,7 @@ Get a matched route param by name.
### `getRouterParams(event, opts: { decode? })`

Get matched route params.

If `decode` option is `true`, it will decode the matched route params using `decodeURI`.

### `getValidatedQuery(event, validate)`
Expand All @@ -78,11 +89,13 @@ Get matched route params and validate with validate function.
### `isMethod(event, expected, allowHead?)`

Checks if the incoming request method is of the expected type.

If `allowHead` is `true`, it will allow `HEAD` requests to pass if the expected method is `GET`.

### `toWebRequest(event)`

Convert the H3Event to a WebRequest object.

**NOTE:** This function is not stable and might have edge cases that are not handled properly.

<!-- /automd -->
Expand Down
7 changes: 7 additions & 0 deletions docs/2.utils/2.reponse.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,15 @@ Remove a response header by name.
### `send(event, data?, type?)`

Directly send a response to the client.

**Note:** This function should be used only when you want to send a response directly without using the `h3` event. Normaly you can directly `return` a value inside event handlers.

### `sendIterable(event, iterable)`

Iterate a source of chunks and send back each chunk in order. Supports mixing async work toghether with emitting chunks.

Each chunk must be a string or a buffer.

For generator (yielding) functions, the returned value is treated the same as yielded values.

**Example:**
Expand Down Expand Up @@ -97,17 +100,21 @@ async function delay(ms) {
### `sendNoContent(event, code?)`

Respond with an empty payload.<br>

Note that calling this function will close the connection and no other data can be sent to the client afterwards.

### `sendRedirect(event, location, code)`

Send a redirect response to the client.

It adds the `location` header to the response and sets the status code to 302 by default.

In the body, it sends a simple HTML page with a meta refresh tag to redirect the client in case the headers are ignored.

### `sendStream(event, stream)`

Send a stream response to the client.

Note: You can directly `return` a stream value inside event handlers alternatively which is recommended.

### `sendWebResponse(event, response)`
Expand Down
3 changes: 3 additions & 0 deletions docs/2.utils/98.advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Make sure the status code is a valid HTTP status code.
### `sanitizeStatusMessage(statusMessage)`

Make sure the status message is safe to use in a response.

Allowed characters: horizontal tabs, spaces or visible ascii characters: https://www.rfc-editor.org/rfc/rfc7230#section-3.1.2

<!-- /automd -->
Expand Down Expand Up @@ -130,7 +131,9 @@ Append CORS preflight headers to the response.
### `handleCors(event, options)`

Handle CORS for the incoming request.

If the incoming request is a CORS preflight request, it will append the CORS preflight headers and send a 204 response.

If return value is `true`, the request is handled and no further action is needed.

### `isCorsOriginAllowed(origin, options)`
Expand Down

0 comments on commit 96eda87

Please sign in to comment.