Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate Content-Type failures from tests/wpt/xhr/setrequestheader-content-type.htm #20436

Open
jdm opened this issue Mar 26, 2018 · 25 comments
Open

Comments

@jdm
Copy link
Member

@jdm jdm commented Mar 26, 2018

We certainly try to implement step 4 of https://xhr.spec.whatwg.org/#the-send()-method in XMLHttpRequest::Send, but there are a bunch of test failures shown in https://github.com/servo/servo/blob/master/tests/wpt/metadata/xhr/setrequestheader-content-type.htm.ini that demonstrate that our implementation is not correct. We should investigate precisely what is causing the tests not to pass.

@jdm
Copy link
Member Author

@jdm jdm commented Mar 26, 2018

@nupurbaghel This might be a good next issue if you're looking for one.

@jdm
Copy link
Member Author

@jdm jdm commented Mar 26, 2018

A good place to start is by deleting the ini file so the full error messages are shown (including expected vs. actual values).

@jdm
Copy link
Member Author

@jdm jdm commented Mar 26, 2018

Note: any errors about ReadableStreams can be ignored, since we don't implement that yet.

@nupurbaghel
Copy link
Contributor

@nupurbaghel nupurbaghel commented Mar 26, 2018

Thank you so much for suggesting 😄 !
I would really like to work on this issue next :)

@jdm jdm added the C-assigned label Mar 26, 2018
@nupurbaghel
Copy link
Contributor

@nupurbaghel nupurbaghel commented Mar 28, 2018

A good place to start is by deleting the ini file

I tried deleting the ini file, and running mach build. But it was build successfully without any errors. Do we need to alter anything else as well?

@jdm
Copy link
Member Author

@jdm jdm commented Mar 28, 2018

./mach build is unrelated to these tests. You'll want to run ./mach test-wpt --no-pause-after-test tests/wpt/web-platform-tests/xhr/setrequestheader-content-type.htm to see the errors that occur when running the test.

@nupurbaghel
Copy link
Contributor

@nupurbaghel nupurbaghel commented Mar 31, 2018

On comparing the test results with the actual values, I noticed that the majority of tests were failing because of addition of an extra space.
Also, there was mismatch of lower/upper case. The test files had 'Content-Type' and the results obtained from request had 'content-type'. For the time being I have converted everything to small-case.

@nupurbaghel
Copy link
Contributor

@nupurbaghel nupurbaghel commented Mar 31, 2018

Also, I was trying to understand the flow of data during a request from xhr/xmlhttprequest.rs .Until now I have figured out that the final text_response generated, comes after decoding from self.response which itself is assigned value during process_partial_response. I wanted to confirm I am going in the right direction :)

@jdm
Copy link
Member Author

@jdm jdm commented Mar 31, 2018

The actual network data is transferred to XMLHttpRequest via the callbacks in the impl FetchResponseListener for XHRContext, which calls methods like XMLHttpRequest::process_headers_available and XMLHttpRequest::process_data_avaialable, which ends up in XMLHttpRequest::process_partial_response like you said.

@jdm jdm removed the C-assigned label Feb 13, 2019
@fadedreamz
Copy link

@fadedreamz fadedreamz commented Sep 6, 2019

@jdm I would like to try it out to get familiar with both rust and servo. Is it something that requires extensive knowledge of the servo? If not please assign it to me.

@jdm
Copy link
Member Author

@jdm jdm commented Sep 6, 2019

@fadedreamz This issue should be pretty self-contained, so it does sound like a reasonable introduction to Servo to me.

@fadedreamz
Copy link

@fadedreamz fadedreamz commented Sep 6, 2019

@jdm Thanks, I would like to take a shot at it, can you please mark it assigned?

@jdm jdm added the C-assigned label Sep 6, 2019
@fadedreamz
Copy link

@fadedreamz fadedreamz commented Sep 6, 2019

@jdm when I ran the ./mach test-wpt --no-pause-after-test tests/wpt/xhr/setrequestheader-content-type.htm command I get the following error:
0:01.12 INFO Using 12 client processes
0:01.12 ERROR Unable to find any tests at the path(s):
0:01.12 ERROR tests/wpt/xhr/setrequestheader-content-type.htm
0:01.12 ERROR Please check spelling and make sure there are tests in the specified path(s).
0:01.12 INFO Closing logging queue
0:01.12 INFO queue closed

