-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat($http): add $xhrFactory service to enable creation of custom xhr objects #12159
Conversation
* @description | ||
* Factory function used to create XMLHttpRequest objects. | ||
* | ||
* Decorate this service to create your own custom XMLHttpRequest objects. |
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.
I would say: "Replace or decorate ..."
I've left a couple of comments regarding decorators usage, but otherwise it LGTM after taking a quick look. |
It's funny, my first thought was to do exactly like you suggested. Then for some reason I decided to only go for the decorator version. Anyways, I've updated the text and the example. |
@@ -46,7 +72,7 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc | |||
}); | |||
} else { | |||
|
|||
var xhr = createXhr(); | |||
var xhr = createXhr(method, url); |
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.
Just curious: Why are we passing the method
and URL
?
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.
We could pass more (essentially everything we've got here :-)). We can't really predict what people might need... The other approach would be to expose nothing by default and expand the API as soon as we've got more use cases.
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.
Not for us, but for the benefit of end users who will override the service. Let's say you want to use a custom object for certain urls only..
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.
I think method and url is a good middle ground to start with.
Wouldn't it make more sense for this to use the same mechanism as the httpInterceptors and the httpParamSerializers?
Having only one implementation per app might not be the best idea. |
@Narretz you will have one xhrObject pr request. The xhrFactory will be called for each request and should return a unique xhrObject every time. It will also be called with the method and the url as parameters so you could customise it to only add certain features for certain urls. But still, you can't have a separate implementation of the factory for each request, so this implementation only solves the Firefox issue, it doesn't seem like a good solution to the progress listener case. |
IMO we shouldn't try to fix progress events here, it is a separate issue. And IMO we shouldn't try to have a factory per-request - this is what we've discussed during a meeting: adding per-request handling will add one more param to the $http's object and this is the very issue we wanted to avoid |
Any update on the status of this PR? Anything else I need to do? |
This one LGTM, I'm +1 for merging this as-is. @petebacondarwin @caitp @Narretz - any objections? |
* @description | ||
* Factory function used to create XMLHttpRequest objects. | ||
* | ||
* Replace or decorate this service to create your own custom XMLHttpRequest objects. |
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.
This affects $http and $resource requests alike, right? (since resource uses http). We should probably note this here.
Still not a big fan of this solution, since it's at odds with the way we do other things for $http. @petebacondarwin to the rescue! |
@Narretz do you have a better suggestion for how we could deal with this? |
@petebacondarwin I was thinking more about how the paramSerializers are implemented. This would bea) more consistent and b) more flexible. But since I don't know if this per-request flexibility is actually needed, let's just merge it once with switch to 1.5 and then see if somebody needs the flexibility. |
Extract the createXhr function into a service called $xhrFactory which can easily be decorated to be able to construct non-standard or customised XMLHttpRequest objects. This is required for use of the mozAnon and mozSystem options for FirefoxOS.
See https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest#XMLHttpRequest() for details.
Alternate solution to PR #9319
Closes #2318