-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#1252 Fix HttpContext in DelegatingHandler #1268
#1252 Fix HttpContext in DelegatingHandler #1268
Conversation
Conflicts: src/Ocelot/Requester/HttpClientBuilder.cs src/Ocelot/Requester/HttpClientWrapper.cs Cherry picked from ThreeMammals#1268
Hi J! I've merged latest top-commits from develop, resolved merge conflicts, fixed a few compile errors.
I believe a small fix in test setup section should fix the problem of 400 Bad Request. Could you have a look to it and fix the issue please? |
3222fe3
to
55d2738
Compare
@jlukawska |
public HttpClientWrapper(HttpClient client) | ||
public DelegatingHandler ClientMainHandler { get; } | ||
|
||
public HttpClientWrapper(HttpClient client, DelegatingHandler clientMainHandler) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not making clientMainHandler default null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or define new overloaded method version. 😉
@@ -34,7 +30,7 @@ public class DelegatingHandlerHandlerFactory : IDelegatingHandlerHandlerFactory | |||
_qoSFactory = qoSFactory; | |||
} | |||
|
|||
public Response<List<Func<DelegatingHandler>>> Get(DownstreamRoute downstreamRoute) | |||
public Response<List<Func<DelegatingHandler>>> Get(DownstreamRoute downstreamRoute, HttpContext httpContext) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public Response<List<Func<DelegatingHandler>>> Get(DownstreamRoute downstreamRoute, HttpContext httpContext) | |
public Response<IList<Func<DelegatingHandler>>> Get(DownstreamRoute downstreamRoute, HttpContext httpContext) | |
} | ||
|
||
return delegatingHandler; | ||
}).ToList(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}).ToList(); | |
}).ToArray(); | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you hate lists?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Array is more efficient than list on ram usage
One line definition of the auto-property
…have its default value null
b67123a
to
6a8822a
Compare
Build 2170 has been failed after last changes in Polly provider. @RaynaldM @jlukawska It seems we have to fix these tests:
All these tests belong to the ClaimsInDelegatingHandlerTests class. |
This PR was created 4 years ago and almost all modified files no longer exist. As I saw in #1252 there is another idea to solve this issue. I'm closing this PR for now. |
I understand your decision to close this PR. However, you are welcome to open a new PR if you wish to contribute. It is crucial to use the new code base from the development branch. The internal Ocelot system kernel underwent a redesign last year, and we need to devise a new solution or re-investigate the reported issue. |
Fixes #1252
The problem
After changes from fe3e8bd there is a new instance of
HttpContext
created for each request (or even more instances for aggregated routes). IfHttpContextAccessor
is used to obtain aHttpContext
instance in a delegating handler class, it will return the originalHttpContext
without e.g. authentication data that is added to the new instance.Proposed Changes
HttpContext
, a delegating handler class should implementIDelegatingHandlerWithHttpContext
interfaceDelegatingHandlerHandlerFactory
will add the validHttpContext
as a property to the delegating handler class