Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

feat($http): add option for unsafe xhr requests in FirefoxOS #7903

Closed
wants to merge 1 commit into from

Conversation

amccausl
Copy link

Previously, it was not possible to pass settings to the constructor of the XMLHttpRequest. This
adds an optional config property xhrConfig to the $http constructor, allowing us to do so. 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.

Closes #2318

@amccausl amccausl added cla: yes and removed cla: no labels Jun 19, 2014
@@ -8,7 +8,7 @@ function createXhr(method) {
!window.XMLHttpRequest)) {
return new window.ActiveXObject("Microsoft.XMLHTTP");
} else if (window.XMLHttpRequest) {
return new window.XMLHttpRequest();
return new window.XMLHttpRequest(config);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will possibly cause IDL arity errors in other browsers...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not chromium at least =) a lot of the blink bindings will throw when the arity does not match though.... Guess that doesn't apply to constructors

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know that was a thing :(. Better safe than sorry, so have updated. Thanks for the feedback :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nah I wouldn't worry about it if tests are passing

Previously, it was not possible to pass settings to the constructor of the XMLHttpRequest.  This
adds an optional config property `xhrConfig` to the $http constructor, allowing us to do so.  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.

Closes angular#2318
@caitp
Copy link
Contributor

caitp commented Jun 19, 2014

Related jQuery bug http://bugs.jquery.com/ticket/13394 (their resolution doesn't really apply here since we don't have a similar mechanism yet)

@caitp
Copy link
Contributor

caitp commented Jun 19, 2014

Anyways, we probably should have something like xhrFields in angular, instead of solving this this way. I'll see what people think about that, I guess.

@sjurba
Copy link
Contributor

sjurba commented Jun 19, 2014

Oh.. Damit.. Didn't see this before I just submitted my own pull request #7906. Sorry for the duplicate. We have actually made quite identical solutions. Only difference I can see is that I called it xhrFields like jQuery and that I added support for setting it on the $http.defaults object. I also added some tests and updated the documentation.

@caitp
Copy link
Contributor

caitp commented Jun 19, 2014

The jQuery xhrFields stuff is a bit different, though --- they don't pass the object to the constructor, but instead this: https://github.com/jquery/jquery/blob/01c360f96390ff16edfe65ef3b34e167087ef645/src/ajax/xhr.js#L51-L55

@caitp
Copy link
Contributor

caitp commented Jun 19, 2014

I think we need something like that, as well as a way to have defaults which are applied to all XHR objects, as well as per-request xhrFields, similar to our headers strategy. That would make more sense IMO.

@sjurba
Copy link
Contributor

sjurba commented Jun 19, 2014

The problem with that approach is that it doesn't actually work since the mozSystem property is read-only and cannot be set except through the constructor. (On Firefox OS)

@caitp
Copy link
Contributor

caitp commented Jun 19, 2014

That sounds like a bug you should file on b2g, because the problem with this is that the XHR constructor isn't normally supposed to take any parameters, but if one extension to it wants to add custom parameters, what if another one does too which behaves differently? The whole thing is a mess.

Anyways, this is the solution suggested by the jQuery team, so it was probably valid and tested at some point.

@sjurba
Copy link
Contributor

sjurba commented Jun 19, 2014

Yes, you I right. And I agree that it would be a better solution. I'm double-checking my statement and will check if making a jQuery ajax request actually works on Firefox OS. I'll post back with my findings.

@amccausl
Copy link
Author

I'm happy with changes from #7906. Not sure what the protocol is now that discussion is here, but will happily close this PR or give @sjurba access to update the branch behind this PR with his change.

Great work @sjurba :)

@sjurba
Copy link
Contributor

sjurba commented Jun 19, 2014

I have verified my findings. It doesn't work with the current implementation by jQuery either. This is also backed up by this bug report: http://bugs.jquery.com/ticket/13862.
Here they actually suggest several different workarounds, all of which rely on the xhr config param (http://api.jquery.com/jquery.ajax/) which basically is an option to override the xhr constructor function:
https://github.com/jquery/jquery/blob/01c360f96390ff16edfe65ef3b34e167087ef645/src/ajax/xhr.js#L22

Don't know if that is something you guys would consider as well. It would sure make mocking the XMLHttpRequest object a lot simpler..

@sjurba
Copy link
Contributor

sjurba commented Jul 10, 2014

@caitp: So it seems this one stalled since passing arguments to a constructor that is not supposed to take one is a bad idea and should really be fixed by Mozilla B2G. But maybe you would be willing to accept a workaround that lets you pass in your own createXhr method instead. In other words the same thing jQuery offers with its xhr parameter: http://api.jquery.com/jquery.ajax/

If so I could probably make a PR for it.

@caitp
Copy link
Contributor

caitp commented Jul 10, 2014

I don't see a problem with allowing custom createXhr()

@Narretz Narretz added this to the Ice Box milestone Jul 17, 2014
@ripper2hl
Copy link

hello, change jquery to angular in my application, but do not know how this property is added to the service $http, was something in jquery:
var xhr = new XMLHttpRequest({mozSystem: true});

my english is bad.

@caitp
Copy link
Contributor

caitp commented Jul 24, 2014

@ripper2hl there's no way in angular to do this currently... I guess I could submit a patch for it... but frankly the B2G people should just get their act together and not use a different function signature from the interoperable XHR api

@ripper2hl
Copy link

It is sad to know that the standard is not followed, if you send the patch would be a great help, thanks for the information.

@sjurba
Copy link
Contributor

sjurba commented Jul 24, 2014

I started on a fix here: https://github.com/sjurba/angular.js/tree/createXhr

The implementation is simple enough, but it kinda cries for some refactoring.. But I'm not quite sure how to approach that. What's best for you? Should I just create a pull request for what I got so far and start a discussion there?

@Narretz
Copy link
Contributor

Narretz commented Sep 28, 2014

@sjurba Sorry for the late response, but yes, sending a PR is a good idea

@sjurba
Copy link
Contributor

sjurba commented Sep 28, 2014

No worries. I've been busy elsewhere.. I'll dig back into it later this evening/afternoon.. —
Sjur

On Sun, Sep 28, 2014 at 1:42 PM, Narretz notifications@github.com wrote:

@sjurba Sorry for the late response, but yes, sending a PR is a good idea

Reply to this email directly or view it on GitHub:
#7903 (comment)

@sjurba
Copy link
Contributor

sjurba commented Sep 28, 2014

Ok, PR #9319 is sent..

@pkozlowski-opensource
Copy link
Member

This one looks a lot like #7906 and that one was closed in favour of the more generic approach. Currently we've got a PR for a more flexible approach (#9319) but I'm not super-happy with it either...

Anyway, closing this one as almost identical #7906 was closed. Let's focus on solving it in a more flexible way.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mozSystem parameter for window.XMLHttpRequest on FirefoxOS
6 participants