Skip to content

Commit

Permalink
Fixes #449
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinmoris committed Nov 26, 2020
1 parent 7f47e64 commit ae4702f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Release Notes
=============

## 5.0.0-rc-3

- Added `ReadBodyBufferedFromRequestAsync` extension method to buffer and read a the request body and make subsequent reads possible (see [#449](https://github.com/giraffe-fsharp/Giraffe/issues/449))

## 5.0.0-rc-2

- Fixed pre-conditions validation issue (see [#424](https://github.com/giraffe-fsharp/Giraffe/issues/424))
Expand Down
19 changes: 19 additions & 0 deletions src/Giraffe/ModelBinding.fs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,25 @@ type HttpContext with
return! reader.ReadToEndAsync()
}

/// <summary>
/// Reads the entire body of the <see cref="Microsoft.AspNetCore.Http.HttpRequest"/> asynchronously and returns it as a <see cref="System.String"/> value.
/// This method buffers the response and makes subsequent reads possible.
/// </summary>
/// <returns>Returns the contents of the request body as a <see cref="System.Threading.Tasks.Task{System.String}"/>.</returns>
member this.ReadBodyBufferedFromRequestAsync() =
task {
this.Request.EnableBuffering()
use reader =
new StreamReader(
this.Request.Body,
encoding = Encoding.UTF8,
detectEncodingFromByteOrderMarks = false,
leaveOpen = true)
let! body = reader.ReadToEndAsync()
this.Request.Body.Position <- 0L
return body
}

/// <summary>
/// Uses the <see cref="IJsonSerializer"/> to deserializes the entire body of the <see cref="Microsoft.AspNetCore.Http.HttpRequest"/> asynchronously into an object of type 'T.
/// </summary>
Expand Down

0 comments on commit ae4702f

Please sign in to comment.