Bug 29121 - XMLHttpRequest::getAllResponseHeaders throws INVALID_STATE_ERR when called in state HEADERS_RECEIVED
Summary: XMLHttpRequest::getAllResponseHeaders throws INVALID_STATE_ERR when called in...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore JavaScript (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC All
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-09-10 04:59 PDT by Carol Szabo
Modified: 2009-10-01 10:47 PDT (History)
4 users (show)

See Also:


Attachments
Example test case (1.17 KB, application/zip)
2009-09-10 05:04 PDT, Carol Szabo
no flags Details
Proposed patch (5.60 KB, patch)
2009-09-10 08:00 PDT, Carol Szabo
sam: review-
commit-queue: commit-queue-
Details | Formatted Diff | Diff
New Patch proposal to address sam's concerns (9.78 KB, patch)
2009-09-10 11:49 PDT, Carol Szabo
sam: review+
Details | Formatted Diff | Diff
Modified tests to make them more portable (10.83 KB, patch)
2009-09-11 08:54 PDT, Carol Szabo
no flags Details | Formatted Diff | Diff
Proposed patch. Moved tests to http/tests/xmlhttprequest from fast/xmlhttprequest (11.52 KB, patch)
2009-09-11 13:27 PDT, Carol Szabo
no flags Details | Formatted Diff | Diff
Improved text in the tests per ap's comments. (11.71 KB, patch)
2009-09-14 09:18 PDT, Carol Szabo
ap: review+
ap: commit-queue-
Details | Formatted Diff | Diff
Fixed a few minor issues with the tests and some regretable mistakes in the test results. (11.19 KB, patch)
2009-09-14 12:37 PDT, Carol Szabo
ap: review-
Details | Formatted Diff | Diff
New patch that fixes problems with failing old http tests (28.57 KB, patch)
2009-09-15 16:19 PDT, Carol Szabo
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Carol Szabo 2009-09-10 04:59:57 PDT
Despite http://dev.w3.org/2006/webapi/XMLHttpRequest-2/#the-getallresponseheaders-method mentioning explicitely and with an example that XMLHttpRequest::getAllResponseHeaders should return the headers in readyState HEADERS_RECEIVED. The Webkit implementation still throws an exception in this scenario.
Comment 1 Carol Szabo 2009-09-10 05:04:27 PDT
Created attachment 39341 [details]
Example test case

This is an example that reproduces the problem. just unzip the archive in any virtual directory of an http server and access the included garhs.htm from a Webkit browser.
Comment 2 Carol Szabo 2009-09-10 08:00:44 PDT
Created attachment 39349 [details]
Proposed patch
Comment 3 WebKit Commit Bot 2009-09-10 09:50:55 PDT
Comment on attachment 39349 [details]
Proposed patch

Rejecting patch 39349 from commit-queue.

carol.szabo@nokia.com does not have committer permissions according to http://trac.webkit.org/browser/trunk/WebKitTools/Scripts/modules/committers.py.
Comment 4 Sam Weinig 2009-09-10 10:05:49 PDT
Comment on attachment 39349 [details]
Proposed patch

This should really also fix getResponseHeader which has the same bug.
Comment 5 WebKit Commit Bot 2009-09-10 10:07:51 PDT
Comment on attachment 39349 [details]
Proposed patch

Rejecting patch 39349 from commit-queue.

This patch will require manual commit. ['WebKitTools/Scripts/run-webkit-tests', '--no-launch-safari', '--quiet', '--exit-after-n-failures=1'] failed with exit code 1
Comment 6 Carol Szabo 2009-09-10 11:49:27 PDT
Created attachment 39362 [details]
New Patch proposal to address sam's concerns

Despite the fact that this bug does not cover the similar problem with getResponseHeader, in the interest of saving time and satisfying reviewers, I fixed both bugs here.
Comment 7 Eric Seidel (no email) 2009-09-10 12:41:13 PDT
fast/xmlhttprequest/xmlhttprequest-getallheaders.html -> failed
was the test that failed when trying to land attachment 39349 [details].
Comment 8 Carol Szabo 2009-09-11 08:09:25 PDT
(In reply to comment #7)
> fast/xmlhttprequest/xmlhttprequest-getallheaders.html -> failed
> was the test that failed when trying to land attachment 39349 [details].

Eric, can you attach the actual output from the failed tests to the bug so that I can improve the tests. I know the tests have some weaknesses regarding portability, but I'd like to see what exactly went wrong in your environment.
Thanks,
Carol
Comment 9 Carol Szabo 2009-09-11 08:54:45 PDT
Created attachment 39437 [details]
Modified tests to make them more portable

My previous patch had at least one of the new tests fail according to Eric. I have modified the tests to make them less dependent on the environment.
Eric,
Can you see if these tests work for you and can you add this patch to the commit queue?
Thanks,
Carol
Comment 10 Eric Seidel (no email) 2009-09-11 09:23:27 PDT
These were the difffs from the commit-queue's failure:
--- /tmp/layout-test-results/fast/xmlhttprequest/xmlhttprequest-getallheaders-expected.txt      2009-09-10 10:07:46.000000000 -0700
+++ /tmp/layout-test-results/fast/xmlhttprequest/xmlhttprequest-getallheaders-actual.txt        2009-09-10 10:07:46.000000000 -0700
@@ -8,5 +8,4 @@
  Header name and Header value is separated by COLON and SPACE.
  Set-Cookie and Set-Cookie2 Headers with any ASCII case-insensitive match NOT displayed.
 SUCCEEDED: getAllResponseHeaders returned:
-Cache-Control: no-cache
Comment 11 Carol Szabo 2009-09-11 09:44:15 PDT
(In reply to comment #10)
> These were the difffs from the commit-queue's failure:
> ---
> /tmp/layout-test-results/fast/xmlhttprequest/xmlhttprequest-getallheaders-expected.txt
>      2009-09-10 10:07:46.000000000 -0700
> +++
> /tmp/layout-test-results/fast/xmlhttprequest/xmlhttprequest-getallheaders-actual.txt
>        2009-09-10 10:07:46.000000000 -0700
> @@ -8,5 +8,4 @@
>   Header name and Header value is separated by COLON and SPACE.
>   Set-Cookie and Set-Cookie2 Headers with any ASCII case-insensitive match NOT
> displayed.
>  SUCCEEDED: getAllResponseHeaders returned:
> -Cache-Control: no-cache

As I expected, the difference is in the headers that get returned.
In your environment, there are no headers returned for the "file" scheme, where as in mine there is one header.
I fixed this problem, by not displaying the headers if the test is ran with DumpRenderTree, just analyze them for problems. The scope of these tests is anyway just to make sure that no INVALID_STATE exception is thrown.
Please verify my new patch which only differs in the test area from the previous.
Comment 12 Alexey Proskuryakov 2009-09-11 10:32:54 PDT
(In reply to comment #0)
> Despite
> http://dev.w3.org/2006/webapi/XMLHttpRequest-2/#the-getallresponseheaders-method
> mentioning explicitely and with an example that
> XMLHttpRequest::getAllResponseHeaders should return the headers in readyState
> HEADERS_RECEIVED. The Webkit implementation still throws an exception in this
> scenario.

Have you tested IE and Firefox? Please do.

> In your environment, there are no headers returned for the "file" scheme, where
> as in mine there is one header.

I suggest making these HTTP tests. Asking for HTTP response headers of a file:/// resource doesn't make much sense, and there is no specification for XHR operating on such.
Comment 13 Eric Seidel (no email) 2009-09-11 10:42:41 PDT
Comment on attachment 39437 [details]
Modified tests to make them more portable

Marking cq=? w/o marking r=? makes little sense.  Also, ap seems to have objections to this patch, so removing cq?
Comment 14 Carol Szabo 2009-09-11 12:31:46 PDT
(In reply to comment #12)
> (In reply to comment #0)
> > Despite
> > http://dev.w3.org/2006/webapi/XMLHttpRequest-2/#the-getallresponseheaders-method
> > mentioning explicitely and with an example that
> > XMLHttpRequest::getAllResponseHeaders should return the headers in readyState
> > HEADERS_RECEIVED. The Webkit implementation still throws an exception in this
> > scenario.
> 
> Have you tested IE and Firefox? Please do.

Firefox 3.0.8 works per the standard in this regard.
IE 6 does not have the concept of readyState
IE 7 and IE 8 have a concept of readyState, but it is not the same as the one specified in the standard, and thus IE has a different behavior than WebKit regardless of whether I put my change in or not. IE only gives access to headers when the whole load finished, which is not what WebKit did before my fix.


> I suggest making these HTTP tests. Asking for HTTP response headers of a
> file:/// resource doesn't make much sense, and there is no specification for
> XHR operating on such.

I agree, I will do that.
Comment 15 Carol Szabo 2009-09-11 13:27:09 PDT
Created attachment 39471 [details]
Proposed patch. Moved tests to http/tests/xmlhttprequest from fast/xmlhttprequest

Also I have addressed ap's concerns.
Comment 16 Alexey Proskuryakov 2009-09-11 15:22:45 PDT
Comment on attachment 39471 [details]
Proposed patch. Moved tests to http/tests/xmlhttprequest from fast/xmlhttprequest

FWIW, our current behavior is based on research summarized in bug 15356 comment 7.

+If the test succeeds one should see below the ruller the text "SUCCEEDED: getAllResponseHeaders returned: " followed by a conforming list of headers.

This text looks outdated. Same issue in another test.

We have a lot of data files in xmlhttprequest/resources already, do the new files really need to be added?

Looks good to me, r- to update the tests. It would also be great if you could review the discussion in bug 15356, just in case it has some important details about other browsers' behavior.
Comment 17 Carol Szabo 2009-09-11 15:45:55 PDT
Comment on attachment 39471 [details]
Proposed patch. Moved tests to http/tests/xmlhttprequest from fast/xmlhttprequest

Alexei,
The text your are mentioning is intentionally left that way. If the test is run interactively, that is in a regular browser, not with DumpRenderTree the list of headers and the the value of the header respectively are still displayed. Also regardless of the user agent the very next paragraph after the one you mentioned explains that the header list and the header value respectively are omitted for DumpRenderTree to prevent the failure of the unattended tests.
I have read the discussion that you mentioned. I believe that my change which leads to an exception not being thrown, not to extra exceptions being thrown, increases (a little bit, not very much) the likelihood that a webpage will look as intended, as opposed to the change discussed in bug 15356, apparently would create a more restrictive behavior not a more lenient one. The risk with my change is that pages may be created that work only on Mozilla and WebKit or only on WebKit which is not that bad.
I know that somebody may rely on an exception being thrown instead of the header value being returned, but I think that that use case may be discounted.
Comment 18 Alexey Proskuryakov 2009-09-11 16:00:52 PDT
(In reply to comment #17)
> The text your are mentioning is intentionally left that way. If the test is run
> interactively, that is in a regular browser, not with DumpRenderTree the list
> of headers and the the value of the header respectively are still displayed.

I like that the headers are fully dumped when the test is run in Safari, it can be very helpful.

But this text is confusing nonetheless. There is no reason to leave it in this state - it's easy to have different output for DRT. In fact, we often do the following for DRT-only tests:

if (!window.layoutTestController)
    document.write("<p>This test only works in run-webkit-tests</p>");

Since this code has a long history of changes, it is particularly important not to leave any confusing comments around it.

> I have read the discussion that you mentioned. I believe that my change which
> leads to an exception not being thrown, not to extra exceptions being thrown,

Yes, that's correct. I just wanted to give some additional context, as it appears that at least some browsers' behavior has changed since 2007.
Comment 19 Carol Szabo 2009-09-14 09:18:21 PDT
Created attachment 39547 [details]
Improved text in the tests per ap's comments.
Comment 20 Alexey Proskuryakov 2009-09-14 10:59:16 PDT
Comment on attachment 39547 [details]
Improved text in the tests per ap's comments.

This still includes old test results, so a committer will need to regenerate them - or you could submit a new patch to simplify committer's job.

+    <p>If the test succeeds one should see below the ruller the text

A typo, there is one "l" in "ruler".

r=me
Comment 21 Carol Szabo 2009-09-14 12:37:00 PDT
Created attachment 39564 [details]
Fixed a few minor issues with the tests and some regretable mistakes in the test results.
Comment 22 Alexey Proskuryakov 2009-09-15 14:18:05 PDT
I tried to land this, but tests don't pass on Mac OS X Leopard:

file:///tmp/layout-test-results/http/tests/xmlhttprequest/xmlhttprequest-InvalidStateException-getAllRequestHeaders-diffs.txt
-PASSED (INVALID_STATE_ERR: DOM Exception 11 ) 2
+FAILED ( header :Date: Tue, 15 Sep 2009 21:12:19 GMT

file:///tmp/layout-test-results/http/tests/xmlhttprequest/xmlhttprequest-InvalidStateException-getRequestHeader-diffs.txt
-PASSED (INVALID_STATE_ERR: DOM Exception 11 ) 2
+FAILED ( header :text/html)2

When running the test manually, it also looks wrong:

SUCCEEDED: getResponseHeader returned: null
Comment 23 Carol Szabo 2009-09-15 16:19:01 PDT
Created attachment 39621 [details]
New patch that fixes problems with failing old http tests

This patch includes renaming of the test and expected results files. I believe it will be hard to read please advise on a better way to submit it if this method is not acceptable.
Thanks.
Comment 24 Alexey Proskuryakov 2009-09-16 09:14:37 PDT
Comment on attachment 39621 [details]
New patch that fixes problems with failing old http tests

> This patch includes renaming of the test and expected results files. I believe
> it will be hard to read please advise on a better way to submit it if this
> method is not acceptable.

It's actually fine, we do get a diff from old to new in such patches.

r=me, and let's see if the bot manages to land this...
Comment 25 WebKit Commit Bot 2009-09-16 13:36:53 PDT
Comment on attachment 39621 [details]
New patch that fixes problems with failing old http tests

Clearing flags on attachment: 39621

Committed r48433: <http://trac.webkit.org/changeset/48433>
Comment 26 WebKit Commit Bot 2009-09-16 13:36:59 PDT
All reviewed patches have been landed.  Closing bug.