Closed
Bug 955953
Opened 11 years ago
Closed 11 years ago
FxAccountsClient should set Accept-Language header on all server calls
Categories
(Firefox :: Firefox Accounts, defect)
Tracking
()
RESOLVED
FIXED
Firefox 30
People
(Reporter: spenrose, Assigned: spenrose)
References
Details
Attachments
(1 file, 3 obsolete files)
3.71 KB,
patch
|
rnewman
:
review+
jedp
:
feedback+
|
Details | Diff | Splinter Review |
Assignee | ||
Updated•11 years ago
|
Summary: FxAccountsClient should set Accept-Language header on server calls that trigger emails → FxAccountsClient should set Accept-Language header on all server calls
Assignee | ||
Updated•11 years ago
|
Assignee: nobody → spenrose
Assignee | ||
Comment 1•11 years ago
|
||
A dirt-simple patch that reads the general.useragent.locale pref and sets the Accept-Language header accordingly.
Attachment #8355314 -
Flags: feedback?(zack.carter)
Comment 2•11 years ago
|
||
Again, is this for Desktop or Android or both?
Comment 3•11 years ago
|
||
Comment on attachment 8355314 [details] [diff] [review]
955953_v0.1.patch
Review of attachment 8355314 [details] [diff] [review]:
-----------------------------------------------------------------
::: services/fxaccounts/FxAccountsClient.jsm
@@ +328,5 @@
> });
> xhr.setRequestHeader("authorization", header.field);
> }
>
> + let locale = Services.prefs.getCharPref("general.useragent.locale");
general.useragent.locale might be set to something weird for people that spoof their User-Agent header. nsHttpHandler [1] gets its accepted languages from intl.accept_languages.
In order to read that pref correctly you'd need to use Services.prefs.getComplexValue("intl.accept_languages", Ci.nsIPrefLocalizedString).data.
[1] https://mxr.mozilla.org/mozilla-central/source/netwerk/protocol/http/nsHttpHandler.cpp#1274
@@ +329,5 @@
> xhr.setRequestHeader("authorization", header.field);
> }
>
> + let locale = Services.prefs.getCharPref("general.useragent.locale");
> + if (!!locale) {
if (locale) is sufficient.
Attachment #8355314 -
Flags: feedback-
Assignee | ||
Updated•11 years ago
|
Assignee | ||
Comment 5•11 years ago
|
||
Per ttaubert's feedback I read a different preference, and moved it to where the HTTP object is currently assembled.
Attachment #8355314 -
Attachment is obsolete: true
Attachment #8355314 -
Flags: feedback?(zack.carter)
Attachment #8376594 -
Flags: feedback?(jparsons)
Assignee | ||
Comment 6•11 years ago
|
||
Now with actual patch.
Attachment #8376594 -
Attachment is obsolete: true
Attachment #8376594 -
Flags: feedback?(jparsons)
Attachment #8376601 -
Flags: feedback?(jparsons)
Comment 7•11 years ago
|
||
Comment on attachment 8376601 [details] [diff] [review]
955953_v0.2.patch
Review of attachment 8376601 [details] [diff] [review]:
-----------------------------------------------------------------
Hrm ... I'm getting a failure. It doesn't like that indexOf test:
0:23.86 TEST-UNEXPECTED-FAIL | /Users/zeus/code/firefox/build_inbound/_tests/xpcshell/services/common/tests/unit/test_restrequest.js | -1 != -1 - See following stack:
JS frame :: /Users/zeus/code/firefox/build_inbound/_tests/xpcshell/services/common/tests/unit/test_restrequest.js :: test_hawk_authenticated_request/server<["/elysium"] :: line 888
JS frame :: resource://testing-common/httpd.js :: ServerHandler.prototype.handleResponse :: line 2374
JS frame :: resource://testing-common/httpd.js :: Connection.prototype.process :: line 1225
JS frame :: resource://testing-common/httpd.js :: RequestReader.prototype._handleResponse :: line 1679
JS frame :: resource://testing-common/httpd.js :: RequestReader.prototype._processBody :: line 1527
JS frame :: resource://testing-common/httpd.js :: RequestReader.prototype.onInputStreamReady :: line 1395
native frame :: <unknown filename> :: <TOP_LEVEL> :: line 0
and since it fails, it returns a 500, so the following is kind of superfluous:
0:23.89 TEST-UNEXPECTED-FAIL | /Users/zeus/code/firefox/build_inbound/_tests/xpcshell/services/common/tests/unit/test_restrequest.js | 200 == 500 - See following stack:
JS frame :: /Users/zeus/code/firefox/build_inbound/_tests/xpcshell/services/common/tests/unit/test_restrequest.js :: onComplete :: line 902
JS frame :: resource://services-common/rest.js :: onStopRequest :: line 459
native frame :: <unknown filename> :: <TOP_LEVEL> :: line 0
Attachment #8376601 -
Flags: feedback?(jparsons)
Assignee | ||
Comment 8•11 years ago
|
||
Hhmm. I'm only doing indexOf to work around black-box rewriting of the value. Also it Works On My Box™ . Maybe I'll switch to a regular expression as see if that passes for you.
Comment 9•11 years ago
|
||
You might initially set the pref to a value you control and that is highly unlikely to be a default. This way I think you'll also be able to save yourself the regex tests, as it seems you and I have different whitespace in our prefs for some reason; there could be other differences with other testers, I imagine.
So for example:
let str = Cc['@mozilla.org/supports-string;1'].createInstance(Ci.nsISupportsString);
// Set the accept-languages pref to the Nepalese dialect of Zulu, falling back
// on Volapük where that is not available.
str.data = 'zu-NP;vo';
Services.prefs.setComplexValue('intl.accept_languages', Ci.nsISupportsString, str);
// ... do some tests ...
// at the end of the tests, restore defaults
Services.prefs.resetUserPrefs();
// maybe a sanity check to be sure that got changed back
let pref = Services.prefs.getComplexValue('intl.accept_languages', Ci.nsIPrefLocalizedString);
do_check_neq(str.data, pref.data);
Assignee | ||
Comment 10•11 years ago
|
||
Followed suggestion in comment #9, with slight tweaks. Who shall we ask to review this?
Attachment #8376601 -
Attachment is obsolete: true
Attachment #8376833 -
Flags: feedback?(jparsons)
Comment 11•11 years ago
|
||
Tests look good to me with this tweak.
Perhaps rnewman would be a good one to review this?
Assignee | ||
Updated•11 years ago
|
Attachment #8376833 -
Flags: review?(rnewman)
Updated•11 years ago
|
Attachment #8376833 -
Flags: feedback?(jparsons) → feedback+
Comment 12•11 years ago
|
||
Comment on attachment 8376833 [details] [diff] [review]
955953_v0.4.patch
Review of attachment 8376833 [details] [diff] [review]:
-----------------------------------------------------------------
This is simple, which is nice.
I don't like that we attach A-L on every authenticated request -- it's wasteful. I do understand why, though.
I'm assuming that this prefs hit is cheap enough to do on every request without caching and using an observer to invalidate the cache. (I could imagine that this more complex access to prefs is less cheap than usual.) If you can spend two minutes to add a couple of log statements and verify that during a sync, please do.
Thanks for the test!
::: services/common/rest.js
@@ +788,5 @@
> + if (acceptLanguage) {
> + this.setHeader("Accept-Language", acceptLanguage);
> + }
> + } catch (err) {
> + this._log.error("Error reading intl.accept_languages pref: " + CommonUtils.exceptionStr(err));
Concern: if this fails once, it'll probably fail over and over again, spamming the shit out of the user's console and sync log. Please add a flag in an outer scope to ensure that this only logs once per session, and update the log message accordingly.
(Even better if we skip doing the work altogether if it ever failed!)
Attachment #8376833 -
Flags: review?(rnewman) → review+
Comment 13•11 years ago
|
||
Perhaps in a follow-up bug we could read the pref the first time a RESTRequest is instantiated, and then subsequently only when we observe "nsPref:changed" for this pref? That would also take care of the potential log spam on error.
Comment 14•11 years ago
|
||
(In reply to Jed Parsons (use needinfo, please) [:jedp, :jparsons] from comment #13)
> Perhaps in a follow-up bug we could read the pref the first time a
> RESTRequest is instantiated, and then subsequently only when we observe
> "nsPref:changed" for this pref? That would also take care of the potential
> log spam on error.
WFM.
Comment 15•11 years ago
|
||
I've filed Bug 974990 for the follow-up.
Sam, do you have time to address :rnewman's suggestion from Comment 12? I'd be happy to tweak your patch and check it in for you if you don't have time.
Flags: needinfo?(spenrose)
Assignee | ||
Comment 16•11 years ago
|
||
Yeah, let's leave it on my plate for now
Flags: needinfo?(spenrose)
Assignee | ||
Updated•11 years ago
|
Keywords: checkin-needed
Comment 17•11 years ago
|
||
Updated•11 years ago
|
Status: NEW → ASSIGNED
Component: Identity → FxA
Comment 18•11 years ago
|
||
Status: ASSIGNED → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Whiteboard: [fixed-in-fx-team]
Target Milestone: --- → mozilla30
Updated•7 years ago
|
Product: Core → Firefox
Updated•7 years ago
|
Target Milestone: mozilla30 → Firefox 30
You need to log in
before you can comment on or make changes to this bug.
Description
•