Skip to content

Commit 490ec6b

Browse files
committed
Fixed an issue where the request stream might not be seekable
1 parent 47098af commit 490ec6b

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/Platforms/Exceptionless.AspNetCore/RequestInfoCollector.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,15 @@ public static RequestInfo Collect(HttpContext context, IEnumerable<string> exclu
4343
} else if (context.Request.ContentLength.HasValue && context.Request.ContentLength.Value > 0) {
4444
if (context.Request.ContentLength.Value < 1024 * 50) {
4545
try {
46-
if (context.Request.Body.Position > 0)
46+
if (context.Request.Body.CanSeek && context.Request.Body.Position > 0)
4747
context.Request.Body.Position = 0;
4848

49-
using (var inputStream = new StreamReader(context.Request.Body))
50-
info.PostData = inputStream.ReadToEnd();
49+
if (context.Request.Body.Position == 0) {
50+
using (var inputStream = new StreamReader(context.Request.Body))
51+
info.PostData = inputStream.ReadToEnd();
52+
} else {
53+
info.PostData = "Unable to get POST data: The stream could not be reset.";
54+
}
5155
} catch (Exception ex) {
5256
info.PostData = "Error retrieving POST data: " + ex.Message;
5357
}

src/Platforms/Exceptionless.Web/RequestInfoCollector.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,15 @@ public static RequestInfo Collect(HttpContextBase context, ExceptionlessConfigur
5252
} else if (context.Request.ContentLength > 0) {
5353
if (context.Request.ContentLength < 1024 * 50) {
5454
try {
55-
if (context.Request.InputStream.Position > 0)
55+
if (context.Request.InputStream.CanSeek && context.Request.InputStream.Position > 0)
5656
context.Request.InputStream.Position = 0;
5757

58-
using (var inputStream = new StreamReader(context.Request.InputStream))
59-
info.PostData = inputStream.ReadToEnd();
58+
if (context.Request.InputStream.Position == 0) {
59+
using (var inputStream = new StreamReader(context.Request.InputStream))
60+
info.PostData = inputStream.ReadToEnd();
61+
} else {
62+
info.PostData = "Unable to get POST data: The stream could not be reset.";
63+
}
6064
} catch (Exception ex) {
6165
info.PostData = "Error retrieving POST data: " + ex.Message;
6266
}

0 commit comments

Comments
 (0)