Closed Bug 393968 Opened 17 years ago Closed 17 years ago

[FIX]XMLHttpRequest error status 500 on POST multipart form-data

Categories

(Core :: DOM: Core & HTML, defect, P2)

defect

Tracking

()

RESOLVED FIXED
mozilla1.9beta2

People

(Reporter: lfournie, Assigned: bzbarsky)

References

Details

(Keywords: regression)

Attachments

(1 file, 1 obsolete file)

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a8pre) Gecko/2007082705 Minefield/3.0a8pre Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a8pre) Gecko/2007082705 Minefield/3.0a8pre AJAX request to upload files does not work, and use to work with FF2 The pb occurs only with multipart type request, normal POST request works. See the Python CGI bellow to produce the error Reproducible: Always Steps to Reproduce: run the python CGI Actual Results: http error 500 Expected Results: status 200 #!/usr/bin/python import cgi class ajax: def __init__(self): self.fo = cgi.FieldStorage() print 'Content-type: application/vnd.mozilla.xul+xml\n' print '<?xml version="1.0" encoding="ISO-8859-1"?>' if self.fo.has_key('a'): print '<a>OK</a>' else: print '<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" onload="run()">' self.js() print '<description>Test</description></window>' def js(self): print """<script language="javascript"> <![CDATA[ function run() { var msg = '\\n--AaB03x\\ncontent-disposition: form-data; name="a"; filename="z"\\n' + 'Content-Type: application/octet-stream\\n' + 'Content-Transfer-Encoding: binary\\n\\n' + 'AAAAA_content_AAAAA' + '\\n--AaB03x\\n'; var a1 = new ajax(msg,function(res) { alert((new XMLSerializer()).serializeToString(res));}); a1.doGet(); } function ajax(params, cb) { var req = new XMLHttpRequest(); req.onreadystatechange = processRequest; function processRequest () { if (req.readyState == 4) { if (req.status == 200) { if (cb) cb(req.responseXML); } else { alert('Error status:'+ req.status); } } } this.doGet = function() { req.open('POST', 'tst_ajax.py', true); req.setRequestHeader('Content-Type', 'multipart/form-data; boundary="AaB03x"'); req.setRequestHeader('Content-length', params.length); req.setRequestHeader('Connection', 'close'); req.send(params); } } ]]> </script> """ if __name__ == '__main__': ajax()
Bug still occurs on Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a8pre) Gecko/2007090205 Minefield/3.0a8pre
The regression is still there with the Minefield release Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a8pre) Gecko/2007090504 Minefield/3.0a8pre All Web sites using Ajax Uploading with FF2 may not work with FF3. I do not know if it concerns only XUL app or all HTML apps. Please look at the bug.
I found a rational ON FF3M8 the "boundary" field is not sent ! Why, I don't know POST /tramwaytool/tstajax.py HTTP/1.1 Host: faugeres.france.rockwellcollins.com:8008 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a8pre) Gecko/2007090604 Minefield/3.0a8pre Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Proxy-Connection: keep-alive Content-Type: multipart/form-data;charset=UTF-8 Referer: http://faugeres.france.rockwellcollins.com:8008/tramwaytool/tstajax.py Content-Length: 152 Cookie: MODULE=SAAB2000_AEWC; REPOSITORY=%2Fcvs%2FDT313%2FRTU; SERVER=cvsdt Authorization: Basic bGZvdXJuaWU6YXF0aHJvdCwy Pragma: no-cache Cache-Control: no-cache ON FF2 IT WORKS well POST /tramwaytool/tstajax.py HTTP/1.1 Host: faugeres.france.rockwellcollins.com:8008 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Proxy-Connection: keep-alive Content-Type: multipart/form-data; boundary="xx" Connection: close Referer: http://faugeres.france.rockwellcollins.com:8008/tramwaytool/tstajax.py Content-Length: 152 Cookie: REPOSITORY=%2Fcvs%2FDT313%2FRTU; SERVER=cvsdt; MODULE=SAAB2000_AEWC Authorization: Basic bGZvdXJuaWU6YXF0aHJvdCwy Pragma: no-cache Cache-Control: no-cache
Severity: major → blocker
Version: unspecified → Trunk
Please take 5' to look at this bug. Application using binary file Upload may not work with FF3, because the boundary field is not sent.
identified the same problem with an independent project. After a call to setRequestHeader("Content-Type","multipart/form-data; boundary=abcdefg"), in FF 2 the header shows up correctly as "multipart/form-data; boundary=abcdefg" but in FF 3.0a8 the header shows up as "multipart/form-data;charset=UTF-8"
This appears to be a regression caused by the patch from bug 382947. The Content-Type is being overwritten without considering any existing boundary field.
The same behaviour can be observed on the Mac in 3a builds too. In FF2 on the Mac the request doesn't even get dispatched and returns status 400 'Bad Request'
Forget that about multipart/form-data not working at all on the Mac in FF2. During testing with FF3a I must have corrected an error that caused said behavior. (I think I had the wrong EOL-delimiter: \n instead of \r\n.)
Is there a plan to fix this bug, because with version 1.9a9pre upload of files don't work any more.
Assignee: nobody → bzbarsky
Status: UNCONFIRMED → NEW
Ever confirmed: true
I have no idea why this got assigned to me (I didn't cause the bug, and I don't recall Brian being my manager), or for that matter why it's stuck in the wrong product, without the dependencies it should have...
Assignee: bzbarsky → nobody
Blocks: 382947
Severity: blocker → major
Component: General → DOM: Mozilla Extensions
OS: Windows XP → All
Product: Firefox → Core
QA Contact: general → general
Hardware: PC → All
We really do need to fix this, though. biesi, is there a necko helper function we could use here? We basically want to replace the value of a single parameter in a header with a new value...
Flags: blocking1.9?
Assignee: nobody → jonas
Flags: blocking1.9? → blocking1.9+
Keywords: regression
Priority: -- → P2
(In reply to comment #10) > I have no idea why this got assigned to me (I didn't cause the bug, and I don't > recall Brian being my manager), or for that matter why it's stuck in the wrong > product, without the dependencies it should have... Yes, apologies.. completely my fault. I should have triaged it correctly. It seemed like a serious regression and you came to mind first.
One thing that comes to mind is to have nsINetUtil.parseContentType output not only the charset and whether there was a charset, but also where in the header string the charset appeared. Then in this code we could just do a simple replace if there is already a charset, and an append otherwise. We'd need to change net_ParseContentType too, but that shouldn't be too bad. biesi, would you be OK with that sort of change?
Blocks: 397234
Like additional parameters "out unsigned long charsetStartIndex, out unsigned long charsetEndIndex"? Fine with me, though perhaps that should be a new additional function so that callers needn't care about those parameters when they don't need them.
I was going to only add out unsigned long charsetStartIndex, since charsetEndIndex is charsetStartIndex + aCharset.Length(). And would you just want a new function on nsINetUtil, or additional signatures for NS_ParseContentType and net_ParseContentType?
My gut instinct, to be honest, is to change the signature in nsINetUtil and add new signatures for NS_ParseContentType and net_ParseContentType.
(In reply to comment #15) > I was going to only add out unsigned long charsetStartIndex, since > charsetEndIndex is charsetStartIndex + aCharset.Length(). I hadn't realized that you want this to be just the value of the parameter. Why do you want that? If you use start/end and make it refer to the entire ";charset=foo" string, you can also just replace that with ";charset=bar", and also allow callers to just remove the charset parameter if they want that. (In reply to comment #16) > My gut instinct, to be honest, is to change the signature in nsINetUtil and add > new signatures for NS_ParseContentType and net_ParseContentType. fine with me
Attached patch Possible patch (obsolete) — Splinter Review
Just checkpointing. Still need to write tests and such.
Attached patch Proposed fixSplinter Review
I discovered that I wanted different enough behavior in terms of the hadCharset boolean that a separate function makes more sense. Also prevents me breaking existing code... That said, maybe we want to return the start/end indices at end of string (and hadCharset == true) in the new function in the circumstance where we now set hadCharset to false because net_ParseContentType returns an index of -1?
Attachment #288331 - Attachment is obsolete: true
Attachment #288809 - Flags: superreview?(cbiesinger)
Attachment #288809 - Flags: review?(cbiesinger)
That includes the fix for bug 397234, by the way.
Assignee: jonas → bzbarsky
Summary: XMLHttpRequest error status 500 on POST multipart form-data → [FIX]XMLHttpRequest error status 500 on POST multipart form-data
Target Milestone: --- → mozilla1.9 M10
Attachment #288809 - Flags: superreview?(cbiesinger)
Attachment #288809 - Flags: superreview+
Attachment #288809 - Flags: review?(cbiesinger)
Attachment #288809 - Flags: review+
Fix and tests checked in. Laurent, thanks for hunting down exactly what the problem was!
Status: NEW → RESOLVED
Closed: 17 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Boris and others, Yes, it works! Thank you very much. We really needed this bug to be fixed because we are developing an OpenSource XUL application using tree cell editing and file upload...only with FF3. Thanks again, Laurent
Component: DOM: Mozilla Extensions → DOM
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: