Method
handleRequest(uri:includeBody:)
Handles an HTTP request and returns an appropriate response.
func handleRequest(uri: String, includeBody: Bool) async -> HTTPResponse
Parameters
uri-
The request URI path, potentially including query parameters.
includeBody-
Whether to include the response body. Set to
falsefor HEAD requests to omit the body while preserving headers.
Return Value
An HTTP response containing the file data or error status.
Discussion
This method processes the request URI, validates the path, locates the requested file, and constructs an HTTP response with the file content or an appropriate error status.
Response Codes
-
200 OK: File found and served successfully
-
400 Bad Request: Malformed URI or invalid path encoding
-
403 Forbidden: Path escapes root directory (security violation)
-
404 Not Found: File or directory index does not exist
-
500 Internal Server Error: File read failure
Example
let response = await handler.handleRequest(
uri: "/documentation/index.html",
includeBody: true
)