Skip to content
Merged
Changes from all commits
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
3 changes: 1 addition & 2 deletions src/Giraffe/Core.fs
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,7 @@ module Core =
/// <param name="str">The string value to be send back to the client.</param>
/// <returns>A Giraffe <see cref="HttpHandler" /> function which can be composed into a bigger web application.</returns>
let setBodyFromString (str: string) : HttpHandler =
let bytes = Encoding.UTF8.GetBytes str
fun (_: HttpFunc) (ctx: HttpContext) -> ctx.WriteBytesAsync bytes
fun (_: HttpFunc) (ctx: HttpContext) -> ctx.WriteStringAsync str
Comment thread
Thorium marked this conversation as resolved.
Comment thread
Thorium marked this conversation as resolved.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

...because now it constructs a new dictionary on each next-call. Will there be more next-calls than routePorts calls? Just to note that Dictionary is not thread-safe so not to put it outside let routePorts.

We might need to check the IL/ASM and run a benchmark to check if there's any noticeable performance improvement. Furthermore, if we make this change, I'd like to add new automated tests to assert things are still working in the long run.


/// <summary>
/// Writes an UTF-8 encoded string to the body of the HTTP response and sets the HTTP Content-Length header accordingly, as well as the Content-Type header to text/plain.
Expand Down
Loading