Bug 1120985 - nsPartChannel does not return the correct value for isLastPart r=honzab
authorValentin Gosu <valentin.gosu@gmail.com>
Thu, 12 Feb 2015 00:11:24 +0200
changeset 228777 4168d9fc720767621dbbb39e572ce4655f164951
parent 228776 edadb5717a9c10399b0c1d4f2897feadbca2b726
child 228778 b63d5963f1bb70e4f47369125225e629da8a1084
push idunknown
push userunknown
push dateunknown
reviewershonzab
bugs1120985
milestone38.0a1
Bug 1120985 - nsPartChannel does not return the correct value for isLastPart r=honzab
netwerk/streamconv/converters/nsMultiMixedConv.cpp
netwerk/test/unit/test_multipart_streamconv.js
--- a/netwerk/streamconv/converters/nsMultiMixedConv.cpp
+++ b/netwerk/streamconv/converters/nsMultiMixedConv.cpp
@@ -617,16 +617,19 @@ nsMultiMixedConv::OnDataAvailable(nsIReq
     int32_t tokenLinefeed = 1;
     while ( (token = FindToken(cursor, bufLen)) ) {
 
         if (((token + mTokenLen) < (cursor + bufLen)) &&
             (*(token + mTokenLen + 1) == '-')) {
             // This was the last delimiter so we can stop processing
             rv = SendData(cursor, LengthToToken(cursor, token));
             if (NS_FAILED(rv)) return rv;
+            if (mPartChannel) {
+                mPartChannel->SetIsLastPart();
+            }
             return SendStop(NS_OK);
         }
 
         if (!mNewPart && token > cursor) {
             // headers are processed, we're pushing data now.
             NS_ASSERTION(!mProcessingHeaders, "we should be pushing raw data");
             rv = SendData(cursor, LengthToToken(cursor, token));
             bufLen -= token - cursor;
--- a/netwerk/test/unit/test_multipart_streamconv.js
+++ b/netwerk/test/unit/test_multipart_streamconv.js
@@ -56,16 +56,17 @@ function responseHandler(request, buffer
     do_check_eq(request.QueryInterface(Ci.nsIChannel).contentType,
 		testData[testNum].type);
     if (++testNum == numTests)
 	httpserver.stop(do_test_finished);
 }
 
 var multipartListener = {
   _buffer: "",
+  _index: 0,
 
   QueryInterface: function(iid) {
     if (iid.equals(Components.interfaces.nsIStreamListener) ||
         iid.equals(Components.interfaces.nsIRequestObserver) ||
         iid.equals(Components.interfaces.nsISupports))
       return this;
     throw Components.results.NS_ERROR_NO_INTERFACE;
   },
@@ -79,16 +80,19 @@ var multipartListener = {
       this._buffer = this._buffer.concat(read_stream(stream, count));
       dump("BUFFEEE: " + this._buffer + "\n\n");
     } catch (ex) {
       do_throw("Error in onDataAvailable: " + ex);
     }
   },
 
   onStopRequest: function(request, context, status) {
+    this._index++;
+    // Second part should be last part
+    do_check_eq(request.QueryInterface(Ci.nsIMultiPartChannel).isLastPart, this._index == 2);
     try {
       responseHandler(request, this._buffer);
     } catch (ex) {
       do_throw("Error in closure function: " + ex);
     }
   }
 };