Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions Hummingbird.docc/Articles/RouterGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,15 @@ Route handlers are required to return a type conforming to the `ResponseGenerato
extension String: ResponseGenerator {
/// Generate response holding string
public func response(from request: Request, context: some RequestContext) -> Response {
let buffer = context.allocator.buffer(string: self)
return Response(status: .ok, headers: ["content-type": "text/plain; charset=utf-8"], body: .byteBuffer(buffer))
let buffer = ByteBuffer(string: self)
return Response(
status: .ok,
headers: .defaultHummingbirdHeaders(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could change it to this

headers: [.contentType: "text/plain; charset=utf-8"],

contentType: "text/plain; charset=utf-8",
contentLength: buffer.readableBytes
),
body: .init(byteBuffer: buffer)
)
}
}
```
Expand Down Expand Up @@ -246,4 +253,4 @@ router.post("test") { request, _ -> EditedResponse in
- ``HummingbirdCore/Response``
- ``Router``
- ``RouteCollection``
- ``RouterGroup``
- ``RouterGroup``