Skip to content

Commit

Permalink
Merge pull request #7 from MaxDeg/leave-aspnet-response-body-open
Browse files Browse the repository at this point in the history
StreamReader/Writer are disposing Request/Response body
  • Loading branch information
MangelMaxime committed Nov 12, 2019
2 parents ce42a7e + b05a424 commit 071d34e
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 071d34e

Please sign in to comment.