Skip to content

Commit

Permalink
Merge pull request #580 from WideSpectrumComputing/master
Browse files Browse the repository at this point in the history
Rollbar.NetCore.AspNet module: fixed incorrect assignment of captured HTTP response body
  • Loading branch information
akornich committed Mar 9, 2021
2 parents 2196edd + d6771a2 commit fc917de
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
4 changes: 0 additions & 4 deletions Rollbar.NetCore.AspNet/HttpRequestPackageDecorator.cs
Expand Up @@ -2,12 +2,8 @@

namespace Rollbar.NetCore.AspNet
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json;
using Rollbar.Common;
using Rollbar.DTOs;
using Rollbar.Serialization.Json;
Expand Down
8 changes: 2 additions & 6 deletions Rollbar.NetCore.AspNet/HttpResponsePackageDecorator.cs
@@ -1,11 +1,7 @@
namespace Rollbar.NetCore.AspNet
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json;
using Rollbar.Common;
using Rollbar.DTOs;
using Rollbar.Serialization.Json;
Expand Down Expand Up @@ -92,12 +88,12 @@ private void AssignResponseBody(Data rollbarData)
{
return;
}
rollbarData.Request.PostBody = jsonString;
rollbarData.Response.Body = jsonString;

object requesBodyObject = JsonUtil.InterpretAsJsonObject(jsonString);
if (requesBodyObject != null)
{
rollbarData.Request.PostBody = requesBodyObject;
rollbarData.Response.Body = requesBodyObject;
}
}

Expand Down
13 changes: 13 additions & 0 deletions Samples/Sample.AspNetCore2.WebApi/Controllers/ValuesController.cs
Expand Up @@ -9,6 +9,8 @@
using Microsoft.Extensions.Logging;
using dto = Rollbar.DTOs;
using Rollbar.Telemetry;
using System.IO;
using System.Text;

[Route("api/[controller]")]
public class ValuesController
Expand Down Expand Up @@ -38,10 +40,21 @@ public ValuesController(ILogger<ValuesController> logger, IHttpContextAccessor h

// GET api/values
[HttpGet]
//public Task<IEnumerable<string>> GetAsync()
public IEnumerable<string> Get()
{
this._logger.LogCritical(nameof(ValuesController) + ".Get() is called...");

//StreamWriter streamWriter = new StreamWriter(this._httpContextAccessor.HttpContext.Response.Body);
//streamWriter.WriteLine($"{DateTime.Now} Adding response body");
//streamWriter.Flush();

//await streamWriter.WriteLineAsync($"{DateTime.Now} Adding response body");
//await streamWriter.FlushAsync();

//await this._httpContextAccessor.HttpContext.Response.BodyWriter.WriteAsync(Encoding.UTF8.GetBytes("Adding response body"));
//await this._httpContextAccessor.HttpContext.Response.BodyWriter.FlushAsync();

try
{
int level = 0;
Expand Down
4 changes: 4 additions & 0 deletions Samples/Sample.AspNetCore2.WebApi/Startup.cs
Expand Up @@ -29,6 +29,10 @@ public void ConfigureServices(IServiceCollection services)
//{"Endpoint Routing does not support 'IApplicationBuilder.UseMvc(...)'. To use 'IApplicationBuilder.UseMvc' set 'MvcOptions.EnableEndpointRouting = false' inside 'ConfigureServices(...)."}
services.AddMvc(options => options.EnableEndpointRouting = false);
services.AddOptions();
//services.Configure<IISServerOptions>(options =>
//{
// options.AllowSynchronousIO = true;
//});

services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();

Expand Down
6 changes: 2 additions & 4 deletions SdkCommon.csproj
Expand Up @@ -21,13 +21,11 @@
</ItemGroup>

<PropertyGroup Label="SDK Release Essential Info">
<SdkVersion>4.0.0</SdkVersion> <!-- Required: major.minor.patch -->
<SdkVersion>4.0.1</SdkVersion> <!-- Required: major.minor.patch -->
<SdkVersionSuffix></SdkVersionSuffix> <!-- Optional. Examples: alpha, beta, preview, RC etc. -->
<SdkLtsRelease>false</SdkLtsRelease> <!-- Optional. Examples: false (default) or true. -->
<SdkReleaseNotes> <!-- Required -->
- refactor: resolve GH#577 - Remove unnecessary explicit dependencies from the core Rollbar module
- refactor: resolve GH#576 - Move appsettings.json support into its own new module Rollbar.AppSettings.Json
- refactor: resolve GH#575 - Move app.config support into its own new module Rollbar.App.Config
- fix: Rollbar.NetCore.AspNet module: fixed incorrect assignment of captured HTTP response body
</SdkReleaseNotes>

<!--
Expand Down

0 comments on commit fc917de

Please sign in to comment.