Skip to content

Commit 69a243e

Browse files
committed
Fixes #88
1 parent 7ac14e2 commit 69a243e

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/Simplify.Web/Modules/IWebContext.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,13 @@ public interface IWebContext : IHideObjectMembers
5757
/// <c>true</c> if current request is ajax request; otherwise, <c>false</c>.
5858
/// </value>
5959
bool IsAjax { get; }
60+
61+
/// <summary>
62+
/// Gets the request body.
63+
/// </summary>
64+
/// <value>
65+
/// The request body.
66+
/// </value>
67+
string RequestBody { get; }
6068
}
6169
}

src/Simplify.Web/Modules/WebContext.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
using System;
1+
using Microsoft.AspNetCore.Http;
2+
using System;
3+
using System.IO;
24
using System.Threading.Tasks;
3-
using Microsoft.AspNetCore.Http;
45

56
namespace Simplify.Web.Modules
67
{
@@ -10,6 +11,7 @@ namespace Simplify.Web.Modules
1011
public class WebContext : IWebContext
1112
{
1213
private readonly Lazy<IFormCollection> _form;
14+
private readonly Lazy<string> _requestBody;
1315

1416
/// <summary>
1517
/// Initializes a new instance of the <see cref="WebContext"/> class.
@@ -23,6 +25,7 @@ public WebContext(HttpContext context)
2325
Query = context.Request.Query;
2426

2527
_form = new Lazy<IFormCollection>(() => Task.Run(() => context.Request.ReadFormAsync()).Result);
28+
_requestBody = new Lazy<string>(() => new StreamReader(Context.Request.Body).ReadToEnd());
2629

2730
VirtualPath = string.IsNullOrEmpty(Request.PathBase.Value) ? "" : Request.PathBase.Value;
2831

@@ -83,5 +86,13 @@ public WebContext(HttpContext context)
8386
/// <c>true</c> if current request is ajax request; otherwise, <c>false</c>.
8487
/// </value>
8588
public bool IsAjax { get; }
89+
90+
/// <summary>
91+
/// Gets or sets the request body.
92+
/// </summary>
93+
/// <value>
94+
/// The request body.
95+
/// </value>
96+
public string RequestBody => _requestBody.Value;
8697
}
8798
}

0 commit comments

Comments
 (0)