Documentation Language: Swift

Method

ok(body:contentType:includeBody:)

Creates a 200 OK response with file content.

static func ok(body data: Data, contentType: MIMEType, includeBody: Bool) -> HTTPResponse

Parameters

contentType

The MIME type of the content.

includeBody

Whether to include the body content. Set to false for HEAD requests.

Return Value

A configured HTTP response.

Discussion

This method constructs a successful response containing the file data with appropriate content type and length headers.

Example

let fileData = try Data(contentsOf: fileURL)
let response = HTTPResponse.ok(
    body: fileData,
    contentType: .html,
    includeBody: true
)