Repository navigation
Closed
Labels
area: common/httpIssues related to HTTP and HTTP ClientfeatureLabel used to distinguish feature request from other issuesfreq2: mediumstate: has PR
Milestone
Description
I'm submitting a...
[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
Currently when using a http interceptor you cannot pass meta data about the request to the interceptor
Expected behavior
To be able to pass random data to the http interceptor. Currently the options object is so strongly typed that you cannot pass extra data to it. The proposal would be to add a meta (name needs bikeshedding) property with type any to the http request options that can be used for this purpose.
Minimal reproduction of the problem with instructions
N/A
What is the motivation / use case for changing the behavior?
// tell a caching interceptor to only cache if this is true
this.http.get('/path', {meta: {cache: true}})
// tell an interceptor not to add the `Authorization` for this request only
this.http.get('/path', {meta: {skipAuthorization: true}})
Environment
Angular version: 4.3.0
Browser:
- [x] Chrome (desktop) version 59
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
Others:
Reacted by Trotyl Yu, JB Nizet, Cédric Exbrayat, BenjaminDaRos, Johan, Sean G. Wright, Michael Dudek, Agrumas, Ma Vo, Sergey Vohmyanin and 206 more
Reacted by Mario-Eis, Maxime, Anton Gildebrand, Kumar Gandhi Koppolu, Haoliang Wu, nulltrim, Eunwoo Cho, Bernhard Fuchs, Mariano Alvarez, Rafa SA and 22 more
Metadata
Metadata
Assignees
Labels
area: common/httpIssues related to HTTP and HTTP ClientfeatureLabel used to distinguish feature request from other issuesfreq2: mediumstate: has PR
Activity
jnizet commentedon Jul 17, 2017
This would also be very useful for generic error interceptors:
I see plenty of use-cases for this, and it was something possible in AngularJS using the options object.
alxhub commentedon Jul 19, 2017
This has been on my mind as well. I think it's a good idea and something we should implement.
mattlewis92 commentedon Jul 19, 2017
@alxhub awesome! What do you think of the proposed API, can you think of anything better? I'd love to take a go at a PR for this 😀
alxhub commentedon Jul 25, 2017
@mattlewis92 I like
meta(or possiblymetadata) as the key. In keeping with the theme forHttpRequestandHttpResponseit should also be immutable a laHttpHeaders/HttpParams.I have an open task to merge the implementation of the two by extracting out a generic immutable map type. Once this is done,
HttpMetadatacould easily be built on top of that type.mattlewis92 commentedon Jul 25, 2017
Ah ok I'll leave that to you to implement then 😄
Agrumas commentedon Aug 18, 2017
Is there any neat workaround for this? I am thinking about extending
HttpRequest, however, overloaded constructors make implementation complicated.ChristianUlbrich commentedon Aug 30, 2017
@Agrumas You could abuse HttpHeaders. Set them on your request with a nice name e.g.
X-META-DATAand then strip them in the interceptor from the actual request before it gets send and re-add them on response. That way I plan to enable disabling individual interceptors on a per-request basis, e.g. for toggling a global LoadingNotification. But of course this feature needs to be added - because it has so many use cases.alxhub commentedon Aug 30, 2017
I have an in-progress branch for this, but it's unlikely to land before 5.0. Probably coming in 5.1.
jbojcic1 commentedon Oct 14, 2017
sinedied commentedon Nov 6, 2017
Really disappointed that with the release of Angular 5, the team deprecated the
Httpservice without providing any way to perform withHttpClientwhat was possible withHttp, including custom parameters.We currently extends the
Httpservice and added with 2 extra parameters toRequestOptionsArgs, for common use cases already cited here such as caching requests and error handling (see https://github.com/ngx-rocket/starter-kit/blob/master/src/app/core/http/http.service.ts for details).We would like to move to
HttpClient, but we cannot use interceptors because they do not support custom arguments, and we cannot extendHttpClienteither because therequest()method options do not use a type we can extend, see https://github.com/angular/angular/blob/master/packages/common/http/src/client.ts#L76-L83So basically we are stuck with a deprecated API, and no way to move forward, am I missing something here @alxhub ?
karptonite commentedon Nov 6, 2017
@sinedied I've been using HttpClient and adding metadata by abusing HTTP Headers, as suggested here.
In practice, it looks like this:
sinedied commentedon Nov 6, 2017
@karptonite I saw the comment on this, but this is really a ugly hack and I would like to avoid those while promoting best practices in our generator 😉
karptonite commentedon Nov 6, 2017
@sinedied It isn't pretty, but I've seen far uglier hacks. You can extract out the addition of the headers into a utility function so that when the metadata is added for real, you only have to fix it in a couple places. Anyway, you aren't stuck with a deprecated (but not yet removed) API--you have at least one option.
67 remaining items
maxandriani commentedon Nov 17, 2020
@alxhub Is there something we can do to Help on this issue? I saw there is an PR that you was involved that looks great. Why you guys can not aprove it? I know there is a issue about patterns that should be argued. But we live on agile environment w/ incremental features. You can release a initial version and fix it as the problem happens.
sebastian-zarzycki-apzumi commentedon Nov 17, 2020
Operation Byelog eh? I'm sorry to be harsh, but if Angular team is focusing on pretty minor (nowadays cpu/internet performance considered) speed/size improvements and dances around engines and compilers for another couple years, rather that adding meaningful features, then something is way off balance there.
jcimoch commentedon Nov 17, 2020
@sebastian-zarzycki-es I have exactly the same feeling over years of using angular. It seems like there are couple of people that are fascinated over compilers, performance, alogrithms but not interested in making usefull framework solving real business problems. Maybe if angular compiler wasn't over engineered in the first place (because AOT in its initial format bascially has taken best advantages of dynamic javascript environment in favour of some perfomances gains which were at the best only close to react performance which is fully runtime based). Now with ivy we are bringing back basic stuff like using arrow function were I want and not were angular compiler allows... or dynamically create/load component fetched from resource out of the project, this wasn't possible in any reasonable way before. So we are solving issues that we created and were solved long time ago, even in angularjs.
Something is way off balance there as you said.
CesarD commentedon Nov 18, 2020
marcschroeder commentedon Jan 16, 2021
@alxhub is there anything we can do to support you on this issue? Who of the core team is assigned to this? I feel like there have been plenty of people offering there help over the past three years that this issue is open. This is a non-breaking change, right? What can we do to get this into the next minor release?
imaksp commentedon Jan 16, 2021
As per this comment (on related PR) from angular team member this is not coming anytime soon as it requires code refactoring in core:
#20579 (comment)
But 'InterceptorSkipHeader' (although not the best) solution is working fine for me.
alxhub commentedon Feb 2, 2021
For anyone keeping up with this issue, discussions on PR #25751 have converged on a simple and straightforward design which we hope to be able to land in the next couple days :)
sebastian-zarzycki-apzumi commentedon Feb 2, 2021
4 years of waiting for a change of heart (for the context to be mutable) to eventually implement a simple typed map. Oh, the Angular team, you never cease to amaze me :)
(still, thanks for this)
jcimoch commentedon Feb 2, 2021
alxhub commentedon Mar 19, 2021
Closing as fixed in #25751 (will land in 12!)
CesarD commentedon Mar 23, 2021
Will we have to wait until Angular 12 to make use of this? That's around May, isn't it?
angular-automatic-lock-bot commentedon Apr 23, 2021
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.