Closed
Bug 1278275
Opened 8 years ago
Closed 8 years ago
Headers.get should incorporate getAll behaviour
Categories
(Core :: DOM: Core & HTML, defect)
Core
DOM: Core & HTML
Tracking
()
RESOLVED
FIXED
mozilla52
Tracking | Status | |
---|---|---|
firefox52 | --- | fixed |
People
(Reporter: jdm, Assigned: saurabhs, Mentored)
References
Details
(Keywords: dev-doc-complete, site-compat, Whiteboard: [lang=c++] btpp-backlog)
Attachments
(1 file, 6 obsolete files)
23.08 KB,
patch
|
bkelly
:
review+
|
Details | Diff | Splinter Review |
It appears our implementation of the Headers interface is out of date with the specification. We have an extra getAll method which isn't present upstream, and our get method returns the first header that matches, rather than the combined value of all matching headers.
Specification:
https://fetch.spec.whatwg.org/#dom-headers-get
Code: dom/webidl/Headers.webidl, dom/fetch/Headers.h, dom/fetch/InternalHeaders.cpp
Tests:
./mach mochitest dom/tests/mochitest/fetch/
* this directory contains tests that will need to be updated
./mach web-platform testing/web-platform/fetch/api/headers/
* these tests should show unexpected results after changing the code; the results will need to be updated in testing/web-platform/meta/fetch/api/headers/
Reporter | ||
Updated•8 years ago
|
Summary: Headers.get should incorporate getAll behaviour to match spec → Headers.get should incorporate getAll behaviour
Reporter | ||
Updated•8 years ago
|
Mentor: josh
Updated•8 years ago
|
Whiteboard: [lang=c++] → [lang=c++] btpp-backlog
Assignee | ||
Comment 1•8 years ago
|
||
Hi, I would like to tackle this bug. Need some info about what the Headers interface is all about. Also, how can I get the source code?
Thanks.
Reporter | ||
Comment 2•8 years ago
|
||
You'll need to follow the instructions at https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Build_Instructions/Simple_Firefox_build for getting the code and compiling it. https://developer.mozilla.org/en-US/docs/Web/API/Headers should be able to explain what you want to know about the Headers interface.
Assignee | ||
Comment 3•8 years ago
|
||
Thanks Josh. I will start now.
Comment 4•8 years ago
|
||
Hi Josh, So are you planning to completely remove GetAll function because I tried doing that and it creates lots of other issues so I was thinking that we could keep the GetAll function and just change get definition, which says all the name values must be separated by commas.
Flags: needinfo?(josh)
Comment 5•8 years ago
|
||
This patch fixes the functionality of get Function, now we are appending all the fetched values to result.
Attachment #8773840 -
Flags: review?(josh)
Assignee | ||
Comment 6•8 years ago
|
||
I am already working on this issue and I have got the code to compile after removing the GetAll method everywhere it is accessed. Tests still need to be modified.
Reporter | ||
Comment 7•8 years ago
|
||
Comment on attachment 8773840 [details] [diff] [review]
patch.diff
I'm clearing review on this for the time being, since Saurabh was working on this already.
Flags: needinfo?(josh)
Attachment #8773840 -
Flags: review?(josh)
Comment 8•8 years ago
|
||
(In reply to Josh Matthews [:jdm] from comment #7)
> Comment on attachment 8773840 [details] [diff] [review]
> patch.diff
>
> I'm clearing review on this for the time being, since Saurabh was working on
> this already.
yeah sure I submitted a patch as I saw no activity on this bug from long time. As Saurabh he is working on it still I could delete my patch.
Assignee | ||
Comment 9•8 years ago
|
||
Hi Josh, on running
./mach mochitest dom/tests/mochitest/fetch/test_fetch_app_protocol.html
I am getting TypeError: navigator.mozApps is undefined
I tried reading up on mozApps but couldn't find anything related to the problem. How can I solve this issue? Also, how is navigator.mozApps defined for the test environment?
Reporter | ||
Comment 10•8 years ago
|
||
You can ignore that failures - it is automatically skipped in non-Firefox OS build environments (since navigator.mozApps is a Firefox OS API). Update the test as best you can, and we'll run it against our CI system to ensure that it passes.
Reporter | ||
Comment 11•8 years ago
|
||
Oh, and in the sharing how I knew this, I looked at mochitest.ini in the same directory and read the `skip-if` conditions for that particular test file.
Assignee | ||
Comment 12•8 years ago
|
||
Attachment #8780790 -
Flags: review?(josh)
Reporter | ||
Comment 13•8 years ago
|
||
Comment on attachment 8780790 [details] [diff] [review]
HeadersgetAll.patch
Review of attachment 8780790 [details] [diff] [review]:
-----------------------------------------------------------------
Great work! I'd like to see a new patch that includes the API suggestions I've made; I think it will reduce the number of changes that are required. Please also add a commit messages like "Bug 1278275 - Update Headers::GetAll and Headers::Get to match the specification. r=jdm".
::: dom/cache/AutoUtils.cpp
@@ +263,5 @@
>
> ErrorResult headerRv;
> nsAutoCString value;
> + nsTArray<nsCString> values;
> + requestHeaders->GetAll(header, values, headerRv);
Let's add a GetFirst C++ API so we don't duplicate this pattern in many places. That should let us get rid of GetAll, too.
::: dom/fetch/FetchDriver.cpp
@@ +339,5 @@
> mRequest->GetBody(getter_AddRefs(bodyStream));
> if (bodyStream) {
> nsAutoCString method;
> mRequest->GetMethod(method);
> + nsAutoCString aValue;
The `a` prefix is used for arguments; this should be called contentTypeValue.
::: dom/fetch/InternalHeaders.cpp
@@ +86,5 @@
> if (IsInvalidName(lowerName, aRv)) {
> return;
> }
>
> + const char* delimiter = ", ";
The specification says there should be no space after ,: https://fetch.spec.whatwg.org/#concept-header-value-combined
@@ +93,3 @@
> for (uint32_t i = 0; i < mList.Length(); ++i) {
> if (lowerName == mList[i].mName) {
> + if( firstValueFound ) {
nit: use `if (firstValueFound) {`
@@ +100,5 @@
> }
> }
>
> // No value found, so return null to content
> + if(aValue.IsEmpty()) {
nit: space after if
@@ +363,4 @@
> MOZ_ASSERT(!result.Failed());
>
> AutoTArray<nsCString, 5> exposeNamesArray;
> + nsAutoCString aValue;
This should be called exposedNamesValue.
::: testing/web-platform/meta/fetch/api/headers/headers-combine.html.ini
@@ +5,3 @@
>
> [Check append methods when called with already used name]
> + expected: PASS
This file can be removed now; the default state is pass for all tests if no ini file is present.
Attachment #8780790 -
Flags: review?(josh) → feedback+
Reporter | ||
Updated•8 years ago
|
Assignee: nobody → singhal.saurabh.mnnit
Assignee | ||
Comment 14•8 years ago
|
||
Thanks for the review Josh. I will fix the outstanding issues soon.
Assignee | ||
Comment 15•8 years ago
|
||
(In reply to Josh Matthews [:jdm] (away until 9/3) from comment #13)
> Let's add a GetFirst C++ API so we don't duplicate this pattern in many
> places. That should let us get rid of GetAll, too.
This piece of code uses GetAll:
dom/cache/AutoUtils.cpp:
AutoTArray<nsCString, 16> varyHeaders;
ErrorResult rv;
cachedResponseHeaders->GetAll(NS_LITERAL_CSTRING("vary"), varyHeaders, rv);
MOZ_ALWAYS_TRUE(!rv.Failed());
// Assume the vary headers match until we find a conflict
bool varyHeadersMatch = true;
for (uint32_t j = 0; j < varyHeaders.Length(); ++j) {
I don't think we can get rid of GetAll.
Assignee | ||
Comment 16•8 years ago
|
||
Addressing review comments from jdm@
Attachment #8780790 -
Attachment is obsolete: true
Attachment #8786799 -
Flags: review?(josh)
Assignee | ||
Comment 18•8 years ago
|
||
Hey Josh, is there anything else that needs to be fixed in the latest patch?
Reporter | ||
Comment 19•8 years ago
|
||
Comment on attachment 8786799 [details] [diff] [review]
HeadersgetAll.patch
Review of attachment 8786799 [details] [diff] [review]:
-----------------------------------------------------------------
Looks great! Sorry about the delay; I was on vacation last week and Monday was a Canadian holiday.
Attachment #8786799 -
Flags: review?(josh) → review+
Reporter | ||
Comment 20•8 years ago
|
||
Saurabh, do you have access to the tryserver to run the automated testsuite against these changes? If not, please follow the steps at https://www.mozilla.org/hacking/committer/ and I'll vouch for you.
Flags: needinfo?(singhal.saurabh.mnnit)
Assignee | ||
Comment 21•8 years ago
|
||
I don't know about tryserver. I will follow the link you have given.
Assignee | ||
Updated•8 years ago
|
Flags: needinfo?(singhal.saurabh.mnnit)
Assignee | ||
Comment 22•8 years ago
|
||
I have filed BUG1301685 for commit access to the tryserver.
Assignee | ||
Comment 25•8 years ago
|
||
Pushed the changes to the try server: ./mach try -b d -p all -u saurabh dom/tests/ testing/web-platform/tests/dom/
Assignee | ||
Comment 26•8 years ago
|
||
Results are here : https://treeherder.mozilla.org/#/jobs?repo=try&revision=c5dd2d6069c5
Reporter | ||
Comment 27•8 years ago
|
||
Unfortunately, `./mach try` doesn't understand directories like that, I believe. We ended up only testing subsets of a bunch of different test suites. Let's use the following syntax instead (obtained from selecting all the mochitest-N, e10s-mochitest-N, web-platform-test-N, and e10s-web-platform-test-N entries):
./mach try -b do -p linux,linux64,macosx64,win32,win64 -u mochitest-1,mochitest-2,mochitest-3,mochitest-4,mochitest-5,mochitest-e10s-1,mochitest-e10s-2,mochitest-e10s-3,mochitest-e10s-4,mochitest-e10s-5,web-platform-tests-1,web-platform-tests-2,web-platform-tests-3,web-platform-tests-4,web-platform-tests-5,web-platform-tests-6,web-platform-tests-7,web-platform-tests-8,web-platform-tests-e10s-1,web-platform-tests-e10s-2,web-platform-tests-e10s-3,web-platform-tests-e10s-4,web-platform-tests-e10s-5,web-platform-tests-e10s-6,web-platform-tests-e10s-7,web-platform-tests-e10s-8 -t none
Flags: needinfo?(singhal.saurabh.mnnit)
Reporter | ||
Comment 28•8 years ago
|
||
For the record, I used http://trychooser.pub.build.mozilla.org/ to create that syntax.
Assignee | ||
Comment 29•8 years ago
|
||
Thanks Josh. I scheduled the tests again. But, it looks like this time my changes were not pushed. The command says this:
remote: added 1 changesets with 0 changes to 0 files (+1 heads)
How can I push my changes?
Flags: needinfo?(singhal.saurabh.mnnit) → needinfo?(josh)
Reporter | ||
Comment 30•8 years ago
|
||
Was there a link to treeherder as part of the output? I am not surprised by the "1 changesets with 0 changes", since no code changed since your previous push - only one extra commit with the trychooser syntax as the commit message.
Flags: needinfo?(josh)
Reporter | ||
Comment 31•8 years ago
|
||
Looks like https://treeherder.mozilla.org/#/jobs?repo=try&revision=9c8e25f06f93e02aac5bdd503105043e30edeceb is the correct one.
Assignee | ||
Comment 32•8 years ago
|
||
Oh ok. Yes that is the one. I will look at the results.
Assignee | ||
Comment 33•8 years ago
|
||
Hi Josh. I was debugging this failure: https://treeherder.mozilla.org/#/jobs?repo=try&revision=9c8e25f06f93e02aac5bdd503105043e30edeceb&selectedJob=27719108&filter-searchStr=e7d624b19ab4d63b029b64af1514107b91eee896
I am unable to understand what the test is doing. Can you give me some pointers?
Flags: needinfo?(josh)
Reporter | ||
Comment 34•8 years ago
|
||
Oh, wow. I read your patch over and over, and read the test over and over, and I had to step through the code in a debugger to figure out what was happening. test_fetch_event.html tests various interactions with a service worker which intercepts network requests and provides responses. That means that the XHR to "empty-header" is intercepted in fetch_event_worker.js, which then calls Headers.get looking for the header named "emptyheader" that was originally set on the XHR. Previously, this would return the empty string because Headers.get used to return the first value that matched the requested header name. Now, we return null because Headers.get checks whether the final combined header value is empty. We need to modify the check in Headers.get to only return null if !firstValueFound. Does that make sense?
Flags: needinfo?(josh)
Assignee | ||
Comment 35•8 years ago
|
||
Thanks Josh for debugging this. Your explanation makes sense.
How did you attach a debugger to the test? This is not working for me: sudo gdb ./mach mochitest dom/workers/test/serviceworkers/test_fetch_event.html
Flags: needinfo?(josh)
Assignee | ||
Comment 36•8 years ago
|
||
Next I was looking at this failure: https://treeherder.mozilla.org/#/jobs?repo=try&revision=9c8e25f06f93e02aac5bdd503105043e30edeceb&selectedJob=27717335&filter-searchStr=Linux%20debug%20W3C%20Web%20Platform%20Tests%20e10s%20W3C%20Web%20Platform%20Tests%20e10s%20W-e10s(4)
When I run the test on my system, it skips the test instead of running it. Is it because the application cache feature is deprecated?
Reporter | ||
Comment 37•8 years ago
|
||
You can use `./mach mochitest dom/workers/test/serviceworkers/test_fetch_event.html --debugger=gdb` to attach to the parent process, or `MOZ_DEBUG_CHILD_PROCESS=1 ./mach mochitest dom/workers/test/serviceworkers/test_fetch_event.html` and then attach gdb manually to the process id that is printed on stdout if you want to attach to the child process. On the other hand, I used `--disble-e10s --debugger=gdb` so that there was only one process that needed debugging.
Flags: needinfo?(josh)
Reporter | ||
Comment 38•8 years ago
|
||
According to https://dxr.mozilla.org/mozilla-central/source/testing/web-platform/meta/html/infrastructure/urls/resolving-urls/query-encoding/utf-16be.html.ini that test is skipped on OS X. You could remove that line in order to run it locally, but given that bug 1295445 exists and the test doesn't use the Headers API, I believe you can ignore that test failure.
Assignee | ||
Comment 39•8 years ago
|
||
This job reports memleak : https://treeherder.mozilla.org/#/jobs?repo=try&revision=9c8e25f06f93e02aac5bdd503105043e30edeceb&selectedJob=27717055&filter-searchStr=OS%20X%2010.10%20debug%20Mochitest%20Mochitest%20M(2)
But I am unable to find out which test is run here.
Flags: needinfo?(josh)
Assignee | ||
Comment 40•8 years ago
|
||
I am facing a weird issue. After I submitted the patch to bugzilla, I had to move to a different laptop where I did hg clone and all the stuff again. Also, I took this patch and applied it in the latest mozilla-central repository but testing/web-platform/meta/fetch/api/headers/headers-combine.html.ini file was not there already so the part of the patch where the file was deleted did not apply properly. This caused a test failure here : https://treeherder.mozilla.org/#/jobs?repo=try&revision=9c8e25f06f93e02aac5bdd503105043e30edeceb&selectedJob=27721630&filter-searchStr=Windows%207%20VM%20opt%20W3C%20Web%20Platform%20Tests%20W3C%20Web%20Platform%20Tests%20W(2)
Notice the test unexpected pass. How do I resolve this issue?
Reporter | ||
Comment 41•8 years ago
|
||
(In reply to Saurabh Singhal [:saurabh] from comment #39)
> This job reports memleak :
> https://treeherder.mozilla.org/#/
> jobs?repo=try&revision=9c8e25f06f93e02aac5bdd503105043e30edeceb&selectedJob=2
> 7717055&filter-searchStr=OS%20X%2010.
> 10%20debug%20Mochitest%20Mochitest%20M(2)
>
> But I am unable to find out which test is run here.
If we aren't seeing similar memory leaks on other platforms for the same testsuite, we can ignore this (otherwise we would need to investigate more). The leak warnings mean "we ran a bunch of tests in a browser window, and when we closed the browser there was memory that was leaked", so it's difficult to associate with a particular test. However, bug 1293324 looks like it matches that leak, and it's a known intermittent leak, so we don't need to worry about it here.
Flags: needinfo?(josh)
Reporter | ||
Comment 42•8 years ago
|
||
(In reply to Saurabh Singhal [:saurabh] from comment #40)
> I am facing a weird issue. After I submitted the patch to bugzilla, I had to
> move to a different laptop where I did hg clone and all the stuff again.
> Also, I took this patch and applied it in the latest mozilla-central
> repository but
> testing/web-platform/meta/fetch/api/headers/headers-combine.html.ini file
> was not there already so the part of the patch where the file was deleted
> did not apply properly. This caused a test failure here :
> https://treeherder.mozilla.org/#/
> jobs?repo=try&revision=9c8e25f06f93e02aac5bdd503105043e30edeceb&selectedJob=2
> 7721630&filter-
> searchStr=Windows%207%20VM%20opt%20W3C%20Web%20Platform%20Tests%20W3C%20Web%2
> 0Platform%20Tests%20W(2)
> Notice the test unexpected pass. How do I resolve this issue?
I agree that this is odd, because headers-combine.html.ini is definitely still present in mozilla-central: https://dxr.mozilla.org/mozilla-central/source/testing/web-platform/meta/fetch/api/headers/headers-combine.html.ini . Make sure that you have an updated mozilla-central and reapply the patch?
Assignee | ||
Comment 43•8 years ago
|
||
(In reply to Josh Matthews [:jdm] from comment #42)
> (In reply to Saurabh Singhal [:saurabh] from comment #40)
> > I am facing a weird issue. After I submitted the patch to bugzilla, I had to
> > move to a different laptop where I did hg clone and all the stuff again.
> > Also, I took this patch and applied it in the latest mozilla-central
> > repository but
> > testing/web-platform/meta/fetch/api/headers/headers-combine.html.ini file
> > was not there already so the part of the patch where the file was deleted
> > did not apply properly. This caused a test failure here :
> > https://treeherder.mozilla.org/#/
> > jobs?repo=try&revision=9c8e25f06f93e02aac5bdd503105043e30edeceb&selectedJob=2
> > 7721630&filter-
> > searchStr=Windows%207%20VM%20opt%20W3C%20Web%20Platform%20Tests%20W3C%20Web%2
> > 0Platform%20Tests%20W(2)
> > Notice the test unexpected pass. How do I resolve this issue?
>
> I agree that this is odd, because headers-combine.html.ini is definitely
> still present in mozilla-central:
> https://dxr.mozilla.org/mozilla-central/source/testing/web-platform/meta/
> fetch/api/headers/headers-combine.html.ini . Make sure that you have an
> updated mozilla-central and reapply the patch?
I cloned the repo in a different directory and made sure that the ini file was there. Then, I applied the patch and got this:
MacBook-Pro:mozilla-central saurabhs$ hg import ~/HeadersgetAll.patch
applying /Users/saurabhs/HeadersgetAll.patch
patching file testing/web-platform/tests/fetch/api/headers/headers-basic.html
Hunk #1 FAILED at 60
1 out of 1 hunks FAILED -- saving rejects to file testing/web-platform/tests/fetch/api/headers/headers-basic.html.rej
abort: patch failed to apply
On doing hg diff after this, I did not see the headers-combine.html.ini deleted part there although, the file is no longer there in my local repo. It looks like the file got deleted from the disk but did not show up as deleted in the patch. Do you know what can I do here?
Flags: needinfo?(josh)
Reporter | ||
Comment 45•8 years ago
|
||
Another thing you can try is `hg rm -A testing/web-platform/meta/fetch/api/headers/headers-combine.html.ini` which should properly record the removal of headers-combine.html.ini.
Assignee | ||
Comment 46•8 years ago
|
||
(In reply to Josh Matthews [:jdm] from comment #44)
> What does `hg status` show?
MacBook-Pro:headers saurabhs$ hg status
M dom/cache/AutoUtils.cpp
M dom/cache/DBSchema.cpp
M dom/fetch/FetchDriver.cpp
M dom/fetch/Headers.h
M dom/fetch/InternalHeaders.cpp
M dom/fetch/InternalHeaders.h
M dom/flyweb/FlyWebPublishedServer.cpp
M dom/flyweb/HttpServer.cpp
M dom/tests/mochitest/fetch/test_headers_common.js
M dom/tests/mochitest/fetch/test_headers_mainthread.html
M dom/webidl/Headers.webidl
M testing/web-platform/meta/fetch/api/headers/headers-normalize.html.ini
M testing/web-platform/tests/fetch/api/headers/headers-combine.html
M testing/web-platform/tests/fetch/api/headers/headers-normalize.html
! testing/web-platform/meta/fetch/api/headers/headers-combine.html.ini
? testing/web-platform/tests/fetch/api/headers/headers-basic.html.rej
Reporter | ||
Comment 47•8 years ago
|
||
The `hg status --help` output says "! = missing (deleted by non-hg command, but still tracked)", so I recommend running the `hg rm` command I suggested.
Assignee | ||
Comment 48•8 years ago
|
||
Thanks Josh. Your suggestion worked. I have pushed the code to try again.
Assignee | ||
Comment 49•8 years ago
|
||
Comment 51•8 years ago
|
||
The webidl changes from this patch need review from a DOM peer before this can land.
Keywords: checkin-needed
Updated•8 years ago
|
Attachment #8773840 -
Attachment is obsolete: true
Reporter | ||
Comment 52•8 years ago
|
||
Comment on attachment 8786799 [details] [diff] [review]
HeadersgetAll.patch
This needs a DOM peer's review of the Header.webidl changes.
Attachment #8786799 -
Flags: review?(bkelly)
Comment 53•8 years ago
|
||
Comment on attachment 8786799 [details] [diff] [review]
HeadersgetAll.patch
Review of attachment 8786799 [details] [diff] [review]:
-----------------------------------------------------------------
I think we should clarify what Cache API Vary header matching should use before landing this. I filed this spec issue:
https://github.com/w3c/ServiceWorker/issues/991
Overall, though, it looks good. Sorry for the spec issue.
::: dom/cache/AutoUtils.cpp
@@ +262,5 @@
> "TypeUtils::ToPCacheResponseWithoutBody()");
>
> ErrorResult headerRv;
> nsAutoCString value;
> + requestHeaders->GetFirst(header, value, headerRv);
See my comments for DBSchema.cpp. This should be `Get()` per the current spec:
https://w3c.github.io/ServiceWorker/#query-cache-algorithm
@@ +269,5 @@
> MOZ_ASSERT(value.IsEmpty());
> }
>
> nsAutoCString cachedValue;
> + cachedRequestHeaders->GetFirst(header, cachedValue, headerRv);
Keep `Get()` here.
::: dom/cache/DBSchema.cpp
@@ +1299,5 @@
> "TypeUtils::ToPCacheResponseWithoutBody()");
>
> ErrorResult errorResult;
> nsAutoCString queryValue;
> + queryHeaders->GetFirst(header, queryValue, errorResult);
This seems wrong to me or there is a spec bug. The service workers spec says to use Headers `get()` which includes combining. I think we should keep the `Get()` call here instead of using `GetFirst()`.
See:
https://w3c.github.io/ServiceWorker/#query-cache-algorithm
@@ +1306,5 @@
> MOZ_ASSERT(queryValue.IsEmpty());
> }
>
> nsAutoCString cachedValue;
> + cachedHeaders->GetFirst(header, cachedValue, errorResult);
Keep `Get()` here.
::: dom/fetch/Headers.h
@@ +85,5 @@
> {
> mInternalHeaders->Get(aName, aValue, aRv);
> }
>
> + void GetFirst(const nsACString& aName, nsCString& aValue, ErrorResult& aRv) const
I think this should be `nsACString& aValue`.
::: dom/fetch/InternalHeaders.h
@@ +74,5 @@
> void Append(const nsACString& aName, const nsACString& aValue,
> ErrorResult& aRv);
> void Delete(const nsACString& aName, ErrorResult& aRv);
> void Get(const nsACString& aName, nsCString& aValue, ErrorResult& aRv) const;
> + void GetFirst(const nsACString& aName, nsCString& aValue, ErrorResult& aRv) const;
I think this should be `nsACString& aValue).
::: dom/tests/mochitest/fetch/test_headers_mainthread.html
@@ +142,5 @@
> }, TypeError, "Should not be able to delete immutable headers");
>
> checkHas(headers, "foo", "Should be able to check immutable headers");
> ok(headers.get("foo"), "Should be able to get immutable headers");
> + ok(headers.get("foo").length, "Should be able to get all immutable headers");
This test assertion seems wrong to me now. In the old case it was checking the .length of an array. This is checking the .length of the value returned which is effectively checked by the truthy assertion before it.
Since this is a single value in the 'foo' header, perhaps we should just remove this ok() assertion?
Attachment #8786799 -
Flags: review?(bkelly) → review-
Comment 54•8 years ago
|
||
Initial feedback in the github issue is that we should probably be using the combined value in the Vary header logic. So my comments about switching from `GetFirst()` back to `Get()` stand. Sorry for the runaround and thanks for working on this!
Assignee | ||
Comment 55•8 years ago
|
||
(In reply to Ben Kelly [:bkelly] from comment #53)
> ::: dom/fetch/Headers.h
> @@ +85,5 @@
> > {
> > mInternalHeaders->Get(aName, aValue, aRv);
> > }
> >
> > + void GetFirst(const nsACString& aName, nsCString& aValue, ErrorResult& aRv) const
>
> I think this should be `nsACString& aValue`.
Why?
Comment 56•8 years ago
|
||
(In reply to Saurabh Singhal [:saurabh] from comment #55)
> > > + void GetFirst(const nsACString& aName, nsCString& aValue, ErrorResult& aRv) const
> >
> > I think this should be `nsACString& aValue`.
>
> Why?
Its preferable to use the abstract `nsA*String` string types in method signatures so the caller can decide which concrete string type to actually use. I think the only time a method should take explicitly `nsString` or `nsCString` is if you require a flat string (not a dependent substring, etc).
I see that the previous `Get()` method also has an `nsCString`. That could also be switched to `nsACString` I think.
The `GetAll()` method returns an `nsTArray<nsCString>` because it requires a concrete type.
As a side note, why are we leaving `GetAll()` in the code? Can't that be removed now?
Thanks.
Assignee | ||
Comment 57•8 years ago
|
||
(In reply to Ben Kelly [:bkelly] from comment #56)
> As a side note, why are we leaving `GetAll()` in the code? Can't that be
> removed now?
According to https://bugzilla.mozilla.org/show_bug.cgi?id=1278275#c15 GetAll() is still required.
Assignee | ||
Comment 58•8 years ago
|
||
Addressing comments from Ben. Thanks for the review.
Attachment #8786799 -
Attachment is obsolete: true
Attachment #8800748 -
Flags: review?(bkelly)
Assignee | ||
Comment 59•8 years ago
|
||
Uploading the correct diff.
Attachment #8800748 -
Attachment is obsolete: true
Attachment #8800748 -
Flags: review?(bkelly)
Attachment #8800754 -
Flags: review?(bkelly)
Assignee | ||
Comment 60•8 years ago
|
||
(In reply to Saurabh Singhal [:saurabh] from comment #57)
> (In reply to Ben Kelly [:bkelly] from comment #56)
> > As a side note, why are we leaving `GetAll()` in the code? Can't that be
> > removed now?
>
> According to https://bugzilla.mozilla.org/show_bug.cgi?id=1278275#c15
> GetAll() is still required.
Removed GetAll from dom/fetch/Headers.h since the GetAll() being called in AutoUtils.cpp is the one provided by dom/fetch/InternalHeaders.h
Comment 61•8 years ago
|
||
(In reply to Saurabh Singhal [:saurabh] from comment #60)
> Removed GetAll from dom/fetch/Headers.h since the GetAll() being called in
> AutoUtils.cpp is the one provided by dom/fetch/InternalHeaders.h
You should remove the other one as well. Just use Get() in AutoUtils and parse the combined value.
Comment 62•8 years ago
|
||
Comment on attachment 8800754 [details] [diff] [review]
HeadersgetAll.patch
Review of attachment 8800754 [details] [diff] [review]:
-----------------------------------------------------------------
Sorry, can you implement comment 61? Now that Get() combines values we don't need that last GetAll() in AutoUtils. You can just call Get() and let the parsing code that is already there extract the values.
Attachment #8800754 -
Flags: review?(bkelly)
Assignee | ||
Comment 63•8 years ago
|
||
I just found that FetchBody<Derived>::SetMimeType() function in dom/fetch/Fetch.cpp also uses GetAll(). Should I remove this too and add the parsing code here also?
Comment 64•8 years ago
|
||
I believe you can replace that with Get(). Then for this section:
// HTTP ABNF states Content-Type may have only one value.
// This is from the "parse a header value" of the fetch spec.
if (contentTypeValues.Length() == 1) {
mMimeType = contentTypeValues[0];
ToLowerCase(mMimeType);
}
You can instead search for "," to see if there is more than one value. Sound reasonable?
Assignee | ||
Comment 65•8 years ago
|
||
I could not figure out a good place to put the parsing code. So, I have duplicated it for now in AutoUtils.cpp and TypeUtils.cpp
Attachment #8800754 -
Attachment is obsolete: true
Attachment #8801564 -
Flags: review?(bkelly)
Comment 66•8 years ago
|
||
Comment on attachment 8801564 [details] [diff] [review]
HeadersgetAll.patch
Review of attachment 8801564 [details] [diff] [review]:
-----------------------------------------------------------------
Sorry, I think there was a miscommunication. The parsing code is already in the code. See:
https://dxr.mozilla.org/mozilla-central/source/dom/cache/AutoUtils.cpp#255
https://dxr.mozilla.org/mozilla-central/source/dom/cache/TypeUtils.cpp#56
What it was doing before was getting all headers, but then parsing each one. That was because we couldn't tell if a single value returned from Headers.getAll() was combined or not.
So you don't need to implement your own parsing here. Just remove the outer loop from the strtok() loops that are already there.
Attachment #8801564 -
Flags: review?(bkelly) → review-
Assignee | ||
Comment 67•8 years ago
|
||
Fix the parsing code in AutoUtils.cpp and TypeUtils.cpp
Attachment #8801564 -
Attachment is obsolete: true
Attachment #8801810 -
Flags: review?(bkelly)
Comment 68•8 years ago
|
||
Comment on attachment 8801810 [details] [diff] [review]
HeadersgetAll.patch
Review of attachment 8801810 [details] [diff] [review]:
-----------------------------------------------------------------
Thanks!
In the future we may want to rejigger the logic so Headers::Append creates the combined string immediately instead of recalculating it on every Get(). That can be done in a follow-up, though.
Attachment #8801810 -
Flags: review?(bkelly) → review+
Assignee | ||
Comment 69•8 years ago
|
||
Thanks Ben! I have pushed the changes to try. The results are here: https://treeherder.mozilla.org/#/jobs?repo=try&revision=4b7a8502c1d1271d1114cd49bc6264d3b7e4f39d
Comment 71•8 years ago
|
||
Pushed by ryanvm@gmail.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/add68bb69193
Update Headers::GetAll and Headers::Get to match the specification. r=jdm, r=bkelly
Keywords: checkin-needed
Comment 72•8 years ago
|
||
bugherder |
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
status-firefox52:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla52
Comment 73•8 years ago
|
||
Posted the site compatibility doc: https://www.fxsitecompat.com/en-CA/docs/2016/headers-getall-has-been-removed-in-favour-of-get-now-returning-all-values/
Keywords: dev-doc-needed,
site-compat
Comment 74•8 years ago
|
||
I have documented this change, updating the relevant reference/tutorial pages:
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
https://developer.mozilla.org/en-US/docs/Web/API/Headers
https://developer.mozilla.org/en-US/docs/Web/API/Headers/get
https://developer.mozilla.org/en-US/docs/Web/API/Headers/getAll
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
I have also added a note to the Fx52 release notes:
https://developer.mozilla.org/en-US/Firefox/Releases/52#Service_Workers_and_Fetch
Let me know if these look OK. Thanks!
Keywords: dev-doc-needed → dev-doc-complete
Updated•6 years ago
|
Component: DOM → DOM: Core & HTML
You need to log in
before you can comment on or make changes to this bug.
Description
•