Skip to content

Commit

Permalink
adding leaveOpen = true parameter to avoid closing the response/reque…
Browse files Browse the repository at this point in the history
…st body when closing StreamWriter/Reader
  • Loading branch information
Maxime Degallaix committed Nov 7, 2019
1 parent ce42a7e commit b05a424
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/ThothSerializer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type ThothSerializer (?isCamelCase : bool, ?extra : ExtraCoders, ?skipNullField
fun (next: HttpFunc) (ctx: HttpContext) ->
task {
ctx.SetContentType "application/json; charset=utf-8"
use stream = new System.IO.StreamWriter(ctx.Response.Body, Utf8EncodingWithoutBom, DefaultBufferSize)
use stream = new System.IO.StreamWriter(ctx.Response.Body, Utf8EncodingWithoutBom, DefaultBufferSize, true)
use jsonWriter = new JsonTextWriter(stream)
do! body.WriteToAsync(jsonWriter)
return Some ctx
Expand All @@ -37,7 +37,7 @@ type ThothSerializer (?isCamelCase : bool, ?extra : ExtraCoders, ?skipNullField
ctx.SetStatusCode 200
ctx.SetContentType "application/json; charset=utf-8"
use stream =
new System.IO.StreamWriter(ctx.Response.Body, Utf8EncodingWithoutBom, DefaultBufferSize)
new System.IO.StreamWriter(ctx.Response.Body, Utf8EncodingWithoutBom, DefaultBufferSize, true)
use jsonWriter = new JsonTextWriter(stream)
jsonWriter.WriteStartArray()
for item in items do
Expand All @@ -53,7 +53,7 @@ type ThothSerializer (?isCamelCase : bool, ?extra : ExtraCoders, ?skipNullField

static member ReadBodyRaw (ctx: HttpContext) =
task {
use stream = new System.IO.StreamReader(ctx.Request.Body, Utf8EncodingWithoutBom)
use stream = new System.IO.StreamReader(ctx.Request.Body, Utf8EncodingWithoutBom, true, DefaultBufferSize, true)
use jsonReader = new JsonTextReader(stream)
let! json = JValue.ReadFromAsync jsonReader
return json
Expand Down

0 comments on commit b05a424

Please sign in to comment.