I checked and as reported there is no setrequestheader-content-type.htm. Am I missing some steps?

@jdm
Copy link
Member Author

@jdm jdm commented Sep 6, 2019

It's tests/wpt/web-platform-tests/xhr/setrequestheader-content-type.htm.

@jdm
Copy link
Member Author

@jdm jdm commented Sep 6, 2019

Sorry, I have corrected the incorrect path in the earlier comment.

@fadedreamz
Copy link

@fadedreamz fadedreamz commented Sep 14, 2019

@jdm can you provide some suggestion on where the headers are being adjusted, I looked into process_headers_available, SetRequestHeader and process_partial_response. I am having hard time to pinpoint where the headers are being adjusted. For example, a failing test case

function _String() { return "test()"; },
        {"Content-Type": "text/javascript;charset=ASCII"},
        "text/javascript;charset=UTF-8",
        "String request keeps setRequestHeader() Content-Type, with charset adjusted to UTF-8"

I am trying to pinpoint where the adjustment of ASCII to UTF-8 is happening. TIA

@jdm
Copy link
Member Author

@jdm jdm commented Sep 14, 2019

My first suspicion is uses of final_charset and final_mime_type in that file. Alternatively, I can't easily check the test on my phone right now, but is the test currently failing because we are not adjusting the charset when we should be?

@fadedreamz
Copy link

@fadedreamz fadedreamz commented Sep 15, 2019

My suspicion is that when adjusting the charset it is introducing a space, which is leading to three failed test case. I will check the mentioned function and update the ticket.

@fadedreamz
Copy link

@fadedreamz fadedreamz commented Sep 15, 2019

The test case is failing because adjusting it leaves the value to

text/javascript; charset=utf-8

So, an extra space and lower case utf-8 than the expected value. (seems like same root cause for 3 failing test cases).

@fadedreamz
Copy link

@fadedreamz fadedreamz commented Oct 1, 2019

@jdm sorry for some time break, I investigated a little bit more, but could not find where actual adjusting is happening. Maybe my lack of knowledge with rust and servo is not helping me. Any suggestions?

@jdm
Copy link
Member Author

@jdm jdm commented Nov 4, 2019

I'm pretty sure that this code is responsible. For a string request body (as in the failing test case), we default to UTF-8 encoding. Then if the request includes a Content-Type header, we extract its MIME type but ignore its charset value and replace it with the encoding we decided on earlier. That gives us text/javascript; charset=UTF-8, like you said.

@jdm
Copy link
Member Author

@jdm jdm commented Nov 4, 2019

This is steps 4.1-4.4 of the XHR send algorithm from the specification.

@jdm
Copy link
Member Author

@jdm jdm commented Nov 4, 2019

According to https://mimesniff.spec.whatwg.org/#serialize-a-mime-type we should not be including the space in the resulting serialized mime type.

@fadedreamz
Copy link

@fadedreamz fadedreamz commented Nov 5, 2019

@jdm thank you. So, I removed the extra space but could not solve the lower case upper case issue. The root cause is when we are unwrapping the serialized mime string to Mime type via parse(), the UTF8 is being converted to lower case.
So later on when we are rebuilding the header we are getting lower cap "utf-8". Possible fix -
a) change the test expected case from upper case to lower case
b) file a bug report/feature request (?) for mime crate?
c) any other suggestions?

@fadedreamz
Copy link

@fadedreamz fadedreamz commented Nov 24, 2019

@jdm as I couldn't find an easy way to change the mime to uppercase, I changed the value in the test case to lower case. I believe the problem is mime type uses http lowercase notation where xhr expects uppercase notation (Please do correct me if I am wrong) and in rust mime crate all the constant values are in lowercases. I also fixed the mime suffix (e,g - +xml) bug which was leading to other test case failures. At this point now I am left with 4 failing test cases in URLSearchParam (1) and in ReadableStream(3). Now according to xhr (4.1) -
If body is a Document or a USVString, then
so for URLSearchParam it should not change the case, if so, then why in test case we are expecting it to be adjusted?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.