How to fix compressed Aggregates response? #1900
-
Expected BehaviorActual BehaviorWhen using request aggregation we are getting response which looks like it's compressed two times. When added Using Angular 7 HttpClient We cannot set Accept-Encoding because of 'Refused to set unsafe header "Accept-Encoding"'. Any suggestions, please? Thank you Specifications
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 2 replies
-
Hi, I've also faced the same issue which I reported below. Can you please provide solution for this issue |
Beta Was this translation helpful? Give feedback.
-
@LukasSefcik @philproctor , to fixed it you have two solutions :
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
request.Headers.AcceptEncoding.Clear();
request.Headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("deflate"));
request.Headers.AcceptEncoding.Add( new StringWithQualityHeaderValue("utf-8"));
request.Headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("br"));
return await base.SendAsync(request, cancellationToken);
}
|
Beta Was this translation helpful? Give feedback.
-
hi, I have a question about the request to aggregates from Angular CLI. |
Beta Was this translation helpful? Give feedback.
-
@fadem @LukasSefcik @ramesh26 |
Beta Was this translation helpful? Give feedback.
-
Here's more detail on solution 1 from @MSeifAllah. That solution is talking about a Delegating Handler in Ocelot. I preferred that because it didn't involve a bunch of custom C# code for each aggregate request. However, I don't know what the side effects might be as far as replacing gzip compression with other types of compression. Seems to work for my simple test, though. using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
...
public class NoGzipDelegatingHandler : DelegatingHandler
{
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
//Trying to avoid gzip encoding in the response, so selecting other compression algorithms
request.Headers.AcceptEncoding.Clear();
request.Headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("deflate"));
request.Headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("br"));
return await base.SendAsync(request, cancellationToken);
}
} Then in Startup.cs, you add your delegating handler as follows. (The boolean parameter on public void ConfigureServices(IServiceCollection services)
{
services.AddOcelot(Configuration)
.AddDelegatingHandler<NoGzipDelegatingHandler>(true);
} |
Beta Was this translation helpful? Give feedback.
@LukasSefcik @philproctor ,
I had the problem . You have the problem because the responses from Routes are
compressed ( Content-Encoding : gzip )
to fixed it you have two solutions :