Skip to content
This repository was archived by the owner on Oct 11, 2023. It is now read-only.

Commit 080910d

Browse files
authored
Merge pull request #141 from xinyanmsft/master
bug fix in Gateway
2 parents 8bf2ae3 + 02bd4e8 commit 080910d

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

samples/BikeSharingApp/Gateway/Middleware/RequestLoggingMiddleware.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,18 @@ public async Task Invoke(HttpContext context)
3030
await this._next(context);
3131

3232
context.Response.Body = responseStream;
33-
memStream.Seek(0, SeekOrigin.Begin);
34-
using (StreamReader reader = new StreamReader(memStream))
33+
// Writing to response body is not supported for 204, 205 and 304 responses.
34+
if (context.Response.StatusCode != 204 /* NoContent */ &&
35+
context.Response.StatusCode != 205 /* ResetContent */ &&
36+
context.Response.StatusCode != 304 /* NotModified */)
3537
{
36-
responseBody = await reader.ReadToEndAsync();
38+
memStream.Seek(0, SeekOrigin.Begin);
39+
using (StreamReader reader = new StreamReader(memStream))
40+
{
41+
responseBody = await reader.ReadToEndAsync();
42+
}
43+
await context.Response.WriteAsync(responseBody);
3744
}
38-
await context.Response.WriteAsync(responseBody);
3945
}
4046

4147
if (context.Response.StatusCode >= 500)

0 commit comments

Comments
 (0)